0
votes

I am debugging using gdb a C application which uses an installed library(wrote in C). The library is running as daemon process and accepts requests from application and process it. To debug the library daemon I have attached it in gdb and have loaded the libraries symbol file at proper address using commands "info sharedlibrary" and "add-symbol-file".

I have set the source code path using the dir command.

But still the stack trace does not show the file name and line numbers.

(gdb) bt
#0  0xffffe410 in __kernel_vsyscall ()
#1  0xf76b2377 in sem_wait () from /lib/libpthread.so.0
#2  0xf616196d in MySemaphoreWait () from /opt/demo/lib/libdemo.so.0
#3  0xf6130fe5 in ReadFile () from /opt/demo/lib/libdemo.so.0
#4  0xf77870df in ?? () from /opt/demo/lib/libtest.so.0
#5  0xf778016e in ?? () from /opt/demo/lib/libtest.so.0
#6  0xf77584b9 in ServiceRequest () from /opt/novell/lib/libtest.so.0
#7 0xf7744c8a in Demo_Main () from /opt/novell/lib/libtest.so.0

What might be the reason the same and how get rid of it?

1

1 Answers

0
votes

I have attached it in gdb and have loaded the libraries symbol file at proper address using commands "info sharedlibrary" and "add-symbol-file".

On Linux, attaching the process should be sufficient for GDB to load symbols from all shared libraries, and add-symbol-file should not be required.

As a guess, you did something like this:

make install COPT=-O2  # build/install optimized version of libtest.so.0
# start daemon using it
make COPT=-g  # build debug version of libtest.so.0
gdb -p <daemon-pid>
(gdb) info shared
(gdb) add-symbol-file /path/to/dbg-version/libtest.so.0 <address>

That doesn't work, because optimized and debug builds produce totally different binaries with totally different symbol values.

What you want to do is install debug version, restart daemon, and debug that (you wouldn't need add-symbol-file in that case).

Alternatively, you may want to do this:

make COPT='-g -O2'

That builds a matching optimized version, but with debug info. You can then use add-symbol-file to point GDB to the optimized version with debug info.

Beware: debugging optimized code is (relatively) hard. Don't expect next command to take you to the next line, don't expect to be able to examine all the variables, etc.