如http://llvm.org/docs/SourceLevelDebugging.html中所述,
我可以使用以下代码从LLVM IR中找到源代码的行号和列号.
if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction
DILocation Loc(N); // DILocation is in DebugInfo.h
unsigned Line = Loc.getLineNumber();
StringRef File = Loc.getFilename();
StringRef Dir = Loc.getDirectory();
}
Run Code Online (Sandbox Code Playgroud)
但是,我想要更准确的信息.
在AST级别,clang提供FullSourceLoc API(getCharaterData()
),以便我可以找到AST节点和原始源代码之间的映射.我想在LLVM IR和源代码之间找到这样的映射.
我可以从IR的调试信息中获取确切的特征数据吗?
谢谢.
不可能仅从IR调试信息中获取确切的字符数据.您可以做的最好的事情是在某处手动保存源代码,然后使用从调试信息中获得的行和列信息.
顺便说一句,还有一个更简单的方式来获得调试信息Instruction
S:Instruction::getDebugLoc()
返回一个DebugLoc
实例,该实例然后你可以查询getLine()
和getCol()
(但一定要用它来检查一下isUnknown
第一种方法).
归档时间: |
|
查看次数: |
1550 次 |
最近记录: |