I want to debug Clang plugin.
However, I can't find informations about debugging of Clang plugin.
If you know how to debug Clang plugin, Could you tell me that information?
thanks.
When you invoke clang with -Xclang -plugin (...) it will fork into a child process. When invoking your plugin pass also the -v option to see the child process command line. Then use this command line in the debugger.
Both GDB and LLDB are of course excellent debuggers without doubt. GDB is debugger part of the GNU project created to work along the GNU compiler. LLDB is debugger part of the LLVM project created to work along LLVM compiler. The majority of the commands are the same.
You can use GDB or lldb with clang.
In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )
Just a small outline as i'm trying this myself atm. I am using lldb.
I am currently able to stop at any given function in the plugin but the source code is missing. It only shows the assembly.
When you invoke clang
with -Xclang -plugin (...)
it will fork into a child process. When invoking your plugin pass also the -v
option to see the child process command line. 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 output:
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 invoke lldb with:
lldb "/srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/clang-3.1"
And then in the lldb prompt you do
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With