Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which library a specific function is defined in?

Tags:

gdb

objdump

[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,%rbx

So I know freeaddrinfo is a dynamically linked function,but how to know which .so it's defined in?

like image 921
compiler Avatar asked Apr 06 '11 08:04

compiler


2 Answers

For certain low version gdb, "info symbol " could not work as you want.

So please use below method:

  1. Run 'p symbol_name' to get symbol address

    (gdb) p test_fun $1 = {<text variable, no debug info>} 0x84bcc4 <test_fun>

  2. 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]

like image 150
Deli Zhang Avatar answered Nov 18 '22 10:11

Deli Zhang


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]
like image 34
Employed Russian Avatar answered Nov 18 '22 11:11

Employed Russian