<div dir="ltr"><div dir="ltr"><div>Thanks again for your help, Zachary.</div><div><br></div><div>Here's a screenshot of stack traces working on Windows!</div><div><a href="https://i.imgur.com/eOQO0GT.png">https://i.imgur.com/eOQO0GT.png</a></div><div><br></div><div>I owe you some PDB documentation patches.<br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 31, 2018 at 12:52 PM Andrew Kelley <<a href="mailto:superjoe30@gmail.com">superjoe30@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div>Thanks for the advice. I'll examine llvm-pdbutil's behavior with a debugger.</div><div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 31, 2018 at 10:06 AM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For the first and third questions, the easiest thing to do would be run llvm-pdbutil under a debugger and step through the code.  Code that looks simple and innocuous can often have a lot of stuff hidden behind it.  For example you could step through that loop that iterates the debug subsections and look at the value of Reader.getOffset() every time, and see if it matches with your own code (probably it doesn’t).  Or you could dump the entire contents of the C13Substrem and see if the bytes match up between your own implementation.  It looks like you’re reading all 0s, so maybe you’re just not even reading the right data.<br><br>For the second question, unfortunately I don’t know of a better way.  If the/names stream starts with a magic header, maybe you could walk each stream looking for that.  But it maybe possible to have a rare false positive that way.<br><br>BTW, have you considered just using llvm’s library rather than porting it?  It certainly seems like less work <br></blockquote><div><br></div><div>The point of these stack traces is that they go into the userland runtime code. So if I did this, it would cause my users' programs to depend on LLVM. I don't think that's right. I already have working stack traces for linux and macos that don't depend on any libraries and don't add more than ~20KB to the runtime size.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div dir="ltr">On Thu, Aug 30, 2018 at 11:49 PM Andrew Kelley <<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>One more:</div><div><br></div><div>3. In the purpose of mapping source file index to string, I found this code: <br></div><div><br></div><div>Expected<codeview::DebugChecksumsSubsectionRef><br>ModuleDebugStreamRef::findChecksumsSubsection() const {<br>  codeview::DebugChecksumsSubsectionRef Result;<br>  for (const auto &SS : subsections()) {<br>    if (SS.kind() != DebugSubsectionKind::FileChecksums)<br>      continue;<br><br>    if (auto EC = Result.initialize(SS.getRecordData()))<br>      return std::move(EC);<br>    return Result;<br>  }<br>  return Result;<br>}<br></div><div><br></div><div>Subsections() is populated here:</div><div><br></div><div>  if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))<br>    return EC;<br><br>  BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);<br>  if (auto EC =<br>          SymbolReader.readArray(SymbolArray, SymbolReader.bytesRemaining()))<br>    return EC;<br><br>  BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);<br>  if (auto EC = SubsectionsReader.readArray(Subsections,<br>                                            SubsectionsReader.bytesRemaining()))<br>    return EC;<br><br></div><div>So it looks like there should be one of these just after the C13Lines substream:</div><div><br></div><div>struct DebugSubsectionHeader {<br>  support::ulittle32_t Kind;   // codeview::DebugSubsectionKind enum<br>  support::ulittle32_t Length; // number of bytes occupied by this record.<br>};</div><div><br></div><div>But when I look there with my own code I only see zeroes:</div><div><br></div><div>read C13 line info 142964 bytes<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }<br>DebugSubsectionHeader{ .Kind = DebugSubsectionKind.None, .Length = 0 }</div><div><repeats until end of stream></div><div><br></div><div>Any clues?<br></div><div><br></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 31, 2018 at 2:17 AM Andrew Kelley <<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Zachary,</div><div><br></div><div>Thanks for the help on IRC earlier. I've got code that can capture a stack trace and then discover for each address, its module, function, source index, line, and column.</div><div><br></div><div>I still have a couple of loose ends though. Do you know what's going on here?</div><div><br></div><div>1. There appears to be 8 bytes before every LineFragmentHeader. Here's some of my own debug output, which matches llvm-pdbutil's output. You can see it says "unknown bytes: ...".<br></div><div dir="ltr"><br></div><div dir="ltr">read C13 line info 136720 bytes<br>unknown bytes: f2 00 00 00  60 00 00 00<br>LineFragmentHeader{ .RelocOffset = 0, .RelocSegment = 5, .Flags = LineFlags{ .LF_HaveColumns = true, .unused = 0 }, .CodeSize = 52 }<br>has column: true<br>LineBlockFragmentHeader{ .NameIndex = 0, .NumLines = 6, .BlockSize = 84 }<br>LineNumberEntry{ .Offset = 0, .Flags = 101 } Flags{ .Start = 101, .End = 17, .IsStatement = false }<br></div><div><snip some LineNumberEntry's></div><div>ColumnNumberEntry{ .StartColumn = 5, .EndColumn = 0 }<br>ColumnNumberEntry{ .StartColumn = 30, .EndColumn = 0 }<br>unknown bytes: f2 00 00 00  f0 00 00 00<br>LineFragmentHeader{ .RelocOffset = 64, .RelocSegment = 5, .Flags = LineFlags{ .LF_HaveColumns = true, .unused = 0 }, .CodeSize = 366 }<br>has column: true<br>LineBlockFragmentHeader{ .NameIndex = 8, .NumLines = 18, .BlockSize = 228 }<br>LineNumberEntry{ .Offset = 0, .Flags = 53 } Flags{ .Start = 53, .End = 20, .IsStatement = false }<br>LineNumberEntry{ .Offset = 20, .Flags = 54 } Flags{ .Start = 54, .End = 24, .IsStatement = false }</div><div><etc></div><div><br></div><div>Do you know what's going on with these 8 bytes? I have scoured llvm-pdbutil's source but I cannot find where these bytes are coming from.</div><div><br></div><div>2. Is there a simpler way to find out which is the /names (string table) stream index without porting the entire hash table implementation?<br></div><div><br></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div></div></div>
</blockquote></div>