简体   繁体   中英

GDB doesn't find sources

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

But the debugger still says this:

(gdb) info source
No current source file.
...after I point him directories with sources.

This is expected . There is no current source because you haven't started executing your binary yet.

You want to start or run your binary and get it to some place in execution (eg main , or the crash point).

Remove optimize flag :

-O2

And add that flags:

-g -ggdb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM