When compiling my project with clang++, the path to the source files is apparently not included in the object code. This means that gdb is unable to find source files to display code with. For specific instances, I can use gdb's directory
command to add a directory, but my project has a lot of source directories and this gets annoying very quickly.
When I switch my configuration to use g++, gdb simply finds all my source files.
This functionality worked clang++ 2.9 on Snow Leopard, but doesn't work with clang++ 3.1 on Lion. I have XCode 4.3.2.
Is there a clang option that forces full paths to be used in object files? Might something else be wrong with my configuration?
I discovered this: the issue happens, when building projects with hierarchical makefiles. If a subdirectory has been built from a parent directory (in my makefile: make -w -C sub-dir
) then gdb can not open the source file. When changing into the sub-dir and calling make just for this directory then gdb finds the source. You can verify this by searching the build-path in the generated object files. I used strings object-file | grep $HOME
.
I noticed also: this was not happen for one object file: this file has not been compiled with CC. This file has been compiled with esql. At the end, esql calls CC.
That's why I tried this workaround: don't call clang directly from make. Call clang from a shell script.
$ cat ~/bin/mycc
/usr/bin/cc "$@"
$ export CC=mycc
$ make
Hurray! gdb opens the source files!
BTW: replacing make -w -C sub-dir
by (cd sub-dir;make -w)
is another workaround.
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