authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-05-06 22:08:04+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-07 12:43:22-04:00
log79bf4003da5fad5046b34d6256eeb8a575890ea5
tree84b540bfe6abdba3db679401faad296b5ee01877
parentba43492c0e4b37924caf5956b4dbaf832b964b81

stage1: add ZigList gdb pretty printing


1 files changed, 39 insertions(+), 0 deletions(-)

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