gdbserver:skip load symbol if use logfile as input

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2024-09-02 12:23:39 +08:00 committed by Xiang Xiao
parent ddf44def10
commit 7c37a46f69
1 changed files with 56 additions and 36 deletions

View File

@ -30,6 +30,7 @@ import socket
import struct
import subprocess
import sys
import traceback
import elftools
from elftools.elf.elffile import ELFFile
@ -263,7 +264,7 @@ class DumpELFFile:
self.__xlen = None
self.__text = 0
def parse(self):
def parse(self, load_symbol: bool):
self.__memories = []
elf = ELFFile.load_from_path(self.elffile)
self.__arch = elf.get_machine_arch().lower().replace("-", "")
@ -313,6 +314,8 @@ class DumpELFFile:
if segment.header.p_flags & 1 and not self.__text:
self.__text = segment.header.p_vaddr
self.load_symbol = load_symbol
if load_symbol:
symtab = elf.get_section_by_name(".symtab")
self.symbol = {}
for symbol in symtab.iter_symbols():
@ -332,7 +335,6 @@ class DumpELFFile:
)
elf.close()
return True
def merge(self, other):
@ -537,6 +539,7 @@ class GDBStub:
self.threadinfo = []
self.current_thread = 0
if elffile.load_symbol:
try:
self.parse_thread()
logger.debug(f"Have {len(self.threadinfo)} threads to debug.")
@ -553,8 +556,12 @@ class GDBStub:
except TypeError:
if not self.registers:
logger.critical(
"Logfile, coredump, or rawfile do not contain register. Please check if the files are correct."
"Logfile, coredump, or rawfile do not contain register,"
"Please check if the files are correct."
)
stack_trace = traceback.format_exc()
logger.debug(stack_trace)
sys.exit(1)
def get_gdb_packet(self):
@ -1017,6 +1024,15 @@ def arg_parser():
help="coredump file, will prase memory in this file",
)
parser.add_argument(
"-s",
"--symbol",
action="store_true",
help="Analyze the symbol table in the ELF file, use in thread awareness"
"if use logfile input, this option will is false by default"
"if use rawfile or coredump input, this option will is true by default",
)
parser.add_argument(
"--debug",
action="store_true",
@ -1101,7 +1117,11 @@ def main(args):
config_log(args.debug)
elf = DumpELFFile(args.elffile[0])
elf.parse()
if args.symbol is False:
if args.rawfile or args.coredump:
args.symbol = True
elf.parse(args.symbol)
elf_texts = [elf.text()]
for name in args.elffile[1:]:
other = DumpELFFile(name)