From 03f0a59816111ff8cebc135fcb753dfe04c1b380 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Sat, 17 Aug 2024 20:05:48 +0800 Subject: [PATCH] minidumpserver:Special processing xtensa architecture Signed-off-by: anjiahao --- tools/minidumpserver.py | 43 +++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/tools/minidumpserver.py b/tools/minidumpserver.py index aaeb3b93f8..aa2acc4e14 100755 --- a/tools/minidumpserver.py +++ b/tools/minidumpserver.py @@ -217,14 +217,14 @@ reg_table = { # make sure the a0-a15 can be remapped to the correct register reg_fix_value = { "esp32s3": { - "WINDOWBASE": 0, - "WINDOWSTART": 1, - "PS": 0x40000, + "WINDOWBASE": (0, 69), + "WINDOWSTART": (1, 70), + "PS": (0x40000, 73), }, "xtensa": { - "WINDOWBASE": 0, - "WINDOWSTART": 1, - "PS": 0x40000, + "WINDOWBASE": (0, 584), + "WINDOWSTART": (1, 585), + "PS": (0x40000, 742), }, "riscv": { "ZERO": 0, @@ -382,7 +382,7 @@ class DumpLogFile: if arch in reg_fix_value: for reg_name, reg_vals in reg_fix_value[arch].items(): reg_index = self.reg_table[reg_name] - self.registers[reg_index] = reg_vals + self.registers[reg_index] = reg_vals[0] def _parse_stack(self, line, start, data): line = str_get_after(line, "stack_dump:") @@ -511,11 +511,13 @@ class GDBStub: elffile: DumpELFFile, rawfile: RawMemoryFile, coredump: CoreDumpFile, + arch: str, ): self.registers = logfile.registers self.elffile = elffile self.socket = None self.gdb_signal = GDB_SIGNAL_DEFAULT + self.arch = arch # new list oreder is coredump, rawfile, logfile, elffile @@ -539,6 +541,10 @@ class GDBStub: ) sys.exit(1) + if arch in reg_fix_value.keys(): + self.regfix = True + logger.info(f"Current arch is {arch}, need reg index fix.") + except TypeError: if not self.registers: logger.critical( @@ -645,9 +651,26 @@ class GDBStub: def put_one_register_packet(regs): + regval = None reg = int(pkt[1:].decode("utf8"), 16) - if reg < len(regs) and regs[reg] != b"x": - bval = struct.pack(self.reg_fmt, regs[reg]) + if self.regfix: + for reg_name, reg_vals in reg_fix_value[self.arch].items(): + if reg == reg_vals[1]: + logger.debug(f"{reg_name} fix to {reg_vals[0]}") + regval = reg_vals[0] + + if regval is None: + # tcbinfo index to gdb index + reg_gdb_index = list(reg_table[self.arch].values()) + if reg in reg_gdb_index: + reg = reg_gdb_index.index(reg) + regval = regs[reg] + + elif reg < len(regs) and regs[reg] != b"x": + regval = regs[reg] + + if regval is not None: + bval = struct.pack(self.reg_fmt, regval) self.put_gdb_packet(binascii.hexlify(bval)) else: self.put_gdb_packet(b"x" * self.reg_digits) @@ -1098,7 +1121,7 @@ def main(args): raw = RawMemoryFile(args.rawfile) coredump = CoreDumpFile(args.coredump) - gdb_stub = GDBStub(log, elf, raw, coredump) + gdb_stub = GDBStub(log, elf, raw, coredump, args.arch) gdbserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)