<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">FTR, the size of the compile-unit header also changed in DWARF version 5, independent of the 32/64 format.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">On a different topic, I had thought there was a goal of nuking lldb's copy of the DWARFxxx headers and converting to use LLVM's?  Did I imagine this?  If I
 do remember that correctly, fiddling with lldb's copy doesn't make much sense.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> lldb-commits [mailto:lldb-commits-bounces@lists.llvm.org]
<b>On Behalf Of </b>Zachary Turner via lldb-commits<br>
<b>Sent:</b> Monday, November 20, 2017 8:17 AM<br>
<b>To:</b> Greg Clayton<br>
<b>Cc:</b> Jan Kratochvil via Phabricator; lldb-commits@lists.llvm.org; reviews+D40211+public+c1500ec8aeff1f84@reviews.llvm.org; jdevlieghere@apple.com; jan.kratochvil@redhat.com<br>
<b>Subject:</b> Re: [Lldb-commits] [PATCH] D40211: Add comments to DWARFCompileUnit length fields/methods<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">You can make structs that are host and byte-order independent, LLVM is filled with stuff like this.  And while you might end up processing the information off in a way that it can be stored in a single compile unit without such a struct,
 it still can be useful when you're actually *doing* the parsing.  <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">For one, it serves as documentation of the format.  It sounds like in order to know what a DWARF64 header looks like currently, I have to go read the code that actually parses one, which might require me to understand several functions
 and follow some pointer arithmetic and various other stuff.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Second, it can converts code like this:<o:p></o:p></p>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">if (m_dwarf64) {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // read the first field<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // read the second field<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // read the third field<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  ...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">  // store the fields in the CompileUnit<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">} else {<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">  // read the first field<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // read the second field<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // read the third field<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">  // adjust a pointer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  ...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // store the fields in the CompileUnit<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">into this:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">if (m_dwarf64) {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  DWARF64_HEADER h;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  readStructure(h);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // store the fields in the CompileUnit<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">} else {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  DWARF32_HEADER h;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  readStructure(h);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  // store the fields in the CompileUnit<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Anyway, you answered my question, which is that we don't have one  <o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Nov 20, 2017 at 8:07 AM Greg Clayton <<a href="mailto:clayborg@gmail.com">clayborg@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">sizeof(struct) tends to include system level padding for the current host. But to answer your question, no there isn't a structure defined like this and we wouldn't use them anyway as we want to fill out one compile unit struct that works
 for both. <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Nov 20, 2017, at 8:01 AM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Right but isn’t there a DWARF64_HEADER and DEARF32_HEADER struct somewhere? This way you could just say
<br>
<br>
return m_isdwarf64 ? sizeof(DWARF64_HEADER) : sizeof(DWARF32_HEADER);<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Nov 20, 2017 at 7:50 AM Greg Clayton <<a href="mailto:clayborg@gmail.com" target="_blank">clayborg@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Nov 19, 2017, at 4:56 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Sun, Nov 19, 2017 at 6:35 AM Jan Kratochvil via Phabricator via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">This revision was automatically updated to reflect the committed changes.<br>
Closed by commit rL318626: Add comments to DWARFCompileUnit length fields/methods (authored by jankratochvil).<br>
<br>
Changed prior to commit:<br>
  <a href="https://reviews.llvm.org/D40211?vs=123472&id=123498#toc" target="_blank">
https://reviews.llvm.org/D40211?vs=123472&id=123498#toc</a><br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D40211" target="_blank">https://reviews.llvm.org/D40211</a><br>
<br>
Files:<br>
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h<br>
<br>
<br>
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h<br>
===================================================================<br>
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h<br>
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h<br>
@@ -41,26 +41,24 @@<br>
   void Clear();<br>
   bool Verify(lldb_private::Stream *s) const;<br>
   void Dump(lldb_private::Stream *s) const;<br>
+  // Offset of the initial length field.<br>
   dw_offset_t GetOffset() const { return m_offset; }<br>
   lldb::user_id_t GetID() const;<br>
-  uint32_t Size() const {<br>
-    return m_is_dwarf64 ? 23<br>
-                        : 11; /* Size in bytes of the compile unit header */<br>
-  }<br>
+  // Size in bytes of the initial length + compile unit header.<br>
+  uint32_t Size() const { return m_is_dwarf64 ? 23 : 11; }<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This is pretty gross.  Don't we have a structure somewhere that represents a compile unit header?  That we can just call sizeof on?  Same goes for the rest of the patch<o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">It varies depending on data on how the length unit is represented in the data stream. If the length starts with UINT32_MAX, it is followed by a 64 bit length. If the length isn't UINT32_MAX it is just a 32 bit length. <o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>