an LLVM user a relationship between generated code and the original program
source code.</p>
-<p>Currently, debug information is consumed by the DwarfWriter to produce dwarf
+<p>Currently, debug information is consumed by DwarfDebug to produce dwarf
information used by the gdb debugger. Other targets could use the same
information to produce stabs or other debug forms.</p>
<p>LLVM debugging information has been carefully designed to make it possible
for the optimizer to optimize the program and debugging information without
necessarily having to know anything about debugging information. In
- particular, te use of metadadta avoids duplicated dubgging information from
+ particular, the use of metadata avoids duplicated debugging information from
the beginning, and the global dead code elimination pass automatically
deletes debugging information for a function if it decides to delete the
function. </p>
0x1000.)</p>
<p>The fields of debug descriptors used internally by LLVM
- are restricted to only the simple data types <tt>int</tt>, <tt>uint</tt>,
- <tt>bool</tt>, <tt>float</tt>, <tt>double</tt>, <tt>mdstring</tt> and
- <tt>mdnode</tt>. </p>
+ are restricted to only the simple data types <tt>i32</tt>, <tt>i1</tt>,
+ <tt>float</tt>, <tt>double</tt>, <tt>mdstring</tt> and <tt>mdnode</tt>. </p>
<div class="doc_code">
<pre>
!1 = metadata !{
- uint, ;; A tag
+ i32, ;; A tag
...
}
</pre>
</div>
<p><a name="LLVMDebugVersion">The first field of a descriptor is always an
- <tt>uint</tt> containing a tag value identifying the content of the
+ <tt>i32</tt> containing a tag value identifying the content of the
descriptor. The remaining fields are specific to the descriptor. The values
of tags are loosely bound to the tag values of DWARF information entries.
However, that does not restrict the use of the information supplied to DWARF
targets. To facilitate versioning of debug information, the tag is augmented
- with the current debug version (LLVMDebugVersion = 8 << 16 or 0x80000 or
+ with the current debug version (LLVMDebugVersion = 8 << 16 or 0x80000 or
524288.)</a></p>
<p>The details of the various descriptors follow.</p>
</pre>
</div>
-<p>These descriptors contain informations for a file. Global variables and top
+<p>These descriptors contain information for a file. Global variables and top
level functions would be defined using this context.k File descriptors also
provide context for source line correspondence. </p>
metadata, ;; Reference to type descriptor
i1, ;; True if the global is local to compile unit (static)
i1, ;; True if the global is defined in the compile unit (not extern)
- { }* ;; Reference to the global variable
+ {}* ;; Reference to the global variable
}
</pre>
</div>
<div class="doc_text">
<pre>
- void %<a href="#format_common_declare">llvm.dbg.declare</a>( { } *, metadata )
+ void %<a href="#format_common_declare">llvm.dbg.declare</a>({}*, metadata)
</pre>
<p>This intrinsic provides information about a local element (ex. variable.) The
- first argument is the alloca for the variable, cast to a <tt>{ }*</tt>. The
+ first argument is the alloca for the variable, cast to a <tt>{}*</tt>. The
second argument is
the <tt>%<a href="#format_variables">llvm.dbg.variable</a></tt> containing
the description of the variable. </p>
<div class="doc_text">
<pre>
- void %<a href="#format_common_value">llvm.dbg.value</a>( metadata, i64, metadata )
+ void %<a href="#format_common_value">llvm.dbg.value</a>(metadata, i64, metadata)
</pre>
<p>This intrinsic provides information when a user source variable is set to a
rules.</p>
<p>In order to handle this, the LLVM debug format uses the metadata attached to
- llvm instructions to encode line nuber and scoping information. Consider the
- following C fragment, for example:</p>
+ llvm instructions to encode line number and scoping information. Consider
+ the following C fragment, for example:</p>
<div class="doc_code">
<pre>
%X = alloca i32, align 4 ; <i32*> [#uses=4]
%Y = alloca i32, align 4 ; <i32*> [#uses=4]
%Z = alloca i32, align 4 ; <i32*> [#uses=3]
- %0 = bitcast i32* %X to { }* ; <{ }*> [#uses=1]
- call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
+ %0 = bitcast i32* %X to {}* ; <{}*> [#uses=1]
+ call void @llvm.dbg.declare({}* %0, metadata !0), !dbg !7
store i32 21, i32* %X, !dbg !8
- %1 = bitcast i32* %Y to { }* ; <{ }*> [#uses=1]
- call void @llvm.dbg.declare({ }* %1, metadata !9), !dbg !10
+ %1 = bitcast i32* %Y to {}* ; <{}*> [#uses=1]
+ call void @llvm.dbg.declare({}* %1, metadata !9), !dbg !10
store i32 22, i32* %Y, !dbg !11
- %2 = bitcast i32* %Z to { }* ; <{ }*> [#uses=1]
- call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
+ %2 = bitcast i32* %Z to {}* ; <{}*> [#uses=1]
+ call void @llvm.dbg.declare({}* %2, metadata !12), !dbg !14
store i32 23, i32* %Z, !dbg !15
%tmp = load i32* %X, !dbg !16 ; <i32> [#uses=1]
%tmp1 = load i32* %Y, !dbg !16 ; <i32> [#uses=1]
ret void, !dbg !18
}
-declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
+declare void @llvm.dbg.declare({}*, metadata) nounwind readnone
!0 = metadata !{i32 459008, metadata !1, metadata !"X",
metadata !3, i32 2, metadata !6}; [ DW_TAG_auto_variable ]
<div class="doc_code">
<pre>
-call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
+call void @llvm.dbg.declare({}* %0, metadata !0), !dbg !7
</pre>
</div>
<div class="doc_code">
<pre>
-call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
+call void @llvm.dbg.declare({}* %2, metadata !12), !dbg !14
</pre>
</div>
</pre>
</div>
-<p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declaread at line number 5 and
+<p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declared at line number 5 and
column number 9 inside of lexical scope <tt>!13</tt>. The lexical scope
itself resides inside of lexical scope <tt>!1</tt> described above.</p>
</pre>
</div>
+<p>llvm::Instruction provides easy access to metadata attached with an
+instruction. One can extract line number information encoded in LLVM IR
+using <tt>Instruction::getMetadata()</tt> and
+<tt>DILocation::getLineNumber()</tt>.
+<pre>
+ 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();
+ }
+</pre>
</div>
<!-- ======================================================================= -->