[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.
This commit is contained in:
Justin C. Miller
2021-08-01 14:25:57 -07:00
parent d675d6e54b
commit 59d7271fb5

View File

@@ -19,7 +19,7 @@ class PrintStackCommand(gdb.Command):
try: try:
offset = i * 8 offset = i * 8
base_addr = gdb.parse_and_eval(base) 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))) print("{:016x} (+{:04x}): {:016x}".format(int(base_addr) + offset, offset, int(value)))
except Exception as e: except Exception as e:
print(e) print(e)
@@ -41,17 +41,22 @@ class PrintBacktraceCommand(gdb.Command):
if len(args) > 1: if len(args) > 1:
frame = args[1] frame = args[1]
frame = gdb.parse_and_eval(f"{frame}")
for i in range(depth-1, -1, -1): for i in range(depth-1, -1, -1):
ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 8)") ret = gdb.parse_and_eval(f"*(uint64_t*)({frame} + 0x8)")
frame = gdb.parse_and_eval(f"*(uint64_t*)({frame})")
name = "" name = ""
block = gdb.block_for_pc(int(ret)) try:
if block: block = gdb.block_for_pc(int(ret))
name = block.function or "" 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: if frame == 0 or ret == 0:
return return