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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With