mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 15:12:31 +00:00
Update GDB pretty printers
This commit is contained in:
parent
11903436a9
commit
83051b0cbf
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user