From 83051b0cbf31b76e824d3911a7f4a0be3c0cf94d Mon Sep 17 00:00:00 2001 From: Silver Date: Fri, 24 Mar 2023 00:38:02 +0000 Subject: [PATCH] Update GDB pretty printers --- tools/zig_gdb_pretty_printers.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/zig_gdb_pretty_printers.py b/tools/zig_gdb_pretty_printers.py index 7397097cc1..1bc4b36e57 100644 --- a/tools/zig_gdb_pretty_printers.py +++ b/tools/zig_gdb_pretty_printers.py @@ -2,22 +2,24 @@ # put "source /path/to/zig_gdb_pretty_printers.py" in ~/.gdbinit to load it automatically. import gdb.printing + class ZigPrettyPrinter(gdb.printing.PrettyPrinter): def __init__(self): super().__init__('Zig') def __call__(self, val): tag = val.type.tag - if(tag is None): + if tag is None: return None - if(tag == '[]u8'): + if tag == '[]u8': return StringPrinter(val) - if(tag.startswith('[]')): + if tag.startswith('[]'): return SlicePrinter(val) - if(tag.startswith('?')): + if tag.startswith('?'): return OptionalPrinter(val) return None + class SlicePrinter: def __init__(self, val): self.val = val @@ -35,6 +37,7 @@ class SlicePrinter: def display_hint(self): return 'array' + class StringPrinter: def __init__(self, val): self.val = val @@ -45,20 +48,16 @@ class StringPrinter: def display_hint(self): return 'string' + class OptionalPrinter: def __init__(self, val): self.val = val def to_string(self): - if(self.val['maybe']): - return None # printed by children() + if self.val['some']: + return self.val['data'] else: return 'null' - def children(self): - def it(val): - if(val['maybe']): - yield ('payload', val['val']) - return it(self.val) gdb.printing.register_pretty_printer(gdb.current_objfile(), ZigPrettyPrinter())