[root@xxx memcached-1.4.5]# objdump -R memcached-debug |grep freeaddrinfo
0000000000629e10 R_X86_64_JUMP_SLOT freeaddrinfo
...
(gdb) disas freeaddrinfo
Dump of assembler code for function freeaddrinfo:
0x00000037aa4baf10 <freeaddrinfo+0>: push %rbp
0x00000037aa4baf11 <freeaddrinfo+1>: push %rbx
0x00000037aa4baf12 <freeaddrinfo+2>: mov %rdi,开发者_如何学Go%rbx
So I know freeaddrinfo
is a dynamically linked function,but how to know which .so
it's defined in?
See this answer. The info symbol freeadrinfo
is one way to find out.
On Linux and Solaris you can also use ldd
and LD_DEBUG=symbols
. For example, if you wanted to find out where localtime
in /bin/date
is coming from:
LD_DEBUG=bindings ldd -r /bin/date 2>&1 | grep localtime
26322: binding file /bin/date [0] to /lib/libc.so.6 [0]: normal symbol `localtime' [GLIBC_2.2.5]
For certain low version gdb, "info symbol " could not work as you want.
So please use below method:
Run 'p symbol_name' to get symbol address
(gdb) p test_fun $1 = {<text variable, no debug info>} 0x84bcc4 <test_fun>
Check /proc/PID/maps to find out the module which the symbol address is in.
# more /proc/23275/maps 007ce000-0085f000 r-xp 00000000 fd:00 3524598 /usr/lib/libtest.so
0x84bcc4 is in [007ce000, 0085f000]
Inside the libraries directory you could execute the following command to search for a specific symbol on all libraries:
for file in $(ls -1 *.so); do echo "-------> $file"; nm $file; done | c++filt | grep SYMBOL*
An enhanced version would be to list all libraries that are linked to the executable (through ldd) and go after each library listed searching if the symbol is defined there. Depending on your *nix you might have to tweak the cut parsing:
APP=firefox; for symbol in $(nm -D $APP | grep "U " | cut -b12-); do for library in $(ldd $APP | cut -d ' ' -f3- | cut -d' ' -f1); do for lib_symbol in $(nm -D $library | grep "T " | cut -b12-); do if [ $symbol == $lib_symbol ]; then echo "Found symbol: $symbol at [$library]"; fi ; done; done; done;
精彩评论