<div dir="ltr">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. <div><br></div><div>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.<div><br></div><div>Second, it can converts code like this:<div>```</div><div>if (m_dwarf64) {</div><div> // read the first field</div><div> // adjust a pointer</div><div> // read the second field<br></div><div> // adjust a pointer</div><div> // read the third field</div><div> // adjust a pointer</div><div> ...</div><div><br></div><div> // store the fields in the CompileUnit</div><div>} else {</div><div><div> // read the first field</div><div> // adjust a pointer</div><div> // read the second field</div><div> // adjust a pointer</div><div> // read the third field</div></div><div> // adjust a pointer</div><div> ...</div><div> // store the fields in the CompileUnit</div><div>}</div><div>```</div><div>into this:</div><div>```</div><div>if (m_dwarf64) {</div><div> DWARF64_HEADER h;</div><div> readStructure(h);</div><div> // store the fields in the CompileUnit</div><div>} else {</div><div> DWARF32_HEADER h;</div><div> readStructure(h);</div><div> // store the fields in the CompileUnit</div><div>}</div></div></div><div>```</div><div><br></div><div>Anyway, you answered my question, which is that we don't have one </div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 20, 2017 at 8:07 AM Greg Clayton <<a href="mailto:clayborg@gmail.com">clayborg@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 style="word-wrap:break-word">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. </div><div style="word-wrap:break-word"><div><br><div><div><blockquote type="cite"><div>On Nov 20, 2017, at 8:01 AM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div><br class="m_4642172428757422822Apple-interchange-newline"><div>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);<br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 20, 2017 at 7:50 AM Greg Clayton <<a href="mailto:clayborg@gmail.com" target="_blank">clayborg@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 style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Nov 19, 2017, at 4:56 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div><br class="m_4642172428757422822m_-6047306128612448630Apple-interchange-newline"><div><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">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:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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" rel="noreferrer" 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" rel="noreferrer" 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; }<br></blockquote><div><br></div><div>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</div></div></div>
</div></blockquote></div><br></div><div style="word-wrap:break-word"><div>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. </div></div></blockquote></div>
</div></blockquote></div><br></div></div></div></blockquote></div>