Skip to content

Commit

Permalink
Merge branch 'topic/minor-pp-cleanups' into 'master'
Browse files Browse the repository at this point in the history
Minor gdb pretty-printer cleanups

See merge request eng/ide/VSS!349
  • Loading branch information
tromey committed Dec 4, 2024
2 parents 0cdb5b0 + c283256 commit c20bd52
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions gdb/vss_pp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import gdb
import gdb.printing
from gnatdbg.tagged import reinterpret_tagged

# Use the tag class if it is available.
if hasattr(gdb, "ValuePrinter"):
base = gdb.ValuePrinter
else:
base = object


def decode_utf8(bytes, size):
result = ""
Expand Down Expand Up @@ -36,9 +44,9 @@ def decode_utf8(bytes, size):
return result


class Virtual_String_Printer:
class Virtual_String_Printer(base):
def __init__(self, val):
self.val = val
self._val = val

def to_string(self):
text_type = gdb.lookup_type(
Expand All @@ -51,7 +59,7 @@ def to_string(self):
"vss.implementation.text_handlers.utf8.dynamic.dynamic_utf8_handler"
)

storage = self.val["data"]["storage"]
storage = self._val["data"]["storage"]

if all(byte == 0 for byte in storage.bytes):
# "null" string
Expand All @@ -72,7 +80,7 @@ def to_string(self):
return decode_utf8(data["storage"].bytes, data["size"])

else:
print("<UNKNOWN TYPE>")
raise TypeError("<UNKNOWN TYPE>")

return None

Expand All @@ -81,9 +89,15 @@ def to_string(self):
# return "string"


def vss_pp_func(val):
if str(val.type) == "vss.strings.virtual_string":
return Virtual_String_Printer(val)
class VSSPrinter(gdb.printing.PrettyPrinter):
"""Pretty-print VSS strings."""

def __init__(self):
super().__init__("VSS")

def __call__(self, val):
if str(val.type) == "vss.strings.virtual_string":
return Virtual_String_Printer(val)


gdb.pretty_printers.append(vss_pp_func)
gdb.printing.register_pretty_printer(None, VSSPrinter())

0 comments on commit c20bd52

Please sign in to comment.