From: Jacob Lifshay Date: Thu, 7 Dec 2023 08:55:22 +0000 (-0800) Subject: load_elf: dump a sequence of gdb commands for easy debugging X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=54329e2d6f5b563a8af5a5563dc4075fc34d8277;p=openpower-isa.git load_elf: dump a sequence of gdb commands for easy debugging dumps a sequence of gdb commands that can easily be copied from the output and pasted into gdb to reset the stack to what load_elf uses, instead of what gdb's execve does. --- diff --git a/src/openpower/decoder/isa/mem.py b/src/openpower/decoder/isa/mem.py index 3830ccae..49c10c8f 100644 --- a/src/openpower/decoder/isa/mem.py +++ b/src/openpower/decoder/isa/mem.py @@ -1098,6 +1098,24 @@ class LoadedELF: self.gprs = gprs self.fpscr = fpscr + def dump_gdb_init(self, mem): + lines = [] + lines.append("---BEGIN GDB INIT---") + lines.append("starti") + for k, v in self.gprs.items(): + lines.append("set var $r%d = 0x%X" % (k, v)) + args_addr = self.gprs[1] + args_len = _USER_SPACE_SIZE - args_addr + args = mem.get_ctypes(args_addr, args_len, False) + chunk_size = 16 + assert args_addr % chunk_size == 0 + for offset in range(0, args_len, chunk_size): + parts = ", ".join(hex(args[offset + i]) for i in range(chunk_size)) + lines.append("set var {unsigned char[%d]}0x%X = {%s}" + % (chunk_size, args_addr + offset, parts)) + lines.append("---END GDB INIT---") + log("\n".join(lines), kind=LogType.InstrInOuts) + def raise_if_syscall_err(result): if -4096 < result < 0: @@ -1402,4 +1420,6 @@ def load_elf( gprs[7] = 0 # termination function pointer gprs[12] = pc fpscr = 0 - return LoadedELF(elf_file, pc, gprs, fpscr) + retval = LoadedELF(elf_file, pc, gprs, fpscr) + retval.dump_gdb_init(mem) + return retval