aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorxackus <14938807+xackus@users.noreply.github.com>2020-05-06 22:08:04 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-05-07 12:43:22 -0400
commit79bf4003da5fad5046b34d6256eeb8a575890ea5 (patch)
tree84b540bfe6abdba3db679401faad296b5ee01877 /tools
parentba43492c0e4b37924caf5956b4dbaf832b964b81 (diff)
downloadzig-79bf4003da5fad5046b34d6256eeb8a575890ea5.tar.gz
zig-79bf4003da5fad5046b34d6256eeb8a575890ea5.zip
stage1: add ZigList gdb pretty printing
Diffstat (limited to 'tools')
-rw-r--r--tools/zig-gdb.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/zig-gdb.py b/tools/zig-gdb.py
new file mode 100644
index 0000000000..f0efef9d2f
--- /dev/null
+++ b/tools/zig-gdb.py
@@ -0,0 +1,39 @@
+# pretty printing for stage1
+# put "source /path/to/zig-gdb.py" in ~/.gdbinit to load it automatically
+
+import gdb.printing
+
+class ZigListPrinter:
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return '%s of length %d, capacity %d' % (self.val.type.name, int(self.val['length']), int(self.val['capacity']))
+
+ def children(self):
+ def it(ziglist):
+ for i in range(int(ziglist.val['length'])):
+ item = ziglist.val['items'] + i
+ yield ('[%d]' % i, item.dereference())
+ return it(self)
+
+ def display_hint(self):
+ return 'array'
+
+# handle both Buf and ZigList<char> because Buf* doesn't work otherwise (gdb bug?)
+class BufPrinter:
+ def __init__(self, val):
+ self.val = val['list'] if val.type.name == 'Buf' else val
+
+ def to_string(self):
+ return self.val['items'].string(length=int(self.val['length']))
+
+ def display_hint(self):
+ return 'string'
+
+pp = gdb.printing.RegexpCollectionPrettyPrinter('zig')
+pp.add_printer('Buf', '^Buf$', BufPrinter)
+pp.add_printer('ZigList<char>', '^ZigList<char>$', BufPrinter)
+pp.add_printer('ZigList', '^ZigList<.*>$', ZigListPrinter)
+
+gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)