| author | |
| committer | |
| log | 0a6ba6f666e51eee612b97628e2488a0fdb18210 |
| tree | 597b840f10f57cd9aa36a6611c6aea80b02440af |
| parent | 49ca51fc3ac35ee3ab25cdad9747c9c0719ffe5e |
2 files changed, 65 insertions(+), 1 deletions(-)
tools/zig-gdb.py+1-1| ... | @@ -31,7 +31,7 @@ class BufPrinter: | ... | @@ -31,7 +31,7 @@ class BufPrinter: |
| 31 | def display_hint(self): | 31 | def display_hint(self): |
| 32 | return 'string' | 32 | return 'string' |
| 33 | 33 | ||
| 34 | pp = gdb.printing.RegexpCollectionPrettyPrinter('zig') | 34 | pp = gdb.printing.RegexpCollectionPrettyPrinter('Zig stage1 compiler') |
| 35 | pp.add_printer('Buf', '^Buf$', BufPrinter) | 35 | pp.add_printer('Buf', '^Buf$', BufPrinter) |
| 36 | pp.add_printer('ZigList<char>', '^ZigList<char>$', BufPrinter) | 36 | pp.add_printer('ZigList<char>', '^ZigList<char>$', BufPrinter) |
| 37 | pp.add_printer('ZigList', '^ZigList<.*>$', ZigListPrinter) | 37 | pp.add_printer('ZigList', '^ZigList<.*>$', ZigListPrinter) |
tools/zig_gdb_pretty_printers.py created+64| ... | @@ -0,0 +1,64 @@ | ||
| 1 | # gdb pretty printers for Zig language constructs | ||
| 2 | |||
| 3 | import gdb.printing | ||
| 4 | |||
| 5 | class ZigPrettyPrinter(gdb.printing.PrettyPrinter): | ||
| 6 | def __init__(self): | ||
| 7 | super().__init__('Zig') | ||
| 8 | |||
| 9 | def __call__(self, val): | ||
| 10 | tag = val.type.tag | ||
| 11 | if(tag is None): | ||
| 12 | return None | ||
| 13 | if(tag == '[]u8'): | ||
| 14 | return StringPrinter(val) | ||
| 15 | if(tag.startswith('[]')): | ||
| 16 | return SlicePrinter(val) | ||
| 17 | if(tag.startswith('?')): | ||
| 18 | return OptionalPrinter(val) | ||
| 19 | return None | ||
| 20 | |||
| 21 | class SlicePrinter: | ||
| 22 | def __init__(self, val): | ||
| 23 | self.val = val | ||
| 24 | |||
| 25 | def to_string(self): | ||
| 26 | return f"{self.val['len']} items at {self.val['ptr']}" | ||
| 27 | |||
| 28 | def children(self): | ||
| 29 | def it(val): | ||
| 30 | for i in range(int(val['len'])): | ||
| 31 | item = val['ptr'] + i | ||
| 32 | yield (f'[{i}]', item.dereference()) | ||
| 33 | return it(self.val) | ||
| 34 | |||
| 35 | def display_hint(self): | ||
| 36 | return 'array' | ||
| 37 | |||
| 38 | class StringPrinter: | ||
| 39 | def __init__(self, val): | ||
| 40 | self.val = val | ||
| 41 | |||
| 42 | def to_string(self): | ||
| 43 | return self.val['ptr'].string(length=int(self.val['len'])) | ||
| 44 | |||
| 45 | def display_hint(self): | ||
| 46 | return 'string' | ||
| 47 | |||
| 48 | class OptionalPrinter: | ||
| 49 | def __init__(self, val): | ||
| 50 | self.val = val | ||
| 51 | |||
| 52 | def to_string(self): | ||
| 53 | if(self.val['maybe']): | ||
| 54 | return None # printed by children() | ||
| 55 | else: | ||
| 56 | return 'null' | ||
| 57 | |||
| 58 | def children(self): | ||
| 59 | def it(val): | ||
| 60 | if(val['maybe']): | ||
| 61 | yield ('payload', val['val']) | ||
| 62 | return it(self.val) | ||
| 63 | |||
| 64 | gdb.printing.register_pretty_printer(gdb.current_objfile(), ZigPrettyPrinter()) | ||