On Sat, Aug 28, 2010 at 10:58 PM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com">viridia@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5">On Sat, Aug 28, 2010 at 4:05 PM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com" target="_blank">viridia@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_quote">

<div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div>On Mon, Aug 23, 2010 at 5:58 PM, Devang Patel <span dir="ltr"><<a href="mailto:devang.patel@gmail.com" target="_blank">devang.patel@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_quote">


<div><div></div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div><br><div class="gmail_quote">On Sun, Aug 22, 2010 at 12:50 PM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com" target="_blank">viridia@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>I recently started getting this error when I try to debug my LLVM-compiled program in GDB:</div><div><br></div><div>    Dwarf Error: Cannot find DIE at 0x16769 referenced from DIE at 0x1713c [in module /home/talin/Projects/tart/build-eclipse/test/stdlib/ReflectionTest]</div>






<div><br></div><div>I'm not sure if it's something I did or not. Is there any way to track down the cause of this error? The hex addresses in the error message are meaningless to me.</div></blockquote></div><div>




<br></div></div></div><div>There is not much info here. The error says one debug info entry (DIE) is referring to another debug info entry that does not exist. This usually indicates that dwarf generator in llvm codegen knew about the other DIE but some how gdb does not find the DIE. May be the code generator did not emit the DIE ? If yes then why ?  Otherwise, the DIE was dropped somewhere after  compiler generated code. </div>




<div><br></div></blockquote></div></div><div>I've discovered a little bit more, but not enough to solve the problem.</div><div><br></div><div>Here's what my code looks like for setting the debug location (some details removed for clarity):</div>



<div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><div><font face="'courier new', monospace"><div>
void CodeGenerator::setDebugLocation(const SourceLocation & loc) {</div><div>  if (loc != dbgLocation_ && dbgContext_.isScope()) {</div><div>    dbgLocation_ = loc;</div><div>    if (loc.file == NULL) {</div>


<div>
      builder_.SetCurrentDebugLocation(llvm::DebugLoc());</div><div>    } else if (loc.file == module_->moduleSource()) {</div><div>      TokenPosition pos = tokenPosition(loc);</div><div>      // ** Comment out this line and the DIE errors disappear **</div>



<div><font color="#FF0000">      builder_.SetCurrentDebugLocation(</font></div><div><font color="#FF0000">          DebugLoc::get(pos.beginLine, pos.beginCol, dbgContext_));</font></div>
<div>    }</div><div>  }</div><div>}</div><div><br></div></font></div></div></div></blockquote><div class="gmail_quote"><div><div>As noted in the comment above, if I comment out the line that calls builder_.SetCurrentDebugLocation(), then gdb no longer reports not being able to find the DIE. Of course, I don't get any source-line debugging information either.</div>



</div><div><br></div><div>Note that even in this case, I'm still generating tons of DWARF info for data types, files, functions, and so on. This all apparently works (or at least, it doesn't seem to generate this particular problem). It's only the generating of source line information that causes the error. This is fortunate, since as you can see the code is quite trivial, whereas I was afraid that if the problem was in the data type code, it would take forever to locate the problem as that code is pretty complicated.</div>



<div><br></div><div>As far as why this code is causing the error, I can only guess that I am calling it wrong somehow. But I can't think what I could do differently from what I am doing already.</div></div></blockquote>


<div><br></div></div></div><div>OK some progress on this: Changing the 'scope' argument passed to DebugLoc::get() - from a DICompileUnit to a DIFile (I'm not sure which is right, the docs and comments aren't real clear on this) - gets rid of the "Can't find DIE" error. Instead I get:</div>


<div><br></div><div>    "Line number -1 out of range;"</div><div><br></div><div>...when I try to examine a stack frame. Which is strange, because  *know* my line numbers are not -1. There's even an assert for that. And the comments in my generated assembly language look perfectly valid to me:</div>


<div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><div><font face="'courier new', monospace">Ltmp26:</font></div>
</div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace">        subl    $8, %esp                ## Array.tart:103:11[ Array.tart:103:11 ]</font></div></div></div>
<div class="gmail_quote"><div><div><font face="'courier new', monospace">Ltmp27:                                 ## Array.tart:103:11[ Array.tart:103:11 ]</font></div></div></div><div class="gmail_quote">
<div><div><font face="'courier new', monospace">        movl    $0, 4(%esp)             ## Array.tart:103:11[ Array.tart:103:11 ]</font></div></div></div><div class="gmail_quote"><div><div>
<font face="'courier new', monospace">        movl    $16, (%esp)             ## Array.tart:103:11[ Array.tart:103:11 ]</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace">        call    _malloc                 ## Array.tart:103:11[ Array.tart:103:11 ]</font></div>


</div></div></blockquote><div><br></div>-- <br><font color="#888888">-- Talin<br>
</font></blockquote></div><br>Well, I figured out why the line numbers were getting set to -1: My "add_custom_command" directive in my CMake file which was supposed to run dsymutil was silently failing:<div><br>

</div><div><div><font class="Apple-style-span" face="'courier new', monospace">    add_custom_command(</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    </font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">        </font></span><font class="Apple-style-span" face="'courier new', monospace">OUTPUT "${EXE_FILE}.dSYM/Contents/Resources/DWARF/${EXE_FILE}"</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">        COMMAND ${DSYMUTIL} "${EXE_FILE}"</font></div><div><font class="Apple-style-span" face="'courier new', monospace">        MAIN_DEPENDENCY "${EXE_FILE}"</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">        COMMENT "Generating debug symbols for ${EXE_FILE}")</font></div></div><div><br></div><div>I don't know why, but this directive does nothing and prints nothing. In any case, that's not an LLVM problem so I'll stop talking about it.</div>

<div><br></div><div>However, this leads to a new problem: Now when I manually run dsymutil and attempt to debug my executable, I get this:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div><div><font class="Apple-style-span" face="'courier new', monospace">DW_FORM_strp pointing outside of .debug_str section [in module /Users/talin/Projects/tart/build-eclipse/test/stdlib/ArrayListTest.dSYM/Contents/Resources/DWARF/ArrayListTest]</font></div>

</div></blockquote><div><div><br></div><div>Once again, I have no idea what this means or how to go about debugging it. This is my biggest frustration with DIFactory - there's absolutely no way to verify that the DWARF debugging information that I've emitted into my module is correct or even sensible. The only way to test it is to try and debug it with gdb, but all that will tell you is that *something* failed - it won't tell you where or what. It's not so much like looking for a needle in a haystack - more like looking for a particular needle in a needlestack.</div>

<div><br>-- <br>-- Talin<br>
</div></div>