Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -186,7 +186,7 @@ AccessType accessibility = eAccessNone; if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = die.GetMainDWARF(); if (log) { DWARFDIE context_die; clang::DeclContext *context = @@ -3555,7 +3555,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) { @@ -3613,7 +3613,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(); @@ -3627,7 +3627,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(); @@ -3645,7 +3645,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) { @@ -3701,7 +3701,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.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -213,6 +213,11 @@ dw_offset_t GetBaseObjOffset() const { return m_data->m_base_obj_offset; } + // DW_TAG_compile_unit with DW_TAG_imported_unit for this DW_TAG_partial_unit. + DWARFCompileUnit *GetMainCU() const { + return const_cast(this); + } + dw_offset_t GetFileOffset() const { return m_data->m_file_offset; } dw_offset_t FileOffsetToUniqOffset(dw_offset_t file) const { return ThisCUFileOffsetToUniq(file); Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -600,7 +600,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 m_data->m_dwarf2Data->DebugInfo()->GetDIEForDIEOffset(die_offset); + return GetMainCU()->m_data->m_dwarf2Data->DebugInfo() + ->GetDIEForDIEOffset(die_offset); } } return DWARFDIE(); // Not found @@ -1103,6 +1104,8 @@ } LanguageType DWARFCompileUnit::GetLanguageType() { + if (GetMainCU() != this) + return GetMainCU()->GetLanguageType(); if (m_data->m_language_type != eLanguageTypeUnknown) return m_data->m_language_type; @@ -1140,6 +1143,8 @@ } TypeSystem *DWARFCompileUnit::GetTypeSystem() { + if (GetMainCU() != this) + return GetMainCU()->GetTypeSystem(); if (m_data->m_dwarf2Data) return m_data->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; + DWARFCompileUnit *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 @@ -135,7 +135,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(); } @@ -241,7 +242,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 @@ -347,6 +348,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 @@ -76,6 +76,8 @@ for (size_t idx = 0; idx < num_compile_units; ++idx) { DWARFCompileUnit *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) { @@ -194,7 +196,10 @@ } DWARFCompileUnit *DWARFDebugInfo::GetCompileUnit(const DIERef &die_ref) { - if (die_ref.cu_offset == DW_INVALID_OFFSET) + if (die_ref.cu_offset == DW_INVALID_OFFSET + // FIXME: Workaround default cu_offset = 0 in DIERef ctor. + // Why does GetCompileUnit exist at all? + || (die_ref.cu_offset == 0 /* && m_dwarf2Data->GetDWZSymbolFile() */ )) return GetCompileUnitContainingDIEOffset(die_ref.die_offset); else return GetCompileUnit(die_ref.cu_offset); Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -385,6 +385,9 @@ int &call_column, DWARFExpression *frame_base) const { if (dwarf2Data == nullptr) return false; + // DIERef(DWARFFormValue)->DWARFFormValue::Reference() may need + // FileOffsetToUniqOffset. + dwarf2Data->PreloadSymbols(); SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile(); if (dwo_symbol_file) @@ -569,7 +572,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, @@ -1323,7 +1327,7 @@ void DWARFDebugInfoEntry::BuildAddressRangeTable( SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, DWARFDebugAranges *debug_aranges) const { - if (m_tag) { + if (m_tag && m_tag != DW_TAG_partial_unit) { if (m_tag == DW_TAG_subprogram) { dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -735,6 +735,8 @@ DWARFCompileUnit *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; @@ -764,6 +766,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 @@ -1371,6 +1374,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) @@ -1483,6 +1489,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(); @@ -1503,6 +1513,7 @@ CompileUnit * SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit *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