Skip to content

Commit

Permalink
analysis/datastub/SymbolInfo: Get debug file using gdb
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aewag committed Mar 13, 2023
1 parent 7cfc71c commit c5e198f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion analysis/datastub/SymbolInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit c5e198f

Please sign in to comment.