Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb doesn't find source files compiled by clang++

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?

like image 383
robert Avatar asked Jul 20 '12 12:07

robert


1 Answers

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.

like image 159
Rene Avatar answered Oct 01 '22 20:10

Rene