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

霸气de小男生 提交于 2019-12-09 17:07:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11579747/gdb-doesnt-find-source-files-compiled-by-clang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!