mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Update GDB pretty printers
This commit is contained in:
parent
11903436a9
commit
83051b0cbf
1 changed files with 10 additions and 11 deletions
|
|
@ -2,22 +2,24 @@
|
||||||
# put "source /path/to/zig_gdb_pretty_printers.py" in ~/.gdbinit to load it automatically.
|
# put "source /path/to/zig_gdb_pretty_printers.py" in ~/.gdbinit to load it automatically.
|
||||||
import gdb.printing
|
import gdb.printing
|
||||||
|
|
||||||
|
|
||||||
class ZigPrettyPrinter(gdb.printing.PrettyPrinter):
|
class ZigPrettyPrinter(gdb.printing.PrettyPrinter):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('Zig')
|
super().__init__('Zig')
|
||||||
|
|
||||||
def __call__(self, val):
|
def __call__(self, val):
|
||||||
tag = val.type.tag
|
tag = val.type.tag
|
||||||
if(tag is None):
|
if tag is None:
|
||||||
return None
|
return None
|
||||||
if(tag == '[]u8'):
|
if tag == '[]u8':
|
||||||
return StringPrinter(val)
|
return StringPrinter(val)
|
||||||
if(tag.startswith('[]')):
|
if tag.startswith('[]'):
|
||||||
return SlicePrinter(val)
|
return SlicePrinter(val)
|
||||||
if(tag.startswith('?')):
|
if tag.startswith('?'):
|
||||||
return OptionalPrinter(val)
|
return OptionalPrinter(val)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class SlicePrinter:
|
class SlicePrinter:
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
@ -35,6 +37,7 @@ class SlicePrinter:
|
||||||
def display_hint(self):
|
def display_hint(self):
|
||||||
return 'array'
|
return 'array'
|
||||||
|
|
||||||
|
|
||||||
class StringPrinter:
|
class StringPrinter:
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
@ -45,20 +48,16 @@ class StringPrinter:
|
||||||
def display_hint(self):
|
def display_hint(self):
|
||||||
return 'string'
|
return 'string'
|
||||||
|
|
||||||
|
|
||||||
class OptionalPrinter:
|
class OptionalPrinter:
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
if(self.val['maybe']):
|
if self.val['some']:
|
||||||
return None # printed by children()
|
return self.val['data']
|
||||||
else:
|
else:
|
||||||
return 'null'
|
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())
|
gdb.printing.register_pretty_printer(gdb.current_objfile(), ZigPrettyPrinter())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue