File 0001-Debugger-Fix-custom-GDB-pretty-printers.patch of Package qt-creator

From 72037300496c27aa0161188f95eb7f025872e8a2 Mon Sep 17 00:00:00 2001
From: Andrii Semkiv <andrii.semkiv@qt.io>
Date: Wed, 12 Feb 2025 16:18:42 +0100
Subject: [PATCH] Debugger: Fix custom GDB pretty printers

A GDB pretty printer's to_string method can return a plain string
as well as a Value object. We did not account for the latter.

Fixes: QTCREATORBUG-32480
Change-Id: I3429c30a022a1c810e677a567e2d2aba59c22a79
Reviewed-by: hjk <hjk@qt.io>
---
 share/qtcreator/debugger/gdbbridge.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py
index a781865a411..6cecee3e976 100644
--- a/share/qtcreator/debugger/gdbbridge.py
+++ b/share/qtcreator/debugger/gdbbridge.py
@@ -135,9 +135,12 @@ class PlainDumper():
         if isinstance(val, str):
             # encode and avoid extra quotes ('"') at beginning and end
             d.putValue(d.hexencode(val), 'utf8:1:0')
-        elif val is not None:  # Assuming LazyString
-            d.putCharArrayValue(val.address, val.length,
-                                val.type.target().sizeof)
+        # It might as well be just another gdb.Value, see
+        # https://sourceware.org/gdb/current/onlinedocs/gdb.html/Pretty-Printing-API.html#:~:text=Function%3A%20pretty_printer.to_string%20(self)
+        elif isinstance(val, gdb.Value):
+            d.putItem(d.fromNativeValue(val))
+        else:
+            return
 
         lister = getattr(printer, 'children', None)
         if lister is None:
@@ -1041,7 +1044,8 @@ class Dumper(DumperBase):
                 for printer in printers.subprinters:
                     self.importPlainDumper(printer)
             else:
-                self.warn('Loading a printer without the subprinters attribute not supported.')
+                self.warn("Failed to load printer '{}': loading printers without "
+                          "the subprinters attribute not supported.".format(printers.name))
 
     def importPlainDumpers(self):
         for obj in gdb.objfiles():
-- 
2.48.1

openSUSE Build Service is sponsored by