[LLVMdev] Mapping bitcode to source code

208 views
Skip to first unread message

Trevor Harmon

unread,
Feb 8, 2010, 7:51:36 PM2/8/10
to LLVM-Developer Email List
Hi,

I'm looking for a way to map bitcode to the source code (C/C++) from
which it was generated. For example, the Java class file format has an
optional LineNumberTable attribute that maps each bytecode instruction
to a source code line number:

http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#22856

Is there something analogous in the LLVM environment? Thanks,

Trevor

_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Duncan Sands

unread,
Feb 8, 2010, 11:51:28 PM2/8/10
to Trevor Harmon, LLVM-Developer Email List
Hi Trevor,

> I'm looking for a way to map bitcode to the source code (C/C++) from
> which it was generated. For example, the Java class file format has an
> optional LineNumberTable attribute that maps each bytecode instruction
> to a source code line number:
>
> http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#22856
>
> Is there something analogous in the LLVM environment? Thanks,

this can be done using debug info. Check out
http://llvm.org/docs/SourceLevelDebugging.html

Ciao,

Duncan.

Trevor Harmon

unread,
Feb 9, 2010, 2:13:25 PM2/9/10
to Duncan Sands, LLVM-Developer Email List
On Feb 8, 2010, at 8:51 PM, Duncan Sands wrote:

> this can be done using debug info. Check out
> http://llvm.org/docs/SourceLevelDebugging.html


Wow, that threw me for a loop. I'm using the 2.6 release, thinking I
was up to date, but its debug output doesn't look anything like what's
described in the above link. It appears to document the upcoming 2.7
version, which for some reason produces different debug syntax than
2.6. For example, the llvm.dbg.stoppoint intrinsic function no longer
exists in 2.7, and 2.6 has no "metadata" descriptors. Is there any
information about these changes and why they were necessary?

Also, is there an API for accessing the debug info? I looked through
the Programmer's Manual but didn't see anything.

Thanks,

Trevor

Trevor Harmon

unread,
Feb 9, 2010, 6:16:00 PM2/9/10
to Duncan Sands, LLVM-Developer Email List
On Feb 9, 2010, at 11:13 AM, Trevor Harmon wrote:

> Is there any information about these changes and why they were
> necessary?

I think I found it:

http://nondot.org/~sabre/LLVMNotes/EmbeddedMetadata.txt

Still looking for an API to access the metadata...

Jeffrey Yasskin

unread,
Feb 10, 2010, 12:37:59 AM2/10/10
to Trevor Harmon, LLVM-Developer Email List
On Tue, Feb 9, 2010 at 3:16 PM, Trevor Harmon <Trevor....@nasa.gov> wrote:
> On Feb 9, 2010, at 11:13 AM, Trevor Harmon wrote:
>
>> Is there any information about these changes and why they were
>> necessary?
>
> I think I found it:
>
> http://nondot.org/~sabre/LLVMNotes/EmbeddedMetadata.txt
>
> Still looking for an API to access the metadata...

Does http://llvm.org/doxygen/DebugInfo_8h.html help?

Devang Patel

unread,
Feb 10, 2010, 12:34:26 PM2/10/10
to Trevor Harmon, LLVM-Developer Email List
On Tue, Feb 9, 2010 at 11:16 PM, Trevor Harmon <Trevor....@nasa.gov> wrote:
> On Feb 9, 2010, at 11:13 AM, Trevor Harmon wrote:
>
>> Is there any information about these changes and why they were
>> necessary?
>
> I think I found it:
>
> http://nondot.org/~sabre/LLVMNotes/EmbeddedMetadata.txt
>
> Still looking for an API to access the metadata...

If you want to map llvm instruction to the source location then try

if (MDNode *N = I->getMetadata("dbg")) { // Where 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();
}

Note, this is new and it won't work in llvm2.6.
-
Devang

Reply all
Reply to author
Forward
0 new messages