Skip to content
Snippets Groups Projects
Commit 0c51e4b9 authored by Avi Kivity's avatar Avi Kivity
Browse files

gdb: extract symbol/file/line resolution into a class

parent f53d6ca7
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,28 @@ def load_elf(path, base):
gdb.execute('add-symbol-file %s %s %s' % (path, text_addr, args))
class syminfo(object):
def __init__(self, addr):
infosym = gdb.execute('info symbol 0x%x' % addr, False, True)
self.func = infosym[:infosym.find(" + ")]
sal = gdb.find_pc_line(addr)
try :
# prefer (filename:line),
self.source = '%s:%s' % (sal.symtab.filename, sal.line)
except :
# but if can't get it, at least give the name of the object
if infosym.startswith("No symbol matches") :
self.source = None
else:
self.source = infosym[infosym.rfind("/")+1:].rstrip()
if self.source and self.source.startswith('../../'):
self.source = self.source[6:]
def __str__(self):
ret = self.func
if self.source:
ret += ' (%s)' % (self.source,)
return ret
def translate(path):
'''given a path, try to find it on the host OS'''
name = os.path.basename(path)
......@@ -672,20 +694,9 @@ def show_leak():
else :
gdb.write('%d' % r.minbirth)
gdb.write(']\nfrom:\n')
for f in reversed(r.callchain) :
infosym = gdb.execute('info symbol 0x%x' % f, False, True)
func = infosym[:infosym.find(" + ")]
sal = gdb.find_pc_line(f)
try :
# prefer (filename:line),
source = ' (%s:%s)' % (sal.symtab.filename, sal.line)
except :
# but if can't get it, at least give the name of the object
if infosym.startswith("No symbol matches") :
source = ''
else :
source = ' (%s)' % infosym[infosym.rfind("/")+1:].rstrip()
gdb.write('\t%s%s\n' % (func, source));
for f in reversed(r.callchain):
si = syminfo(f)
gdb.write('\t%s\n' % (si,))
gdb.write('\n')
class osv_trace(gdb.Command):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment