From 8e0fb2c4331cc335b61987f4bc98b4376bcd70c3 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Tue, 13 Aug 2024 14:23:30 +0800 Subject: [PATCH] minidumpserver:support use coredump restore the crash scene The benefit of this approach is that in a multi-core AMP system, a single coredump might contain memory information from other cores. By analyzing this coredump along with the corresponding ELF files from the other cores, you can reconstruct the crash site of those other cores. Signed-off-by: anjiahao --- tools/minidumpserver.py | 88 ++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/tools/minidumpserver.py b/tools/minidumpserver.py index 6336e072d0..77b3b40fc2 100755 --- a/tools/minidumpserver.py +++ b/tools/minidumpserver.py @@ -287,11 +287,9 @@ class DumpELFFile: store = True desc = "text" elif (flags & SHF_WRITE_ALLOC) == SHF_WRITE_ALLOC: - # Data section - # - # Running app changes the content so no need - # to store - pass + # Data or Rodata section, rodata store in ram in some case + store = True + desc = "data or rodata" elif (flags & SHF_ALLOC) == SHF_ALLOC: # Read only data section store = True @@ -466,23 +464,66 @@ class RawMemoryFile: return self.__memories +class CoreDumpFile: + def __init__(self, coredump): + self.__memories = list() + + if coredump is None: + return + + with open(coredump, "rb") as f: + elffile = ELFFile(f) + for segment in elffile.iter_segments(): + if segment["p_type"] != "PT_LOAD": + continue + logger.debug(f"Segment Flags: {segment['p_flags']}") + logger.debug( + f"Segment Offset: {segment['p_offset']}", + ) + logger.debug(f"Segment Virtual Address: {hex(segment['p_vaddr'])}") + logger.debug(f"Segment Physical Address: {hex(segment['p_paddr'])}") + logger.debug(f"Segment File Size:{segment['p_filesz']}") + logger.debug(f"Segment Memory Size:{segment['p_memsz']}") + logger.debug(f"Segment Alignment:{segment['p_align']}") + logger.debug("=" * 40) + f.seek(segment["p_offset"], 0) + data = f.read(segment["p_filesz"]) + self.__memories.append( + pack_memory( + segment["p_paddr"], segment["p_paddr"] + len(data), data + ) + ) + else: + logger.debug("This CoreDump does not have program headers.") + + def get_memories(self): + return self.__memories + + class GDBStub: def __init__( - self, logfile: DumpLogFile, elffile: DumpELFFile, rawfile: RawMemoryFile + self, + logfile: DumpLogFile, + elffile: DumpELFFile, + rawfile: RawMemoryFile, + coredump: CoreDumpFile, ): self.registers = logfile.registers self.elffile = elffile self.socket = None self.gdb_signal = GDB_SIGNAL_DEFAULT + + # new list oreder is coredump, rawfile, logfile, elffile + self.mem_regions = ( - self.elffile.get_memories() - + logfile.get_memories() + coredump.get_memories() + rawfile.get_memories() + + logfile.get_memories() + + self.elffile.get_memories() ) self.reg_digits = elffile.xlen() // 4 self.reg_fmt = "