gpt4 book ai didi

clang - 如何使用 lldb(或 gdb)调试 Clang 插件

转载 作者:行者123 更新时间:2023-12-05 00:33:28 25 4
gpt4 key购买 nike

我想调试 Clang 插件。
但是,我找不到有关 Clang 插件调试的信息。
如果你知道如何调试 Clang 插件,你能告诉我这些信息吗?
谢谢。

最佳答案

只是一个小轮廓,因为我正在尝试这个 atm。我正在使用 lldb。

我目前能够在插件中的任何给定函数处停止,但缺少源代码。它只显示组件。

当您调用 clang-Xclang -plugin (...)它将 fork 到一个子进程中。当调用你的插件时,还有 -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


这应该有效。

关于clang - 如何使用 lldb(或 gdb)调试 Clang 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12111982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com