[LLVMdev] How to read v3.3 dbg metadata using v3.4 LLVM
Eric Christopher
echristo at gmail.com
Wed Jan 22 22:14:52 PST 2014
This is likely going to be difficult if possible. I wouldn't bet on it
working that way. We've not been trying to keep compatibility between
versions for debug information metadata because the format has been in such
flux and upgrading/multiple versions is a significant overhead.
You might be able to walk the instructions and grab the scope + line/column
that way for each instruction. You can see the format of each metadata node
by looking at DebugInfo.h. Hope this helps, feel free to send mail if you
have any more questions.
-eric
On Wed Jan 22 2014 at 8:59:36 PM, James Stark <mrjamesstark at gmail.com>
wrote:
> Hi,
>
> I have bitcode files built by LLVM v3.3 and need to process them using
> v3.4 tools. While I don't expect a lot of backward compatibility in LLVM,
> luckily it seems everything's working fine, except for reading source line
> information attached to instructions. I use this piece of code [0] to get
> source line information. For v3.4, instruction.getMetadata returns NULL.
>
> I used llvm-dis to see what's going on. For a sample program [1], llvm-dis
> v3.3, of course, didn't have problems and dumped [2], showing dbg info.
> However, llvm-dis v3.4 seemed to have problems grabbing the dbg info [3].
>
> Any idea how I can modify the code [0] to solve the problem? Attached is
> the bitcode file used as an example in this mail. It was complied with
> clang v3.3 -g -O0.
>
> Thanks,
> James
>
> [0]
>
> llvm::LLVMContext llvmContext;
>
> unsigned dbgKind = llvmContext.getMDKindID("dbg");
>
> if (MDNode *N = instruction.getMetadata(dbgKind)){
>
> DILocation location(N);
>
> fileDirectoryName = location.getDirectory();
>
> fileName = location.getFilename();
>
> lineNumber = location.getLineNumber();
>
> columnNumber = location.getColumnNumber();
>
> }
> [1]
>
> int main(int argc, char **argv){
>
> return 0;
>
> }
>
> [2]
>
> define i32 @main(i32 %argc, i8** %argv) #0 {
>
> entry:
>
> %retval = alloca i32, align 4
>
> %argc.addr = alloca i32, align 4
>
> %argv.addr = alloca i8**, align 8
>
> store i32 0, i32* %retval
>
> store i32 %argc, i32* %argc.addr, align 4
>
> call void @llvm.dbg.declare(metadata !{i32* %argc.addr}, metadata !12),
> !dbg !13
>
> store i8** %argv, i8*** %argv.addr, align 8
>
> call void @llvm.dbg.declare(metadata !{i8*** %argv.addr}, metadata !14),
> !dbg !13
>
> ret i32 0, !dbg !15
>
> }
>
> [3]
>
> define i32 @main(i32 %argc, i8** %argv) #0 {
>
> entry:
>
> %retval = alloca i32, align 4
>
> %argc.addr = alloca i32, align 4
>
> %argv.addr = alloca i8**, align 8
>
> store i32 0, i32* %retval
>
> store i32 %argc, i32* %argc.addr, align 4
>
> store i8** %argv, i8*** %argv.addr, align 8
>
> ret i32 0
>
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140123/37874e7b/attachment.html>
More information about the llvm-dev
mailing list