jankratochvil updated this revision to Diff 157897.
jankratochvil edited the summary of this revision.

https://reviews.llvm.org/D40473

Files:
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -740,6 +740,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;
@@ -769,6 +771,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)
@@ -1480,6 +1486,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();
 
@@ -1500,6 +1510,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 need to parse
@@ -3164,8 +3175,8 @@
 VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
                                              const DWARFDIE &die,
                                              const lldb::addr_t func_low_pc) {
-  if (die.GetDWARF() != this)
-    return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
+  if (die.GetMainDWARF() != this)
+    return die.GetMainDWARF()->ParseVariableDIE(sc, die, func_low_pc);
 
   VariableSP var_sp;
   if (!die)
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -175,6 +175,11 @@
     return die_iterator_range(m_die_array.begin(), m_die_array.end());
   }
 
+  // DW_TAG_compile_unit with DW_TAG_imported_unit for this DW_TAG_partial_unit.
+  DWARFUnit *GetMainCU() const {
+    return const_cast<DWARFUnit *>(this);
+  }
+
 protected:
   DWARFUnit(SymbolFileDWARF *dwarf);
 
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -510,6 +510,9 @@
 }
 
 TypeSystem *DWARFUnit::GetTypeSystem() {
+  if (GetMainCU() != this)
+    return GetMainCU()->GetTypeSystem();
+
   if (m_dwarf)
     return m_dwarf->GetTypeSystemForLanguage(GetLanguageType());
   else
@@ -557,7 +560,7 @@
       // 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_dwarf->DebugInfo()->GetDIEForDIEOffset(die_offset);
+      return GetMainCU()->m_dwarf->DebugInfo()->GetDIEForDIEOffset(die_offset);
     }
   }
   m_dwarf->GetObjectFile()->GetModule()->ReportError(
@@ -695,6 +698,9 @@
 }
 
 LanguageType DWARFUnit::GetLanguageType() {
+  if (GetMainCU() != this)
+    return GetMainCU()->GetLanguageType();
+
   if (m_language_type != eLanguageTypeUnknown)
     return m_language_type;
 
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -566,7 +566,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/DWARFDebugInfo.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -75,6 +75,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/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -84,7 +84,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();
 }
@@ -138,13 +139,13 @@
 
 lldb_private::Type *DWARFDIE::ResolveType() const {
   if (IsValid())
-    return GetDWARF()->ResolveType(*this, true);
+    return GetMainDWARF()->ResolveType(*this, true);
   else
     return nullptr;
 }
 
 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
Index: source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
+++ source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
@@ -55,6 +55,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/DWARFBaseDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
@@ -138,6 +138,13 @@
     return nullptr;
 }
 
+SymbolFileDWARF *DWARFBaseDIE::GetMainDWARF() const {
+  if (m_cu)
+    return m_cu->GetMainCU()->GetSymbolFileDWARF();
+  else
+    return nullptr;
+}
+
 lldb_private::TypeSystem *DWARFBaseDIE::GetTypeSystem() const {
   if (m_cu)
     return m_cu->GetTypeSystem();
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -238,7 +238,7 @@
 
   AccessType accessibility = eAccessNone;
   if (die) {
-    SymbolFileDWARF *dwarf = die.GetDWARF();
+    SymbolFileDWARF *dwarf = die.GetMainDWARF();
     if (log) {
       DWARFDIE context_die;
       clang::DeclContext *context =
@@ -3631,7 +3631,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) {
@@ -3689,7 +3689,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();
@@ -3703,7 +3703,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();
@@ -3721,7 +3721,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) {
@@ -3778,7 +3778,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);
     }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to