Add a gdb script to show backtrace with Mach-O symbols.

This commit is contained in:
Shinichiro Hamaji 2011-03-26 04:04:18 +09:00
parent fa8b47d788
commit 2a4cd68ca3
2 changed files with 40 additions and 0 deletions

11
.gdbinit Normal file
View File

@ -0,0 +1,11 @@
python sys.path.insert(0, '.')
python import gdb_maloader
define mreload
python reload(gdb_maloader)
end
define mbt
mreload
python gdb_maloader.bt()
end

29
gdb_maloader.py Normal file
View File

@ -0,0 +1,29 @@
import gdb
import os
import re
import sys
def bt():
# Find the newest frame.
frame = gdb.selected_frame()
while True:
next = frame.newer()
if not next:
break
frame = next
pipe = os.popen('c++filt', 'w')
i = 0
while frame:
s = gdb.execute('p dumpExportedSymbol((void*)0x%x)' % frame.pc(),
to_string=True)
m = re.match(r'.*"(.*)"$', s)
if m:
pipe.write("%s\n" % m.group(1))
else:
pipe.write("0x%x\n" % frame.pc())
frame = frame.older()
i += 1
pipe.close()