[libcxx-commits] [libcxx] [libc++] Fix gdb pretty printer for strings (PR #176882)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 20 01:50:46 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Johan Bengtsson (JohanBengtssonIAR)

<details>
<summary>Changes</summary>

The gdb pretty printer for strings reports an error when printing a string that is small enough to fit inline in the string object. The problem is that the lazy_string method can't be applied directly to an array value. The fix is to cast the array to a pointer and apply lazy_string to that value.

---
Full diff: https://github.com/llvm/llvm-project/pull/176882.diff


1 Files Affected:

- (modified) libcxx/utils/gdb/libcxx/printers.py (+2-1) 


``````````diff
diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 1c8ef6d7feb97..4c04894db7f5d 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -198,7 +198,8 @@ def to_string(self):
             data = long_field["__data_"]
             size = long_field["__size_"]
         else:
-            data = short_field["__data_"]
+            char_ptr = gdb.lookup_type("char").pointer()
+            data = short_field["__data_"].cast(char_ptr)
             size = short_field["__size_"]
         return data.lazy_string(length=size)
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/176882


More information about the libcxx-commits mailing list