From 12edc5aee386ea473e9b9091e9c76d70169af634 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 29 Dec 2022 00:59:05 -0600 Subject: [PATCH] Added some ascii art to dbgrbyd.py to help debug how ids change over time An example: $ ./scripts/dbgrbyd.py disk 4096 0 -i mdir 0x0, rev 1, size 59 off tag data (truncated) 00000004: create x01 id1 4 aa aa aa aa .... . 0000000c: altblt x80d0 x4 | 00000010: create x01 id2 4 cc cc cc cc .... | . 00000018: altrlt x80d0 x4 | | 0000001c: altbgt x8000 x10 | | 00000020: create x01 id2 4 bb bb bb bb .... | .\ 00000028: fcrc 5 51 53 7d 52 01 QS}R. | | | 0000002f: crc0 7 5f db 22 8a 1b 1b 1b _.".... | | | --- scripts/dbgrbyd.py | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/scripts/dbgrbyd.py b/scripts/dbgrbyd.py index fda0d9f6..945849c7 100755 --- a/scripts/dbgrbyd.py +++ b/scripts/dbgrbyd.py @@ -4,6 +4,15 @@ import itertools as it import math as m import struct +COLORS = [ + '34', # blue + '31', # red + '32', # green + '35', # purple + '33', # yellow + '36', # cyan +] + def crc32c(data, crc=0): crc ^= 0xffffffff @@ -236,6 +245,10 @@ def main(disk, block_size, block1, block2=None, *, # print tags if args.get('rbyd'): alts = [] + if args.get('ids'): + count = 0 + ids = [] + ids_i = 0 j = 4 while j < (block_size if args.get('all') else off): notes = [] @@ -250,6 +263,16 @@ def main(disk, block_size, block1, block2=None, *, if not tag & 0x4: if (tag & 0x7e) != 0x2: crc = crc32c(data[j:j+size], crc) + # adjust count + if args.get('ids'): + if (tag & 0x7f) == 0x40: + count += 1 + ids.insert(((tag >> 15) & 0xffff)-1, + COLORS[ids_i % len(COLORS)]) + ids_i += 1 + elif (tag & 0x7f) == 0x48: + count -= 1 + ids.pop(((tag >> 15) & 0xffff)-1) # found a crc? else: crc_, = struct.unpack('> 15) & 0xffff)-1 + else '\'' if (tag & 0x7f) == 0x48 + and id == ((tag >> 15) & 0xffff)-1 + else '* ' if not tag & 0x4 + and id == ((tag >> 15) & 0xffff)-1 + else '\ ' if (tag & 0x7f) == 0x40 + and id > ((tag >> 15) & 0xffff)-1 + else '/ ' if (tag & 0x7f) == 0x48 + and id > ((tag >> 15) & 0xffff)-1 + else '| ', + '\x1b[m' if color else '') + for id in range(count)) + if args.get('ids') else '')) # show in-device representation, including some extra @@ -362,7 +403,7 @@ if __name__ == "__main__": action='store_true', help="Don't stop parsing on bad commits.") parser.add_argument( - '-i', '--in-tree', + '-t', '--in-tree', action='store_true', help="Only show tags in the tree.") parser.add_argument( @@ -385,6 +426,10 @@ if __name__ == "__main__": '-j', '--jumps', action='store_true', help="Show alt pointer jumps in the margin.") + parser.add_argument( + '-i', '--ids', + action='store_true', + help="Show inserts/deletes of ids in the margin.") parser.add_argument( '-e', '--error-on-corrupt', action='store_true',