@@ -0,0 +1,1265 @@
+# pretty printing for stage1%0A# put %22source /path/to/zig-gdb.py%22 in ~/.gdbinit to load it automatically%0A%0Aimport gdb.printing%0A%0Aclass ZigListPrinter:%0A    def __init__(self, val):%0A        self.val = val%0A%0A    def to_string(self):%0A        return '%25s of length %25d, capacity %25d' %25 (self.val.type.name, int(self.val%5B'length'%5D), int(self.val%5B'capacity'%5D))%0A%0A    def children(self):%0A        def it(ziglist):%0A            for i in range(int(ziglist.val%5B'length'%5D)):%0A                item = ziglist.val%5B'items'%5D + i%0A                yield ('%5B%25d%5D' %25 i, item.dereference())%0A        return it(self)%0A%0A    def display_hint(self):%0A        return 'array'%0A%0A# handle both Buf and ZigList%3Cchar%3E because Buf* doesn't work otherwise (gdb bug?)%0Aclass BufPrinter:%0A    def __init__(self, val):%0A        self.val = val%5B'list'%5D if val.type.name == 'Buf' else val%0A%0A    def to_string(self):%0A        return self.val%5B'items'%5D.string(length=int(self.val%5B'length'%5D))%0A%0A    def display_hint(self):%0A        return 'string'%0A%0App = gdb.printing.RegexpCollectionPrettyPrinter('zig')%0App.add_printer('Buf', '%5EBuf$', BufPrinter)%0App.add_printer('ZigList%3Cchar%3E', '%5EZigList%3Cchar%3E$', BufPrinter)%0App.add_printer('ZigList', '%5EZigList%3C.*%3E$', ZigListPrinter)%0A%0Agdb.printing.register_pretty_printer(gdb.current_objfile(), pp)%0A

add ZigList gdb pretty printing