From 81162f30dc45f481bdb005ff69889ef171cd965e Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Wed, 13 Mar 2019 22:37:28 -0700 Subject: [PATCH] Add popc_stack command to gdb --- assets/debugging/popcorn.elf-gdb.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/assets/debugging/popcorn.elf-gdb.py b/assets/debugging/popcorn.elf-gdb.py index 413053e..12bcdbb 100644 --- a/assets/debugging/popcorn.elf-gdb.py +++ b/assets/debugging/popcorn.elf-gdb.py @@ -1,3 +1,28 @@ +import gdb + +class PrintStackCommand(gdb.Command): + def __init__(self): + super().__init__("popc_stack", gdb.COMMAND_DATA) + + def invoke(self, arg, from_tty): + args = gdb.string_to_argv(arg) + + base = "$rsp" + if len(args) > 0: + base = args[0] + + depth = 22 + if len(args) > 1: + depth = int(args[1]) + + for i in range(depth-1, -1, -1): + offset = i * 8 + value = gdb.parse_and_eval(f"*(uint64_t*)({base} + {offset})") + print("{:04x}: {:016x}".format(offset, int(value))) + + +PrintStackCommand() + import time time.sleep(3.5) gdb.execute("target remote :1234")