Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB doesn't find sources

Tags:

c

gcc

debugging

gdb

I start gdb using this (working dir is /home/leon/Develop/tests/atomic/):

 gdb ./bin/lin64/httpress

Then I add directories with source files, and it understands me:

Source directories searched: /home/leon/Develop/tests/atomic/third/http_parser:/home/leon/Develop/tests/atomic/src/tools:$cdir:$cwd

When I run my binary, gdb doesn't recognize the line in my source code, where segfault happened. How to set source files for gdb?

The program is compiled by gcc:

gcc -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -O2   -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99  -lpthread -lev -lgnutls -O2 -s -DWITH_SSL -Wno-strict-aliasing \
        -I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c

Ok, I've made some changes:

gcc -g -ggdb -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99  -lpthread -lev -lgnutls -s -DWITH_SSL -Wno-strict-aliasing \
        -I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c

In this case it still can't find symbols in the binary. But if I remove -s option from gcc call. It writes:

Reading symbols from /home/leon/Develop/tests/atomic/bin/lin64/httpress...done.

But the debugger still says this:

(gdb) info source
No current source file.

...after I point him directories with sources.

like image 563
Leonid Avatar asked Nov 20 '13 12:11

Leonid


1 Answers

You miss the -g in your gcc call to include debugging information.

On the other hand, I suggest to decrease optimization level from -O2 to -O0 and use it only once (included gcc call has 2 -O2).

Apart of this, you can add directories to gdb's source path with dir command: Source_Path. But this would only work if you've proper debug information available in httpress

like image 136
jcm Avatar answered Oct 02 '22 19:10

jcm