From a56e5dce69bfad45ee6977a916ccea283e087e8b Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 5 Sep 2023 09:13:14 -0600 Subject: Handle pointers and references correctly in DAP A user pointed out that the current DAP variable code does not let the client deference a pointer. Oops! Fixing this oversight is simple enough -- adding a new no-op pretty-printer for pointers and references is quite simple. However, doing this naive caused a regession in scopes.exp, which expected there to be no children of a 'const char *' variable. This problem was fixed by the preceding patches in the series, which ensure that a C type of this kind is recognized as a string. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30821 --- gdb/python/lib/gdb/printing.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gdb/python') diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py index 1a761a6..223a699 100644 --- a/gdb/python/lib/gdb/printing.py +++ b/gdb/python/lib/gdb/printing.py @@ -280,6 +280,20 @@ class NoOpScalarPrinter: return self.value.format_string(raw=True) +class NoOpPointerReferencePrinter: + """A no-op pretty printer that wraps a pointer or reference.""" + + def __init__(self, value): + self.value = value + self.num_children = 1 + + def to_string(self): + return self.value.format_string(deref_refs=False) + + def children(self): + yield "value", self.value.referenced_value() + + class NoOpArrayPrinter: """A no-op pretty printer that wraps an array value.""" @@ -354,6 +368,8 @@ def make_visualizer(value): result = gdb.printing.NoOpArrayPrinter(ty, value) elif ty.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION): result = gdb.printing.NoOpStructPrinter(ty, value) + elif ty.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_REF, gdb.TYPE_CODE_RVALUE_REF): + result = NoOpPointerReferencePrinter(value) else: result = gdb.printing.NoOpScalarPrinter(value) return result -- cgit v1.1