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

Johan Bengtsson via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 20 01:49:52 PST 2026


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

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.

>From b590deba7b07afc027b764a2260c3ddd50ff800c Mon Sep 17 00:00:00 2001
From: Johan Bengtsson <johan.bengtsson at iar.com>
Date: Tue, 20 Jan 2026 10:40:40 +0100
Subject: [PATCH] [libc++] Fix gdb pretty printer for strings

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.
---
 libcxx/utils/gdb/libcxx/printers.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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)
 



More information about the libcxx-commits mailing list