<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 7, 2018, at 2:04 AM, Jan Kratochvil <<a href="mailto:jan.kratochvil@redhat.com" class="">jan.kratochvil@redhat.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Sat, 07 Apr 2018 00:52:26 +0200, Greg Clayton wrote:<br class=""><blockquote type="cite" class="">Take look at how LLVM does it. I believe my changes mirror that approach.<br class=""></blockquote><br class="">LLVM does not support partial units so there is nothing to look at there.<br class=""><br class=""><br class=""><blockquote type="cite" class="">DWARFUnit should be the base class for anything that needs to hand out DIEs.<br class=""></blockquote><br class="">That's OK for partial units.<br class=""><br class=""><br class=""><blockquote type="cite" class="">Any specializations should be inheriting from DWARFUnit, like both<br class="">DWARFCompileUnit and DWARFTypeUnit.<br class=""></blockquote><br class="">I see now the source of misunderstanding:<br class=""><br class="">DWARFCompileUnit = DW_TAG_compile_unit<br class="">DWARFTypeUnit = DW_TAG_type_unit<br class="">DWARFPartialUnit != DW_TAG_partial_unit<br class="">                ^^^^<br class="">BTW DW_TAG_imported_unit is importing (="caller") tag, not a unit (="callee").<br class=""><br class="">DW_TAG_partial_unit gets read in (by<br class="">DWARFDebugInfo::ParseCompileUnitHeadersIfNeeded) as DWARFCompileUnit because<br class="">there is no quick enough way to find the difference.  It would require reading<br class="">the first DIE tag which means to read and decode .debug_abbrev for each unit<br class="">being scanned.<br class=""></div></div></blockquote><div><br class=""></div>If there is no structural difference other than the first DW_TAG, is there a reason you would need to know the difference? It would be fine to just add extra methods on DWARFCompileUnit that do partial unit kind of things if it is a partial unit? Let me know if I am missing something?</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div class=""><br class="">DWARFPartialUnit is used only as a remapping of DWARFCompileUnit to a new<br class="">offset without any new data (there is stored only a new remapped offset whose<br class="">value is only made up internally in LLDB) at the moment someone uses<br class="">DW_TAG_imported_unit for it - at that moment we easily know that unit has to<br class="">be DW_TAG_partial_unit.<br class=""></div></div></blockquote><div><br class=""></div>It is remapped to a new offset just to keep LLDB's lldb::user_id_t stuff happy? A partial unit can refer to an external file on disk. The remapping is solely making a unique offset by adding an offset to the offset of the external file?</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div class=""><br class="">Therefore DWARFCompileUnit and DWARFTypeUnit both contain some their own data.<br class="">But DWARFPartialUnit is just a remapping of DWARFCompileUnit (containing<br class="">DW_TAG_partial_unit) to a new offset without any new data. Particularly<br class="">m_die_array is not in DWARFPartialUnit.</div></div></blockquote><div><br class=""></div>In reading the DWZ it sounded like you can only have 1 external debug info file and that external debug info file can't itself refer to another? Is this what the DWARFPartialUnit would be for and this is the only remapping that needs to happen?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">DWARFTypeUnit can be recognized easily as it is either in .debug_types<br class="">(<=DWARF-4) or the unit header contains DW_UT_type (>=DWARF-5).<br class="">DWARFPartialUnit (for DW_TAG_partial_unit) cannot be recognized easily first.</div></div></blockquote><blockquote type="cite" class=""><div class=""><div class="">Besides that one would need then some DWARFRemappedPartialUnit for what I use<br class="">DWARFPartialUnit now.<br class=""><br class="">I have implemented it according to your advice from this mail - at least<br class="">according to how I understood it:<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>[lldb-dev] RFC for DWZ = DW_TAG_imported_unit + DWARF-5 supplementary files<br class=""><span class="Apple-tab-span" style="white-space:pre">    </span><a href="https://lists.llvm.org/pipermail/lldb-dev/2017-August/012664.html" class="">https://lists.llvm.org/pipermail/lldb-dev/2017-August/012664.html</a><br class=""><br class="">It does not try to share anything at AST level, it only shares DWARF data (and<br class="">thus DWARFCompileUnit). Given that DWZ finds arbitrary unique DWARF subtrees<br class="">I find more logical to decode it at DWARF (and not at AST) level.<br class=""><br class="">You wrote:<br class=""># The drawback is this won't allow sharing /tmp/shared1 or /tmp/shared2<br class=""># between two different top level DWARF files, but it does allow one<br class=""># clang::ASTContext to be used between all of them.<br class=""><br class="">In my implementation /tmp/shared1<br class="">(/usr/lib/debug/.dwz/coreutils-8.27-20.fc27.x86_64) is shared between multiple<br class="">*.so files (which use DW_TAG_imported_unit) at DWARF level, also<br class="">clang::ASTContext is shared.<br class=""><br class=""><br class=""># SymbolFileDWARFDebugMap makes it lldb::user_id_t contain the CU index in the<br class=""># top 32 bits, and the DIE offset within that .o file's DWARF in the bottom 32<br class=""># bits. You could do something similar in your case where the top 32 bits is<br class=""># the index of the DWARF file in the "dwarf[]" array that would be maintained<br class=""># in a new SymbolFileDWARFDWZ subclass.<br class=""><br class="">DW_TAG_imported_unit+DW_TAG_partial_unit can be also used for optimization of<br class="">a single file (without /usr/lib/debug/.dwz/* file which is used exclusively<br class="">for DW_TAG_partial_unit entries). Additionally the tags can be also used for<br class="">recursive inclusion. I haven't found how to use the top 32 bits for that.<br class="">I just reserve new remapped offset space for each DW_TAG_imported_unit (in the<br class="">bottom 32 bits).<br class=""><br class="">I tried first to implement dw_offset_t caller (=unit with<br class="">DW_TAG_imported_unit) to be tracked along any dw_offset_t DIE offset but that<br class="">would require huge changes of the DWARF parsing code everywhere.  Also it<br class="">cannot work well given the inclusion is recursive (so we would need<br class="">std::vector<dw_offset_t> of the callers stack).<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">I have no idea what are in your other patches<br class=""></blockquote><br class="">OK, so there was a gross misunderstanding and my DWARFUnit implemented<br class="">something very different from what you expected+approved. I am sure fine with<br class="">that but I needed to understand first why you did that big screw up of my<br class="">carefully coded patch.<br class=""><br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">This is how DWARFPartialUnit works, it is only a DWARFCompileUnit remapped to<br class="">new offset.  I do not see how to implement it transparently without the<br class="">accessor (and without needlessly copying all the data fields many times into<br class="">each DWARFPartialUnit instance).<br class=""></blockquote><br class="">What extra functions are needed for a partial unit that can't be done in<br class="">a DWARFCompileUnit? Seems like they both contain things, but the partial<br class="">unit can be referenced from compile units. <br class=""></blockquote><br class="">DWARFPartialUnit is only a remapping, not really a representation of DWARF<br class="">file data.  So DWARFPartialUnit cannot contain its own m_die_array, m_version<br class="">and other data members you have moved back to DWARFUnit.<br class=""><br class=""><br class=""><blockquote type="cite" class="">As we are saying, we are trying to make the layering more like LLVM's<br class="">layering, so that is what I meant by "fix the layering". I believe we should<br class="">strive for being more like LLVM so that any transition can happen without<br class="">major re-organization of the DWARF code later. So I would like the get the<br class="">ok the revert the revert if you on board with what my suggestions are in the<br class="">paragraph. I know this will require modifications to your patches and<br class="">apologize for that.<br class=""><br class="">Let me know what you think,<br class=""></blockquote><br class="">I would like to know what is the approved plan / upstreaming order regarding<br class="">all the planned changes:<br class=""><br class="">(1) Your DWARFTypeUnit patch - it makes it more aligned to LLVM DWARFUnits.<br class="">(2) My DWZ patch - it is a new feature with no counterpart in LLVM DWARFUnits.<br class="">(3) Replacement of LLDB DWARFUnits with LLVM DWARFUnits.<br class=""><br class="">I can sure work even on (3) but after half a year of work on DWZ support which<br class="">completely blocks LLDB for Red Hat usage (as Red Hat requires "upstream first"<br class="">to prevent heavy forks like what happened for Red Hat GDB) it makes the DWZ<br class="">upstreaming possibility too far for me to start refactoring LLDB for (3) first<br class="">- before upstreaming (2).<br class=""><br class=""><br class="">Thanks,<br class="">Jan<br class=""></div></div></blockquote><br class=""></div><div>We need to solve (1) first so we can move onto (2). (3) can wait IMHO, but if someone really wants to tackle that it is fine.</div><div><br class=""></div><div>I think I need to see any example of this DWZ so I can intelligently comment on thing. The brief description of DWZ at <a href="http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open" class="">http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open</a> doesn't help me see how this is actually laid out on disk and who refers to who and how things are laid out in the DWARF itself. Can you somehow make some simple executables available to me so I can see the DWARF in the main compile unit, the partial unit and the info in the external DWZ file? I know you know what you have done and fully understand this feature, but I would like to take a look at an example so I can see how we can make both the .debug_types and your feature work using similar work arounds.</div><div><br class=""></div><div>One idea that might work is to expand the DWARFDataExtractor so it can contain enough information to create a lldb::user_id_t that would work for .debug_info, .debug_types and for the alternate debug file. It would also need to be able to get us to the right debug info when a SymbolFileDWARF API was handed a lldb::user_id_t and be able to turn that back into something. The current offset hack that was used for .debug_types could be used for this purpose as well. But I really would like to see an example program that refers to an external DWZ file so I can make sure what I recommend is viable.</div><div><br class=""></div><div>Greg Clayton</div><div><br class=""></div></body></html>