为什么我没有从LLVM获得精确的行/列调试信息

时间:2020-11-09 14:53:06

标签: clang llvm clang++ llvm-ir

我正在编写一个非常简单的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信息。该位置的所有打印输出均显示“未检测到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!

有什么原因找不到位置元数据?预先感谢。

1 个答案:

答案 0 :(得分:0)

我没有得到任何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选项启用调试信息。

相关问题