clang - 为什么我没有从 LLVM 获得精确的行/列调试信息
问题描述
我正在编写一个非常简单的 LLVM 传递来简单地迭代函数中的所有指令。
bool TestInstrument::runOnFunction(Function &F)
{
for (inst_iterator it = inst_begin(F), E = inst_end(F); it != E; ++it)
{
std::string str;
llvm::raw_string_ostream ss(str);
ss << *it;
errs() << ss.str() << "\n";
const DebugLoc &location = (&(*it))->getDebugLoc();
if (location)
std::cout << " see line: " << location.getLine() << ", col " << location.getCol() << " \n";
else
std::cout << "no debugloc information detected\n";
}
return true;
}
我使用以下命令构建了我的通行证
clang -emit-llvm -S -fno-discard-value-names -c hello.c
opt -load ../build/InstrumentPass.so -Instrument -S hello.ll -o hello.instrumented.ll
opt -load ../build/SecondInstrumentPass.so -SecondInstrument -S hello.ll -o hello.second.instrumented.ll
clang -o hello ../lib/util.c hello.second.instrumented.ll
当我在一个非常简单的 hello world c 程序上运行上述仪器传递时,我可以看到每条迭代指令的打印输出。但是,没有一条指令找到 debugloc 信息。该位置的所有打印输出都显示“未检测到调试位置信息\n”。
这是打印的输出
%retval = alloca i32, align 4
no debug info!
store i32 0, i32* %retval, align 4
no debug info!
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0))
no debug info!
ret i32 0
no debug info!
找不到位置元数据有什么原因吗?提前致谢。
解决方案
我没有得到任何 debugloc 信息的原因是在我的构建命令中,我使用了
clang -emit-llvm -S -fno-discard-value-names -c hello.c
应该使用
clang -emit-llvm -S -fno-discard-value-names -c hello.c -g
-g 选项启用调试信息。
推荐阅读
- hadoop - Ranger 显示用于授予访问权限的 Hadoop-ACL 而不是 Ranger-ACL
- reactjs - Sending 'sent' data from a page to a component in Gatsby
- html - Angular Material Forms 和 Flex Layout - 在所有行中获得相等的输入宽度
- javascript - 错误 [ERR_MODULE_NOT_FOUND]:找不到包 'src'
- python - 字符串中的字符数(转义序列)
- flutter - 有没有办法在“Flutter web”应用程序的代码中获取用于启动应用程序的 URL?
- javascript - 如何在 javascript 中添加指向导航栏的链接?
- apache - 如何解决 %1 不是有效的 win32 应用程序。无法启动管道日志程序错误?
- protocols - Siemens S7、Omron FINS、Mitsubishi MC Protocol 和 Allen Bradley EntherNet Protocol
- ruby-on-rails - RoR ActiveRecord 半人工智能应用程序加入帮助