From c5e198f34351cefb67bfecba9f589c6f1474e54c Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Fri, 17 Feb 2023 15:16:30 +0100 Subject: [PATCH] analysis/datastub/SymbolInfo: Get debug file using gdb For libc and other installed libaries a separate package can be installed to access debug symbols. But for this a separate elffile is stored with an arbitrary name. gdb does automagically detect this and loads the correct files. If nm fails to load any symbols, gdb is used as a fallback to find the debug elffile. --- analysis/datastub/SymbolInfo.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/analysis/datastub/SymbolInfo.py b/analysis/datastub/SymbolInfo.py index e62531ab..38b029b0 100644 --- a/analysis/datastub/SymbolInfo.py +++ b/analysis/datastub/SymbolInfo.py @@ -36,6 +36,17 @@ """ +def getdebugelf(fname): + command = f"gdb -ex quit {fname}" + output = subprocess.check_output(command.split(" ")).decode("utf-8") + lines = output.splitlines() + assert lines[-2].find(fname) != -1 + if lines[-1].find("No debugging symbols found") != -1: + return None + assert lines[-2].find("Reading symbols from") != -1 + return lines[-1].split(" ")[-1].split("...")[0] + + def readelfsyms(fname, image): try: command = "objdump --demangle -f %s" % (fname) @@ -53,7 +64,13 @@ def readelfsyms(fname, image): return None if lines is None or len(lines) == 0: - return None + debug(0, f"No symbols found in {fname}") + fname = getdebugelf(fname) + if fname is None: + debug(0, "GDB didnot found any debug file") + return None + debug(0, f"GDB found debug file: {fname}") + return readelfsyms(fname, image) syms = [] for line in lines: