Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -215,7 +215,7 @@ AccessType accessibility = eAccessNone; if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); if (log) { DWARFDIE context_die; clang::DeclContext *context = @@ -3679,7 +3679,7 @@ Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); DWARFAttributes attributes; const size_t num_attributes = die.GetAttributes(attributes); if (num_attributes > 0) { @@ -3737,7 +3737,7 @@ case DW_TAG_variable: case DW_TAG_constant: case DW_TAG_formal_parameter: { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); Type *type = GetTypeForDIE(die); if (dwarf && type) { const char *name = die.GetName(); @@ -3751,7 +3751,7 @@ break; } case DW_TAG_imported_declaration: { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { CompilerDecl imported_decl = imported_uid.GetDecl(); @@ -3769,7 +3769,7 @@ break; } case DW_TAG_imported_module: { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { @@ -3826,7 +3826,7 @@ } if (decl_ctx == nullptr && try_parsing_type) { - Type *type = die.GetDWARF()->ResolveType(die); + Type *type = die.GetMainDWARF()->ResolveType(die); if (type) decl_ctx = GetCachedClangDeclContextForDIE(die); } Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -613,6 +613,7 @@ } LanguageType DWARFCompileUnit::GetLanguageType() { + lldbassert(GetMainCU() == this); if (m_language_type != eLanguageTypeUnknown) return m_language_type; @@ -646,6 +647,7 @@ } TypeSystem *DWARFCompileUnit::GetTypeSystem() { + lldbassert(GetMainCU() == this); if (m_dwarf2Data) return m_dwarf2Data->GetTypeSystemForLanguage(GetLanguageType()); else Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDIE.h +++ source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -57,6 +57,9 @@ //---------------------------------------------------------------------- SymbolFileDWARF *GetDWARF() const; + // File which referenced DWZCommonFile (where this DIE may be located). + SymbolFileDWARF *GetMainDWARF() const; + DWARFUnit *GetCU() const { return m_cu; } DWARFDebugInfoEntry *GetDIE() const { return m_die; } Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -128,7 +128,8 @@ DWARFFormValue form_value; if (m_die->GetAttributeValue(dwarf, cu, attr, form_value, nullptr, check_specification_or_abstract_origin)) - return dwarf->GetDIE(DIERef(form_value)); + return cu->GetMainCU()->GetSymbolFileDWARF() + ->GetDIE(DIERef(form_value)); } return DWARFDIE(); } @@ -239,7 +240,7 @@ } lldb_private::Type *DWARFDIE::ResolveTypeUID(const DIERef &die_ref) const { - SymbolFileDWARF *dwarf = GetDWARF(); + SymbolFileDWARF *dwarf = GetMainDWARF(); if (dwarf) return dwarf->ResolveTypeUID(dwarf->GetDIE(die_ref), true); else @@ -345,6 +346,13 @@ return nullptr; } +SymbolFileDWARF *DWARFDIE::GetMainDWARF() const { + if (m_cu) + return m_cu->GetMainCU()->GetSymbolFileDWARF(); + else + return nullptr; +} + lldb_private::TypeSystem *DWARFDIE::GetTypeSystem() const { if (m_cu) return m_cu->GetTypeSystem(); Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -78,6 +78,8 @@ for (size_t idx = 0; idx < num_compile_units; ++idx) { DWARFUnit *cu = GetCompileUnitAtIndex(idx); + if (cu->GetMainCU() != cu) + continue; dw_offset_t offset = cu->GetOffset(); if (cus_with_data.find(offset) == cus_with_data.end()) { if (log) { Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -570,7 +570,8 @@ if (ranges.IsEmpty() || name == NULL || mangled == NULL) { for (const DIERef &die_ref : die_refs) { if (die_ref.die_offset != DW_INVALID_OFFSET) { - DWARFDIE die = dwarf2Data->GetDIE(die_ref); + DWARFDIE die = cu->GetMainCU()->GetSymbolFileDWARF() + ->GetDIE(die_ref); if (die) die.GetDIE()->GetDIENamesAndRanges( die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -151,6 +151,11 @@ } dw_offset_t GetNextCompileUnitFileOffset() const; + // DW_TAG_compile_unit with DW_TAG_imported_unit for this DW_TAG_partial_unit. + DWARFUnit *GetMainCU() const { + return const_cast(this); + } + protected: virtual DWARFCompileUnit &Data() = 0; virtual const DWARFCompileUnit &Data() const = 0; Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -162,7 +162,8 @@ // Don't specify the compile unit offset as we don't know it because the // DIE belongs to // a different compile unit in the same symbol file. - return Data().m_dwarf2Data->DebugInfo()->GetDIEForDIEOffset(die_offset); + return GetMainCU()->Data().m_dwarf2Data->DebugInfo() + ->GetDIEForDIEOffset(die_offset); } } Data().m_dwarf2Data->GetObjectFile()->GetModule()->ReportError( Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -734,6 +734,8 @@ DWARFUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()); + if (dwarf_cu) + dwarf_cu = dwarf_cu->GetMainCU(); if (dwarf_cu && dwarf_cu->GetUserData() == NULL) dwarf_cu->SetUserData(comp_unit); return dwarf_cu; @@ -763,6 +765,7 @@ uint32_t cu_idx) { CompUnitSP cu_sp; if (dwarf_cu) { + dwarf_cu = dwarf_cu->GetMainCU(); CompileUnit *comp_unit = (CompileUnit *)dwarf_cu->GetUserData(); if (comp_unit) { // We already parsed this compile unit, had out a shared pointer to it @@ -1370,6 +1373,9 @@ Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, bool assert_not_being_parsed) { + // this can be neither die.GetDWARF() nor die.GetMainDWARF(). + if (die.GetMainDWARF() != this) + return die.GetMainDWARF()->ResolveTypeUID(die, assert_not_being_parsed); if (die) { Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log) @@ -1482,6 +1488,10 @@ Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die, bool assert_not_being_parsed, bool resolve_function_context) { + // this can be neither die.GetDWARF() nor die.GetMainDWARF(). + if (die.GetMainDWARF() != this) + return die.GetMainDWARF()->ResolveType( + die, assert_not_being_parsed, resolve_function_context); if (die) { Type *type = GetTypeForDIE(die, resolve_function_context).get(); @@ -1502,6 +1512,7 @@ CompileUnit * SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFUnit *dwarf_cu, uint32_t cu_idx) { + dwarf_cu = dwarf_cu->GetMainCU(); // Check if the symbol vendor already knows about this compile unit? if (dwarf_cu->GetUserData() == NULL) { // The symbol vendor doesn't know about this compile unit, we