From 5c82e5ba1b6369fa618aa0d1a92b3f98ab6596ed Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 15 Jan 2022 09:01:03 -0800 Subject: [PATCH] [tools] Fix gdb j6bt & j6stack commands These commands had a number of issues. They weren't evaluating their arguments (eg, you couldn't use a symbol name instead of a number), and they weren't explicitly using hex when evaluating numbers, so they were getting incorrect values when the default radix was not 10. --- assets/debugging/jsix.elf-gdb.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/assets/debugging/jsix.elf-gdb.py b/assets/debugging/jsix.elf-gdb.py index a69c3bf..23b1ec7 100644 --- a/assets/debugging/jsix.elf-gdb.py +++ b/assets/debugging/jsix.elf-gdb.py @@ -10,6 +10,7 @@ class PrintStackCommand(gdb.Command): base = "$rsp" if len(args) > 0: base = args[0] + base = int(gdb.parse_and_eval(base)) depth = 22 if len(args) > 1: @@ -18,9 +19,8 @@ class PrintStackCommand(gdb.Command): for i in range(depth-1, -1, -1): try: offset = i * 8 - base_addr = gdb.parse_and_eval(base) - value = gdb.parse_and_eval(f"*(uint64_t*)({base} + 0x{offset:x})") - print("{:016x} (+{:04x}): {:016x}".format(int(base_addr) + offset, offset, int(value))) + value = gdb.parse_and_eval(f"*(uint64_t*)({base:#x} + {offset:#x})") + print("{:016x} (+{:04x}): {:016x}".format(base + offset, offset, int(value))) except Exception as e: print(e) continue @@ -33,18 +33,18 @@ class PrintBacktraceCommand(gdb.Command): def invoke(self, arg, from_tty): args = gdb.string_to_argv(arg) - depth = 30 - if len(args) > 0: - depth = int(args[0]) - frame = "$rbp" - if len(args) > 1: - frame = args[1] + if len(args) > 0: + frame = args[0] - frame = gdb.parse_and_eval(f"{frame}") + frame = int(gdb.parse_and_eval(f"{frame}")) + + depth = 30 + if len(args) > 1: + depth = int(gdb.parse_and_eval(args[1])) for i in range(depth-1, -1, -1): - ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 0x8)") + ret = gdb.parse_and_eval(f"*(uint64_t*)({frame:#x} + 0x8)") name = "" try: @@ -56,7 +56,7 @@ class PrintBacktraceCommand(gdb.Command): print("{:016x}: {:016x} {}".format(int(frame), int(ret), name)) - frame = gdb.parse_and_eval(f"*(uint64_t*)({frame})") + frame = int(gdb.parse_and_eval(f"*(uint64_t*)({frame:#x})")) if frame == 0 or ret == 0: return