Revert 106592 for now. It causes clang-selfhost build failure.
[oota-llvm.git] / docs / SourceLevelDebugging.html
index 005eb13039629320fecbad8087cb5044188df1e2..2bbe18118e122bd8825b7b558beeedb58b6c70b2 100644 (file)
@@ -144,7 +144,7 @@ height="369">
    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>
 
@@ -237,7 +237,7 @@ height="369">
 <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>
@@ -289,26 +289,25 @@ height="369">
    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 &lt;&lt; 16 or 0x80000 or
    524288.)</a></p>
 
 <p>The details of the various descriptors follow.</p>  
@@ -370,7 +369,7 @@ height="369">
 </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>
 
@@ -402,7 +401,7 @@ height="369">
   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>
@@ -434,6 +433,13 @@ provide details such as name, type and where the variable is defined.</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)
+  i32       ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
+  i32       ;; Index into a virtual function
+  metadata, ;; indicates which base type contains the vtable pointer for the 
+            ;; derived class
+  i1        ;; isArtificial
+  i1        ;; isOptimized
+  Function *;; Pointer to LLVM function
 }
 </pre>
 </div>
@@ -783,11 +789,11 @@ DW_TAG_return_variable = 258
 
 <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>
@@ -801,7 +807,7 @@ DW_TAG_return_variable = 258
 
 <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
@@ -829,8 +835,8 @@ DW_TAG_return_variable = 258
    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>
@@ -855,14 +861,14 @@ entry:
   %X = alloca i32, align 4                        ; &lt;i32*&gt; [#uses=4]
   %Y = alloca i32, align 4                        ; &lt;i32*&gt; [#uses=4]
   %Z = alloca i32, align 4                        ; &lt;i32*&gt; [#uses=3]
-  %0 = bitcast i32* %X to { }*                    ; &lt;{ }*&gt; [#uses=1]
-  call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
+  %0 = bitcast i32* %X to {}*                     ; &lt;{}*&gt; [#uses=1]
+  call void @llvm.dbg.declare({}* %0, metadata !0), !dbg !7
   store i32 21, i32* %X, !dbg !8
-  %1 = bitcast i32* %Y to { }*                    ; &lt;{ }*&gt; [#uses=1]
-  call void @llvm.dbg.declare({ }* %1, metadata !9), !dbg !10
+  %1 = bitcast i32* %Y to {}*                     ; &lt;{}*&gt; [#uses=1]
+  call void @llvm.dbg.declare({}* %1, metadata !9), !dbg !10
   store i32 22, i32* %Y, !dbg !11
-  %2 = bitcast i32* %Z to { }*                    ; &lt;{ }*&gt; [#uses=1]
-  call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
+  %2 = bitcast i32* %Z to {}*                     ; &lt;{}*&gt; [#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                   ; &lt;i32&gt; [#uses=1]
   %tmp1 = load i32* %Y, !dbg !16                  ; &lt;i32&gt; [#uses=1]
@@ -873,7 +879,7 @@ entry:
   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 ]
@@ -915,7 +921,7 @@ declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
 
 <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>
 
@@ -950,7 +956,7 @@ call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
 
 <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>
 
@@ -967,7 +973,7 @@ call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
 </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>
 
@@ -1069,6 +1075,18 @@ int main(int argc, char *argv[]) {
 </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>
 
 <!-- ======================================================================= -->