Symbol to Library in GDB

Q: I'm debugging with GDB. If I know the address of a symbol, how can I find the shared library that contains it?

A: Starting with the GDB that ships with Xcode 1.5 (Apple version gdb-330.1), you can do this by passing the address to info sharedlibrary. Listing 1 shows an example of doing this for the symbol RunCurrentEventLoopInMode.

Listing 1: Finding a symbol's shared library

$ gdb
GNU gdb 5.3-20030128 (Apple version gdb-330.1) [\x85]
0x900074c8 in mach_msg_trap ()
(gdb) p/a &RunCurrentEventLoopInMode
$1 = 0x927d5edc <RunCurrentEventLoopInMode>
(gdb) info sharedlibrary 0x927d5edc
  9 HIToolbox             F 0x927d0000        dyld Y Y  \
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/\
HIToolbox.framework/Versions/A/HIToolbox at 0x927d0000 (offset 0x0)

In earlier versions of GDB you could do the same thing by using info sharedlibrary to print information about all shared libraries, and then manually searching the list for the library that contains the address of interest. This new feature eliminates the need for a manual search.

Document Revision History

DateNotes
2004-11-15Shows how to find the library containing a symbol in GDB.

Posted: 2004-11-15


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.