gdb doesn't find source files compiled by clang++
Asked Answered
C

1

9

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?

Cabalism answered 20/7, 2012 at 12:50 Comment(2)
I am not sure but have you did a -d ?Quartziferous
@NeelBasu My source files are spread over 40 directories, and I'd rather not use -d 40 times.Cabalism
T
4

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.

Threnode answered 29/8, 2012 at 6:19 Comment(3)
This is interesting, but I use waf, in which sources are included in a hierarchical manner, but waf itself is not hierarchical.Cabalism
Verified: crated a small project. Using waf to build the project. gdb fails: 1 ../dir1/foo.c: No such file or directory.. After rebuilding the project with: CC=mycc ./waf-1.6.1 configure build the problem is gone: (gdb) list main 1 int main(){ 2 return 0; 3 }Threnode
This is also a problem using clang from QT Creator (for me anyway) your suggested fix worked for me.Alitaalitha

© 2022 - 2024 — McMap. All rights reserved.