| ... | @@ -1,37 +0,0 @@ |
| 1 | # pretty printing for stage1. |
| 2 | # put "source /path/to/stage1_gdb_pretty_printers.py" in ~/.gdbinit to load it automatically. |
| 3 | import gdb.printing |
| 4 | |
| 5 | class ZigListPrinter: |
| 6 | def __init__(self, val): |
| 7 | self.val = val |
| 8 | |
| 9 | def to_string(self): |
| 10 | return '%s of length %d, capacity %d' % (self.val.type.name, int(self.val['length']), int(self.val['capacity'])) |
| 11 | |
| 12 | def children(self): |
| 13 | def it(ziglist): |
| 14 | for i in range(int(ziglist.val['length'])): |
| 15 | item = ziglist.val['items'] + i |
| 16 | yield ('[%d]' % i, item.dereference()) |
| 17 | return it(self) |
| 18 | |
| 19 | def display_hint(self): |
| 20 | return 'array' |
| 21 | |
| 22 | # handle both Buf and ZigList<char> because Buf* doesn't work otherwise (gdb bug?) |
| 23 | class BufPrinter: |
| 24 | def __init__(self, val): |
| 25 | self.val = val['list'] if val.type.name == 'Buf' else val |
| 26 | |
| 27 | def to_string(self): |
| 28 | return self.val['items'].string(length=int(self.val['length'])) |
| 29 | |
| 30 | def display_hint(self): |
| 31 | return 'string' |
| 32 | |
| 33 | pp = gdb.printing.RegexpCollectionPrettyPrinter('Zig stage1 compiler') |
| 34 | pp.add_printer('Buf', '^Buf$', BufPrinter) |
| 35 | pp.add_printer('ZigList<char>', '^ZigList<char>$', BufPrinter) |
| 36 | pp.add_printer('ZigList', '^ZigList<.*>$', ZigListPrinter) |
| 37 | gdb.printing.register_pretty_printer(gdb.current_objfile(), pp) |