gdb Objective-C No Symbol Table
I have to debug a Cocoa/Objective-C app that has had its symbols stripped. I am pretty well versed in gdb and Objective-C. Normally, I use tools like otool or cl开发者_如何学JAVAass-dump to find out what I need to make debugging a little easier. For example, class-dump makes it easy to know where, at runtime, certain methods live.
My question is: Can I "help" gdb provide better symbolic information at runtime when looking at backtraces? In the following backtrace I know (from using class-dump) what all of the methods marked as "??" are. It would be great if I could get gdb to do this for me.
Thanks!
(gdb) bt
#0 0x960de54e in -[NSPersistentUIManager init] ()
#1 0x960de489 in __PersistentUIManager_block_invoke_1 ()
#2 0x9abd0693 in _NSFaultInObject ()
#3 0x960ad800 in +[NSPersistentUIManager sharedManager] ()
#4 0x961aefac in -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] ()
#5 0x961aeefd in -[NSWindow orderWindow:relativeTo:] ()
#6 0x96238acc in -[NSWindow orderFront:] ()
#7 0x0000a032 in ?? ()
#8 0x9154bdaa in -[NSObject performSelector:] ()
#9 0x9154bd27 in -[NSSet makeObjectsPerformSelector:] ()
#10 0x960c16a7 in -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] ()
#11 0x960b744d in loadNib ()
#12 0x960b6834 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] ()
#13 0x960b673e in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] ()
#14 0x960b6672 in +[NSBundle(NSNibLoading) loadNibNamed:owner:] ()
#15 0x9633d6c7 in NSApplicationMain ()
#16 0x00002cc6 in ?? ()
#17 0x00002bed in ?? ()
You would need the symbol tables that were generated at the time of the build; typically, the .dSYM folder(s). With those, you can add-symbol-table
in GDB and it'll generally figure things out a bit more.
You can't really produce the symbol tables after the fact. Many developers will archive off a copy of the symbol tables for various production releases of their app such that crash traces can be symbolicated and reproducible crashes (that only reproduce on production builds or a particular client install) can be debugged more easily.
The ?? frames are, most likely, C functions for which there are no symbols -- certainly #16 and #17 are _start() and main(). #7 is likely some CF goober used for the -performSelector: internals.
It would be great if I could get gdb to do this for me.
I expect you should be able to. (I haven't done this for Objective-C, only for plain-C, but I can't imagine there will be any difference).
For C
, suppose you want to teach GDB that foobar()
is at address 0x12345678
. Then:
echo 'void foobar() { }' | gcc -c -xc- -o foobar.o
(gdb) add-symbol-file foobar.o 0x12345678
(This works because in relocatable foobar.o
the address of foobar()
would normally be 0
.)
精彩评论