我想调试 Clang 插件。
但是,我找不到有关调试 Clang 插件的信息。
如果你知道如何调试 Clang 插件,你能告诉我这些信息吗?谢谢。
问问题
4990 次
1 回答
10
只是一个小轮廓,因为我自己正在尝试这个 atm。我正在使用lldb。
我目前能够停止插件中的任何给定功能,但缺少源代码。它只显示程序集。
当您调用它时clang
,-Xclang -plugin (...)
它将分叉到一个子进程中。调用插件时,还可以-v
选择查看子进程命令行。然后在调试器中使用这个命令行。
原始命令行:
$> clang++ -Xclang -load -Xclang ${PLUGIN} -Xclang -plugin -Xclang cgd -std=c++11 -w -fsyntax-only -v
应该输出:
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.
这是您需要的部分:
"/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
现在您使用以下命令调用 lldb:
lldb "/srv/scratch/sigubufo/clang/stable/3.1_src/build/bin/clang-3.1"
然后在 lldb 提示符下执行
(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
这应该有效。
于 2012-09-17T10:08:34.687 回答