Files
jsix/scripts/parse_frame_allocs.py
Justin C. Miller 350396d70f [tools] Commit memory debug (et al) tooling
These are some changes I made to debug tooling while tracking down the
bugfix in the previous commit.

Each `scripts/debug_*_alloc.gdb` script has gdb output a `*_allocs.txt`
file, which in turn can be parsed by the `scripts/parse_*_allocs.py`
script to find errors.
2023-07-10 01:31:07 -07:00

41 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
def add_maps(allocs, addr, count):
for i in range(count):
if addr+i in allocs:
print(f"ERROR: frame {addr+i:012x} map collision.")
else:
#print(f" frame {addr+i:012x} mapped")
allocs.add(addr+i)
def remove_maps(allocs, addr, count):
for i in range(count):
if addr+i not in allocs:
print(f" WARN: removing unmapped frame {addr+i:012x}")
else:
#print(f" frame {addr+i:012x} unmapped")
allocs.remove(addr+i)
def parse_line(allocs, line):
args = line.strip().split()
match args:
case ['+', addr, count]:
add_maps(allocs, int(addr, base=16), int(count))
case ['-', addr, count]:
remove_maps(allocs, int(addr, base=16), int(count))
case _:
pass
def parse_file(f):
allocs = set()
for line in f.readlines():
parse_line(allocs, line)
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
with open(sys.argv[1]) as f:
parse_file(f)
else:
parse_file(sys.stdin)