diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/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(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/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()) @@ -563,11 +564,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; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/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); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/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 @@ -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 GetDwoNum() { return llvm::None; } /// If this is a DWARF object with a single CU, return its DW_AT_dwo_id. @@ -347,6 +340,8 @@ lldb_private::TypeList &GetTypeList() override; + lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu); + virtual DWARFUnit * GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/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()); @@ -1454,13 +1452,17 @@ CompileUnit * SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) { + DWARFCompileUnit *non_dwo_cu = + dwarf_cu.IsDWOUnit() + ? static_cast(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(non_dwo_cu->GetUserData()); } size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name, @@ -1605,7 +1607,8 @@ if (dwo_obj_file == nullptr) return nullptr; - return std::make_unique(dwo_obj_file, *dwarf_cu); + return std::make_unique(*this, dwo_obj_file, + dwarf_cu->GetID()); } void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/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 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; }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/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 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) { return GetBaseSymbolFile().GetTypeSystemForLanguage(language); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwoDwp.cpp +++ b/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) {