问题描述
我正在尝试使用DILocation类从llvm指令中获取调试元数据.
I'm trying to get debugging metadata from an llvm Instruction using the DILocation class.
但是,当我在DILocation中查询指令所在的文件名时,会得到一个带有目录标记在最前面.
However, when I query the DILocation for the filename where the instruction came from, I get a filename with adirectory tagged onto the front.
我虽然会只返回文件并且应该通过调用getDirectory()来检索整个目录路径.
I though it would return just the fileand the entire directory path should be retrieved via a call to getDirectory().
例如,我没有使用XMain_0.c,而是使用了pbg/XMain_0.c
For example, instead of XMain_0.c I end up with pbg/XMain_0.c
我这样编译我的位代码:
I compiled my bitcode like this:
XMain_0.o: pbg/XMain_0.c
$(CC) <snip> -c pbg/XMain_0.c
我在源代码中传递了带有目录的事实吗?意味着元数据会将源文件名保存为输入?
Does the fact that I passed in my source with a directory on itmean that the metadata saves the source filename as the input?
这是一个简化的示例:
const llvm::Instruction* inst //passed in
MDNode *n = inst->getMetadata("dbg");
DILocation loc(n);
file = loc.getFilename().str(); // => pbg/XMain_0.c
dir = loc.getDirectory().str(); // => /projects/pbg/pbg-m/DIR
我可以打电话来标准化"此数据吗?还是需要手工处理?
Are there calls I can make to "normalize" this data or do I need to do it by hand?
如果有必要,请使用Clang 3.1.
Clang 3.1 if that matters.
推荐答案
我认为这取决于编译器的调用.如果您运行:
I think it depends on the invocation of the compiler. If you run:
clang -c somedir/somefile.c
然后,完整的somedir/somefile.c
将是文件名.
Then the full somedir/somefile.c
will be the filename.
您的调用看起来如何?
没有什么奇怪的.调试器将查找相对于某个项目根目录的源文件,如果您像这样编译文件,则将找到它们. gcc做同样的事情:
There is nothing weird about it. The debugger will look for source files relative to some project root, and if you compile files likes this, it's the way they are going to be found. gcc does the same thing:
/tmp$ pwd
/tmp
/tmp$ cat subdir/test.c
int foo() {
return 42;
}
/tmp$ gcc -g -O0 -c subdir/test.c -o test.o
/tmp$ readelf --debug-dump=info test.o | grep -A4 compile_unit
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x0): GNU C 4.6.3
<10> DW_AT_language : 1 (ANSI C)
<11> DW_AT_name : (indirect string, offset: 0xc): subdir/test.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x1a): /tmp
这篇关于llvm :: DIInstruction getFilename返回带有目录的文件名,我只想要文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!