Search code examples
linuxdebuggingllvm-clang

How to get LLVM debug symbols


I've got a c++-project which uses Clang API, and I'd like to have ability to debug into clang/llvm function when I debugging my project.

I built llvm+clang v3.7.0 using CMake with the following opts:

 -DCMAKE_INSTALL_PREFIX=$HOME/opt/llvm -DCMAKE_BUILD_TYPE=Debug

but GDB doesn't step into clang API's functions.

What am I doing wrong?


Solution

  • It's likely what you're doing is not setting a breakpoint on the command line with -cc1 on it. clang forks immediately for error handling purposes, so if you set a breakpoint on main you'll see it happen. If you want to debug starting at clang then you should:

    • Build with debug symbols (looks like you're doing that)
    • Run clang with -v to get the various command lines, e.g.

      dzur:~/tmp> ~/builds/build-llvm/bin/clang -v t.c -S

      "/usr/local/google/home/echristo/builds/build-llvm/bin/clang-3.9" -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name t.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -coverage-file /usr/local/google/home/echristo/tmp/t.c -resource-dir /usr/local/google/home/echristo/builds/build-llvm/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /usr/local/google/home/echristo/builds/build-llvm/bin/../lib/clang/3.9.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /usr/local/google/home/echristo/tmp -ferror-limit 19 -fmessage-length 120 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o t.s -x c t.c

    • Set a breakpoint on the this command line where you'd like in the sources.