alexshap created this revision.
Herald added subscribers: JDevlieghere, aprantl.

At the moment for DIERefs coming from DWO/DWP LLDB expects cu_offset to be 
equal to the offset of
the original compilation unit. This invariant is ensured during the "indexing" 
of DIEs of the original SymbolFileDWARF 
and during the "retrieval" (see, for example, SymbolFileDWARFDwo::GetDIE(const 
DIERef &die_ref) ) as well.
However any call of SymbolFileDWARFDwo::Index would violate this invariant 
since GetOffset() would return 0 in this case
(and later the various asserts would fire).
The diff addresses the issue.


Repository:
  rL LLVM

https://reviews.llvm.org/D39825

Files:
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h


Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
@@ -45,6 +45,10 @@
     return nullptr;
   }
 
+  DWARFCompileUnit* GetBaseCompileUnit() override {
+    return m_base_dwarf_cu;
+  }
+
 protected:
   void LoadSectionData(lldb::SectionType sect_type,
                        lldb_private::DWARFDataExtractor &data) override;
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -299,6 +299,11 @@
   GetDwoSymbolFileForCompileUnit(DWARFCompileUnit &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();
+
 protected:
   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
       DIEToTypePtr;
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -209,6 +209,10 @@
   return nullptr;
 }
 
+DWARFCompileUnit* SymbolFileDWARF::GetBaseCompileUnit() {
+  return nullptr;
+}
+
 void SymbolFileDWARF::Initialize() {
   LogChannelDWARF::Initialize();
   PluginManager::RegisterPlugin(GetPluginNameStatic(),
Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -634,14 +634,23 @@
       DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
                                                       m_is_dwarf64);
 
-  IndexPrivate(this, cu_language, fixed_form_sizes, GetOffset(), 
func_basenames,
+  dw_offset_t cu_offset = DW_INVALID_OFFSET;
+  // m_dwarf2Data->GetBaseCompileUnit() will return non null
+  // if m_dwarf2Data represents a DWO or DWP file.
+  // In this case the offset of the base compile unit should be used.
+  if (const DWARFCompileUnit *base_cu =  m_dwarf2Data->GetBaseCompileUnit())
+    cu_offset = base_cu->GetOffset();
+  else
+    cu_offset = GetOffset();
+
+  IndexPrivate(this, cu_language, fixed_form_sizes, cu_offset, func_basenames,
                func_fullnames, func_methods, func_selectors,
                objc_class_selectors, globals, types, namespaces);
 
   SymbolFileDWARFDwo *dwo_symbol_file = GetDwoSymbolFile();
   if (dwo_symbol_file) {
     IndexPrivate(dwo_symbol_file->GetCompileUnit(), cu_language,
-                 fixed_form_sizes, GetOffset(), func_basenames, func_fullnames,
+                 fixed_form_sizes, cu_offset, func_basenames, func_fullnames,
                  func_methods, func_selectors, objc_class_selectors, globals,
                  types, namespaces);
   }


Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
@@ -45,6 +45,10 @@
     return nullptr;
   }
 
+  DWARFCompileUnit* GetBaseCompileUnit() override {
+    return m_base_dwarf_cu;
+  }
+
 protected:
   void LoadSectionData(lldb::SectionType sect_type,
                        lldb_private::DWARFDataExtractor &data) override;
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -299,6 +299,11 @@
   GetDwoSymbolFileForCompileUnit(DWARFCompileUnit &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();
+
 protected:
   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
       DIEToTypePtr;
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -209,6 +209,10 @@
   return nullptr;
 }
 
+DWARFCompileUnit* SymbolFileDWARF::GetBaseCompileUnit() {
+  return nullptr;
+}
+
 void SymbolFileDWARF::Initialize() {
   LogChannelDWARF::Initialize();
   PluginManager::RegisterPlugin(GetPluginNameStatic(),
Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -634,14 +634,23 @@
       DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
                                                       m_is_dwarf64);
 
-  IndexPrivate(this, cu_language, fixed_form_sizes, GetOffset(), func_basenames,
+  dw_offset_t cu_offset = DW_INVALID_OFFSET;
+  // m_dwarf2Data->GetBaseCompileUnit() will return non null
+  // if m_dwarf2Data represents a DWO or DWP file.
+  // In this case the offset of the base compile unit should be used.
+  if (const DWARFCompileUnit *base_cu =  m_dwarf2Data->GetBaseCompileUnit())
+    cu_offset = base_cu->GetOffset();
+  else
+    cu_offset = GetOffset();
+
+  IndexPrivate(this, cu_language, fixed_form_sizes, cu_offset, func_basenames,
                func_fullnames, func_methods, func_selectors,
                objc_class_selectors, globals, types, namespaces);
 
   SymbolFileDWARFDwo *dwo_symbol_file = GetDwoSymbolFile();
   if (dwo_symbol_file) {
     IndexPrivate(dwo_symbol_file->GetCompileUnit(), cu_language,
-                 fixed_form_sizes, GetOffset(), func_basenames, func_fullnames,
+                 fixed_form_sizes, cu_offset, func_basenames, func_fullnames,
                  func_methods, func_selectors, objc_class_selectors, globals,
                  types, namespaces);
   }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to