How to debug a Clang plugin using lldb (or gdb)

I want to debug the Clang plugin.
However, I can not find debugging information for the Clang plugin.
If you know how to debug a Clang plugin, could you tell me this information? thanks.

+4
source share
1 answer

Just a small outline when I try to do this. I am using lldb.

Currently, I can stop at any given function in the plugin, but the source code is missing. It shows only the assembly.

When you call clang with -Xclang -plugin (...) , it goes into the child process. When invoking your plugin, also pass the -v option to see the command line of the child process. Then use this command line in the debugger.

Original command line:

 $> clang++ -Xclang -load -Xclang ${PLUGIN} -Xclang -plugin -Xclang cgd -std=c++11 -w -fsyntax-only -v 

should be displayed:

 clang version 3.1 (tags/RELEASE_31/final 163510) Target: x86_64-unknown-linux-gnu Thread model: posix "/srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/clang-3.1" -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name call_in_if.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -resource-dir /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -w -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /srv/scratch/sigubufo/danceos_wd/clang/qtcreator-build -ferror-limit 19 -fmessage-length 205 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -load lib/CallGraphDumper.so -plugin cgd -x c++ ../test_cases/call_in_if.cpp clang -cc1 version 3.1 based upon LLVM 3.1svn default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward /usr/local/include /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1/include /usr/include/x86_64-linux-gnu /usr/include End of search list. 

This is the part you need:

 "/srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/clang-3.1" -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name call_in_if.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -resource-dir /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -w -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /srv/scratch/sigubufo/danceos_wd/clang/qtcreator-build -ferror-limit 19 -fmessage-length 205 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -load lib/CallGraphDumper.so -plugin cgd -x c++ ../test_cases/call_in_if.cpp 

Now you call lldb with:

 lldb "/srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/clang-3.1" 

And then at the lldb command prompt you run

 (lldb) break set --name YourPlugin::FunctionToBreakAt (lldb) process launch -- -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -main-file-name call_in_if.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -resource-dir /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/../lib/clang/3.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -w -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /srv/scratch/sigubufo/danceos_wd/clang/qtcreator-build -ferror-limit 19 -fmessage-length 205 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -load lib/CallGraphDumper.so -plugin cgd -x c++ ../test_cases/call_in_if.cpp 

And that should work.

+6
source

All Articles