diff --git a/scripts/loader.py b/scripts/loader.py index eedc4259f6e5d622a3a02907dc5fa4cba103a26f..1b980006e5adab90d5dcd00e937e6ee45ac703eb 100644 --- a/scripts/loader.py +++ b/scripts/loader.py @@ -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):