From 59d7271fb593bded94c33a1f8be0ab59fe6ac133 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sun, 1 Aug 2021 14:25:57 -0700 Subject: [PATCH] [scripts] Improve gdb script stack handling When setting a radix other than 10, the j6stack command will start adding the wrong values - make sure to specify a radix for the offset explicitly. Also show the frame pointer for each frame with the j6bt command, and don't throw exceptions if the name of the block is unknown. --- assets/debugging/jsix.elf-gdb.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/assets/debugging/jsix.elf-gdb.py b/assets/debugging/jsix.elf-gdb.py index ef686cd..be711af 100644 --- a/assets/debugging/jsix.elf-gdb.py +++ b/assets/debugging/jsix.elf-gdb.py @@ -19,7 +19,7 @@ class PrintStackCommand(gdb.Command): try: offset = i * 8 base_addr = gdb.parse_and_eval(base) - value = gdb.parse_and_eval(f"*(uint64_t*)({base} + {offset})") + value = gdb.parse_and_eval(f"*(uint64_t*)({base} + 0x{offset:x})") print("{:016x} (+{:04x}): {:016x}".format(int(base_addr) + offset, offset, int(value))) except Exception as e: print(e) @@ -41,17 +41,22 @@ class PrintBacktraceCommand(gdb.Command): if len(args) > 1: frame = args[1] + frame = gdb.parse_and_eval(f"{frame}") + for i in range(depth-1, -1, -1): - ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 8)") - frame = gdb.parse_and_eval(f"*(uint64_t*)({frame})") + ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 0x8)") name = "" - block = gdb.block_for_pc(int(ret)) - if block: - name = block.function or "" + try: + block = gdb.block_for_pc(int(ret)) + if block: + name = block.function or "" + except RuntimeError: + pass - print("{:016x} {}".format(int(ret), name)) + print("{:016x}: {:016x} {}".format(int(frame), int(ret), name)) + frame = gdb.parse_and_eval(f"*(uint64_t*)({frame})") if frame == 0 or ret == 0: return