I want to debug a process running on Linux 2.6 using GDB. attach PID (where PID is the process identifier), print main , print sin , print gzopen and print dlopen work (i.e. find the corresponding characters). But print myfoo does not work, where myfoo is a function loaded by a process from a .so file using dlopen . Here is what I get:
(gdb) print main $3 = {int (int, char **)} 0x805ba90 <main> (gdb) print sin $4 = {<text variable, no debug info>} 0xb7701230 <sin> (gdb) print gzopen $5 = {<text variable, no debug info>} 0xb720df50 <gzopen> (gdb) print dlopen $6 = {<text variable, no debug info>} 0xb77248e0 <__dlopen_nocheck> (gdb) print myfoo No symbol "myfoo" in current context.
How do I get gdb to find myfoo ?
The myfoo function really exists, because in the program I managed to get its address using dlsym (after dlopen ), and I managed to call it. Only after that I connected GDB to the process.
It turned out that there was an error message mydir/mylib.so: No such file or directory , printed by the attach $PID GDB command. Obviously, GDB was running in the wrong directory. Running the correct cd before starting GDB print myfoo problem and print myfoo started to work.
I would like to automate this: I want GDB to find out where my .so files are (downloaded with dlopen ). The approximation I can think of is looking at /proc/$PID/maps (on Linux), finding possible directories and adding all of them to the GDB library search path before starting GDB. The LD_LIBRARY_PATH extension and the execution of set solib-search-path /tmp/parent did not work ( ls -l /tmp/parent/mydir/myfoo.so really works), GDB still reported No such file or directory . How to tell GDB where to look for mydir/myfoo.so ?
My other question is: how do I get a list of possible directories? Linux /proc/$PID/maps contains them, but what about other operating systems such as FreeBSD and Mac OS X?
linux shared-libraries gdb
pts
source share