jankratochvil updated this revision to Diff 143476.
jankratochvil retitled this revision from "DWZ 05/11: Match also 
DW_TAG_partial_unit when DW_TAG_compile_unit is matched" to "DWZ 02/07: Match 
also DW_TAG_partial_unit when DW_TAG_compile_unit is matched".
jankratochvil added a comment.

It is now reworked without `FileOffset` and the remapping to unique DIE offsets 
for each `DW_TAG_partial_unit` inclusion by `DW_TAG_imported_unit`, as 
discussed in: 
https://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20180409/040324.html


https://reviews.llvm.org/D40469

Files:
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp

Index: source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
+++ source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
@@ -57,6 +57,7 @@
               } break;
 
               case DW_TAG_compile_unit:
+              case DW_TAG_partial_unit:
                 done = true;
                 break;
               }
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -381,6 +381,7 @@
 
     switch (tag) {
     case DW_TAG_compile_unit:
+    case DW_TAG_partial_unit:
     case DW_TAG_subprogram:
     case DW_TAG_inlined_subroutine:
     case DW_TAG_lexical_block:
@@ -3109,6 +3110,7 @@
       if (orig_die != die) {
         switch (die.Tag()) {
         case DW_TAG_compile_unit:
+        case DW_TAG_partial_unit:
         case DW_TAG_namespace:
         case DW_TAG_structure_type:
         case DW_TAG_union_type:
@@ -3307,7 +3309,7 @@
   //   [0] DW_TAG_class_type for "B"
   //   [1] DW_TAG_class_type for "A"
   //   [2] DW_TAG_namespace  for "lldb"
-  //   [3] DW_TAG_compile_unit for the source file.
+  //   [3] DW_TAG_compile_unit or DW_TAG_partial_unit for the source file.
   //
   // We grab both contexts and make sure that everything matches
   // all the way back to the compiler unit.
@@ -3336,9 +3338,11 @@
 #if defined LLDB_CONFIGURATION_DEBUG
 
   // Make sure the top item in the decl context die array is always
-  // DW_TAG_compile_unit. If it isn't then something went wrong in
-  // the DWARFDIE::GetDeclContextDIEs() function...
-  assert(decl_ctx_1.GetDIEAtIndex(count1 - 1).Tag() == DW_TAG_compile_unit);
+  // DW_TAG_compile_unit or DW_TAG_partial_unit. If it isn't then something
+  // went wrong in the DWARFDIE::GetDeclContextDIEs() function...
+  dw_tag_t cu_tag = decl_ctx_1.GetDIEAtIndex(count1 - 1).Tag();
+  UNUSED_IF_ASSERT_DISABLED(cu_tag);
+  assert(cu_tag == DW_TAG_compile_unit || cu_tag == DW_TAG_partial_unit);
 
 #endif
   // Always skip the compile unit when comparing by only iterating up to
@@ -3940,7 +3944,8 @@
       const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
       const dw_tag_t parent_tag = die.GetParent().Tag();
       bool is_static_member =
-          parent_tag == DW_TAG_compile_unit &&
+          (parent_tag == DW_TAG_compile_unit ||
+           parent_tag == DW_TAG_partial_unit) &&
           (parent_context_die.Tag() == DW_TAG_class_type ||
            parent_context_die.Tag() == DW_TAG_structure_type);
 
@@ -3962,7 +3967,8 @@
         // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we
         // should be able
         // to generate a fully qualified name from the declaration context.
-        if (parent_tag == DW_TAG_compile_unit &&
+        if ((parent_tag == DW_TAG_compile_unit ||
+             parent_tag == DW_TAG_partial_unit) &&
             Language::LanguageIsCPlusPlus(die.GetLanguage())) {
           DWARFDeclContext decl_ctx;
 
@@ -4220,6 +4226,7 @@
           dw_tag_t parent_tag = sc_parent_die.Tag();
           switch (parent_tag) {
           case DW_TAG_compile_unit:
+          case DW_TAG_partial_unit:
             if (sc.comp_unit != NULL) {
               variable_list_sp = sc.comp_unit->GetVariableList(false);
               if (variable_list_sp.get() == NULL) {
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -804,6 +804,7 @@
                 break;
 
               case DW_TAG_compile_unit:
+              case DW_TAG_partial_unit:
                 is_global_or_static_variable = true;
                 parent_die = NULL; // Terminate the while loop.
                 break;
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -218,7 +218,8 @@
         m_tag = abbrevDecl->Tag();
         m_has_children = abbrevDecl->HasChildren();
 
-        bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
+        bool isCompileUnitTag = (m_tag == DW_TAG_compile_unit ||
+                                 m_tag == DW_TAG_partial_unit);
         if (cu && isCompileUnitTag)
           const_cast<DWARFUnit *>(cu)->SetBaseAddress(0);
 
@@ -770,7 +771,7 @@
   const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
   lldb::offset_t offset = 0;
   if (cu) {
-    if (m_tag != DW_TAG_compile_unit) {
+    if (m_tag != DW_TAG_compile_unit && m_tag != DW_TAG_partial_unit) {
       SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
       if (dwo_symbol_file)
         return GetAttributes(dwo_symbol_file->GetCompileUnit(),
@@ -851,7 +852,8 @@
     dw_offset_t *end_attr_offset_ptr,
     bool check_specification_or_abstract_origin) const {
   SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
-  if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
+  if (dwo_symbol_file && m_tag != DW_TAG_compile_unit &&
+                         m_tag != DW_TAG_partial_unit)
     return GetAttributeValue(dwo_symbol_file, dwo_symbol_file->GetCompileUnit(),
                              attr, form_value, end_attr_offset_ptr,
                              check_specification_or_abstract_origin);
@@ -1382,11 +1384,12 @@
     SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
     DWARFDeclContext &dwarf_decl_ctx) const {
   const dw_tag_t tag = Tag();
-  if (tag != DW_TAG_compile_unit) {
+  if (tag != DW_TAG_compile_unit && tag != DW_TAG_partial_unit) {
     dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
     DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
     if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
-      if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
+      if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit &&
+          parent_decl_ctx_die.Tag() != DW_TAG_partial_unit)
         parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
             parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(),
             dwarf_decl_ctx);
@@ -1424,6 +1427,7 @@
     if (die.GetDIE() != this) {
       switch (die.Tag()) {
       case DW_TAG_compile_unit:
+      case DW_TAG_partial_unit:
       case DW_TAG_namespace:
       case DW_TAG_structure_type:
       case DW_TAG_union_type:
@@ -1661,6 +1665,7 @@
     case DW_TAG_unspecified_type:
       break;
     case DW_TAG_partial_unit:
+      match_addr_range = true;
       break;
     case DW_TAG_imported_unit:
       break;
@@ -1684,6 +1689,7 @@
             //  puts("***MATCH***");
             switch (m_tag) {
             case DW_TAG_compile_unit: // File
+            case DW_TAG_partial_unit: // File
               check_children = ((function_die != NULL) || (block_die != NULL));
               break;
 
@@ -1709,7 +1715,8 @@
         } else { // compile units may not have a valid high/low pc when there
           // are address gaps in subroutines so we must always search
           // if there is no valid high and low PC
-          check_children = (m_tag == DW_TAG_compile_unit) &&
+          check_children = (m_tag == DW_TAG_compile_unit ||
+                            m_tag == DW_TAG_partial_unit) &&
                            ((function_die != NULL) || (block_die != NULL));
         }
       } else {
@@ -1728,6 +1735,7 @@
             //  puts("***MATCH***");
             switch (m_tag) {
             case DW_TAG_compile_unit: // File
+            case DW_TAG_partial_unit: // File
               check_children = ((function_die != NULL) || (block_die != NULL));
               break;
 
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -267,7 +267,7 @@
 
 void DWARFDIE::GetDWOContext(std::vector<CompilerContext> &context) const {
   const dw_tag_t tag = Tag();
-  if (tag == DW_TAG_compile_unit)
+  if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
     return;
   DWARFDIE parent = GetParent();
   if (parent)
@@ -374,7 +374,7 @@
       const dw_tag_t tag = parent.Tag();
       if (tag == DW_TAG_module)
         top_module_die = parent;
-      else if (tag == DW_TAG_compile_unit)
+      else if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
         break;
     }
 
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
@@ -98,7 +98,8 @@
   dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
   SymbolContextScope *symbol_context_scope = nullptr;
-  if (sc_parent_tag == DW_TAG_compile_unit) {
+  if (sc_parent_tag == DW_TAG_compile_unit ||
+      sc_parent_tag == DW_TAG_partial_unit) {
     symbol_context_scope = sc.comp_unit;
   } else if (sc.function != nullptr && sc_parent_die) {
     symbol_context_scope =
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
@@ -324,7 +324,8 @@
   dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
   SymbolContextScope *symbol_context_scope = nullptr;
-  if (sc_parent_tag == DW_TAG_compile_unit) {
+  if (sc_parent_tag == DW_TAG_compile_unit ||
+      sc_parent_tag == DW_TAG_partial_unit) {
     symbol_context_scope = sc.comp_unit;
   } else if (sc.function != nullptr && sc_parent_die) {
     symbol_context_scope =
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
@@ -431,7 +431,8 @@
         dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
         SymbolContextScope *symbol_context_scope = NULL;
-        if (sc_parent_tag == DW_TAG_compile_unit) {
+        if (sc_parent_tag == DW_TAG_compile_unit ||
+            sc_parent_tag == DW_TAG_partial_unit) {
           symbol_context_scope = sc.comp_unit;
         } else if (sc.function != NULL && sc_parent_die) {
           symbol_context_scope =
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1925,7 +1925,8 @@
         dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
         SymbolContextScope *symbol_context_scope = NULL;
-        if (sc_parent_tag == DW_TAG_compile_unit) {
+        if (sc_parent_tag == DW_TAG_compile_unit ||
+            sc_parent_tag == DW_TAG_partial_unit) {
           symbol_context_scope = sc.comp_unit;
         } else if (sc.function != NULL && sc_parent_die) {
           symbol_context_scope =
@@ -2745,7 +2746,8 @@
       Mangled func_name;
       if (mangled)
         func_name.SetValue(ConstString(mangled), true);
-      else if (die.GetParent().Tag() == DW_TAG_compile_unit &&
+      else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
+                die.GetParent().Tag() == DW_TAG_partial_unit) &&
                Language::LanguageIsCPlusPlus(die.GetLanguage()) && name &&
                strcmp(name, "main") != 0) {
         // If the mangled name is not present in the DWARF, generate the
@@ -3838,6 +3840,7 @@
     bool try_parsing_type = true;
     switch (die.Tag()) {
     case DW_TAG_compile_unit:
+    case DW_TAG_partial_unit:
       decl_ctx = m_ast.GetTranslationUnitDecl();
       try_parsing_type = false;
       break;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to