labath created this revision. labath added reviewers: JDevlieghere, aprantl, clayborg. Herald added a subscriber: arphaman. Herald added a project: LLDB. labath added a child revision: D73782: [lldb/DWARF] Don't hold a unique SymbolFileDWARFDwo in a DWARFUnit.
This is a preparatory patch to re-enable DWP support in lldb (we already have code claiming to do that, but it has been completely broken for a while now). The idea of the new approach is to make the SymbolFileDWARFDwo class handle both dwo and dwo files, similar to how llvm uses one DWARFContext to handle the two. The first step is to remove the assumption that a SymbolFileDWARFDwo holds just a single compile unit, i.e. the GetBaseCompileUnit method. This requires changing the way how we reach the skeleton compile unit (and the lldb_private::CompileUnit) from a dwo unit, which was previously done via GetSymbolFile()->GetBaseCompileUnit() (and some virtual dispatch). The new approach reuses the "user data" mechanism of DWARFUnits, which was used to link dwarf units (both skeleton and split) to their lldb_private counterparts. Now, this is done only for non-dwo units, and instead of that, the dwo units holds a pointer to the relevant skeleton unit. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D73781 Files: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp @@ -13,7 +13,7 @@ #include "lldb/Symbol/ObjectFile.h" #include "lldb/Utility/LLDBAssert.h" -#include "DWARFUnit.h" +#include "DWARFCompileUnit.h" #include "DWARFDebugInfo.h" using namespace lldb; @@ -25,8 +25,9 @@ ObjectFileSP objfile, DWARFCompileUnit &dwarf_cu, uint64_t dwo_id) - : SymbolFileDWARFDwo(objfile, dwarf_cu), m_dwp_symfile(dwp_symfile), - m_dwo_id(dwo_id) {} + : SymbolFileDWARFDwo(dwarf_cu.GetSymbolFileDWARF(), objfile, + dwarf_cu.GetID()), + m_dwp_symfile(dwp_symfile), m_dwo_id(dwo_id) {} void SymbolFileDWARFDwoDwp::LoadSectionData(lldb::SectionType sect_type, DWARFDataExtractor &data) { Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -24,12 +24,11 @@ static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} - SymbolFileDWARFDwo(lldb::ObjectFileSP objfile, DWARFCompileUnit &dwarf_cu); + SymbolFileDWARFDwo(SymbolFileDWARF &m_base_symbol_file, + lldb::ObjectFileSP objfile, uint32_t id); ~SymbolFileDWARFDwo() override = default; - lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu) override; - DWARFCompileUnit *GetCompileUnit(); DWARFUnit * @@ -44,8 +43,6 @@ DWARFDIE GetDIE(const DIERef &die_ref) override; - DWARFCompileUnit *GetBaseCompileUnit() override { return &m_base_dwarf_cu; } - llvm::Optional<uint32_t> GetDwoNum() override { return GetID() >> 32; } protected: @@ -69,11 +66,11 @@ const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override; - SymbolFileDWARF &GetBaseSymbolFile(); + SymbolFileDWARF &GetBaseSymbolFile() { return m_base_symbol_file; } DWARFCompileUnit *ComputeCompileUnit(); - DWARFCompileUnit &m_base_dwarf_cu; + SymbolFileDWARF &m_base_symbol_file; DWARFCompileUnit *m_cu = nullptr; }; Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -23,12 +23,12 @@ char SymbolFileDWARFDwo::ID; -SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile, - DWARFCompileUnit &dwarf_cu) +SymbolFileDWARFDwo::SymbolFileDWARFDwo(SymbolFileDWARF &base_symbol_file, + ObjectFileSP objfile, uint32_t id) : SymbolFileDWARF(objfile, objfile->GetSectionList( /*update_module_section_list*/ false)), - m_base_dwarf_cu(dwarf_cu) { - SetID(((lldb::user_id_t)dwarf_cu.GetID()) << 32); + m_base_symbol_file(base_symbol_file) { + SetID(user_id_t(id) << 32); } void SymbolFileDWARFDwo::LoadSectionData(lldb::SectionType sect_type, @@ -49,14 +49,6 @@ SymbolFileDWARF::LoadSectionData(sect_type, data); } -lldb::CompUnitSP -SymbolFileDWARFDwo::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) { - assert(GetCompileUnit() == &dwarf_cu && - "SymbolFileDWARFDwo::ParseCompileUnit called with incompatible " - "compile unit"); - return GetBaseSymbolFile().ParseCompileUnit(m_base_dwarf_cu); -} - DWARFCompileUnit *SymbolFileDWARFDwo::GetCompileUnit() { if (!m_cu) m_cu = ComputeCompileUnit(); @@ -133,10 +125,6 @@ die, type_name, must_be_implementation); } -SymbolFileDWARF &SymbolFileDWARFDwo::GetBaseSymbolFile() { - return m_base_dwarf_cu.GetSymbolFileDWARF(); -} - llvm::Expected<TypeSystem &> SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) { return GetBaseSymbolFile().GetTypeSystemForLanguage(language); Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -246,8 +246,6 @@ static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die); - virtual lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu); - lldb::ModuleSP GetExternalModule(lldb_private::ConstString name); typedef std::map<lldb_private::ConstString, lldb::ModuleSP> @@ -276,11 +274,6 @@ GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die); - // For regular SymbolFileDWARF instances the method returns nullptr, - // for the instances of the subclass SymbolFileDWARFDwo - // the method returns a pointer to the base compile unit. - virtual DWARFCompileUnit *GetBaseCompileUnit() { return nullptr; } - virtual llvm::Optional<uint32_t> GetDwoNum() { return llvm::None; } /// If this is a DWARF object with a single CU, return its DW_AT_dwo_id. @@ -326,6 +319,8 @@ lldb_private::TypeList &GetTypeList() override; + lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu); + virtual DWARFUnit * GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -645,9 +645,7 @@ // We already parsed this compile unit, had out a shared pointer to it cu_sp = comp_unit->shared_from_this(); } else { - if (&dwarf_cu.GetSymbolFileDWARF() != this) { - return dwarf_cu.GetSymbolFileDWARF().ParseCompileUnit(dwarf_cu); - } else if (dwarf_cu.GetOffset() == 0 && GetDebugMapSymfile()) { + if (dwarf_cu.GetOffset() == 0 && GetDebugMapSymfile()) { // Let the debug map create the compile unit cu_sp = m_debug_map_symfile->GetCompileUnit(this); dwarf_cu.SetUserData(cu_sp.get()); @@ -1456,13 +1454,17 @@ CompileUnit * SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) { + DWARFCompileUnit *non_dwo_cu = + dwarf_cu.IsDWOUnit() + ? static_cast<DWARFCompileUnit *>(dwarf_cu.GetUserData()) + : &dwarf_cu; // Check if the symbol vendor already knows about this compile unit? - if (dwarf_cu.GetUserData() == nullptr) { + if (non_dwo_cu->GetUserData() == nullptr) { // The symbol vendor doesn't know about this compile unit, we need to parse // and add it to the symbol vendor object. - return ParseCompileUnit(dwarf_cu).get(); + return ParseCompileUnit(*non_dwo_cu).get(); } - return (CompileUnit *)dwarf_cu.GetUserData(); + return static_cast<CompileUnit *>(non_dwo_cu->GetUserData()); } size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name, @@ -1607,7 +1609,8 @@ if (dwo_obj_file == nullptr) return nullptr; - return std::make_unique<SymbolFileDWARFDwo>(dwo_obj_file, *dwarf_cu); + return std::make_unique<SymbolFileDWARFDwo>(*this, dwo_obj_file, + dwarf_cu->GetID()); } void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() { Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -89,7 +89,7 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, IndexSet &set) { assert( - !unit.GetSymbolFileDWARF().GetBaseCompileUnit() && + !unit.IsDWOUnit() && "DWARFUnit associated with .dwo or .dwp should not be indexed directly"); Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -79,6 +79,8 @@ DIERef::Section section, lldb::offset_t *offset_ptr); virtual ~DWARFUnit(); + bool IsDWOUnit() { return m_is_dwo; } + void ExtractUnitDIEIfNeeded(); void ExtractDIEsIfNeeded(); Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -347,6 +347,7 @@ DWARFUnit *dwo_cu = dwo_symbol_file->GetCompileUnit(); if (!dwo_cu) return; // Can't fetch the compile unit from the dwo file. + dwo_cu->SetUserData(this); DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly(); if (!dwo_cu_die.IsValid()) @@ -567,11 +568,7 @@ void *DWARFUnit::GetUserData() const { return m_user_data; } -void DWARFUnit::SetUserData(void *d) { - m_user_data = d; - if (m_dwo_symbol_file) - m_dwo_symbol_file->GetCompileUnit()->SetUserData(d); -} +void DWARFUnit::SetUserData(void *d) { m_user_data = d; } bool DWARFUnit::Supports_DW_AT_APPLE_objc_complete_type() { return GetProducer() != eProducerLLVMGCC;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits