[LLVMdev] How to read v3.3 dbg metadata using v3.4 LLVM

James Stark mrjamesstark at gmail.com
Wed Jan 22 20:56:19 PST 2014


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/20140122/3a4fda7e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.o
Type: application/octet-stream
Size: 1552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140122/3a4fda7e/attachment.o>


More information about the llvm-dev mailing list