[Lldb-commits] [lldb] r363767 - DWARF: Make DIERefs always valid

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 19 00:32:39 PDT 2019


Author: labath
Date: Wed Jun 19 00:32:39 2019
New Revision: 363767

URL: http://llvm.org/viewvc/llvm-project?rev=363767&view=rev
Log:
DWARF: Make DIERefs always valid

Summary:
This patch makes the DIERef class always valid by default constructor
and operator bool. This allows one to express the validity of a DIERef
in the type system. Places which are working with potentially-invalid
DIERefs have been updated to use Optional<DIERef> instead.

The constructor taking a DWARFFormValue was not needed, as all places
which were constructing a DIERef this way were immediately converting it
into a DWARFDIE or a user_id. This can be done without constructing an
intermediate DIERef.

Reviewers: JDevlieghere, clayborg, aprantl

Subscribers: arphaman, lldb-commits

Differential Revision: https://reviews.llvm.org/D63399

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp Wed Jun 19 00:32:39 2019
@@ -7,22 +7,3 @@
 //===----------------------------------------------------------------------===//
 
 #include "DIERef.h"
-#include "DWARFUnit.h"
-#include "DWARFDebugInfo.h"
-#include "DWARFFormValue.h"
-#include "SymbolFileDWARF.h"
-#include "SymbolFileDWARFDebugMap.h"
-
-DIERef::DIERef(const DWARFFormValue &form_value) {
-  if (form_value.IsValid()) {
-    DWARFDIE die = form_value.Reference();
-    die_offset = die.GetOffset();
-    if (die) {
-      section = die.GetCU()->GetDebugSection();
-      if (die.GetCU()->GetBaseObjOffset() != DW_INVALID_OFFSET)
-        cu_offset = die.GetCU()->GetBaseObjOffset();
-      else
-        cu_offset = die.GetCU()->GetOffset();
-    }
-  }
-}

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h Wed Jun 19 00:32:39 2019
@@ -10,28 +10,17 @@
 #define SymbolFileDWARF_DIERef_h_
 
 #include "lldb/Core/dwarf.h"
-#include "lldb/lldb-defines.h"
-
-class DWARFFormValue;
-class SymbolFileDWARF;
+#include <vector>
 
 struct DIERef {
   enum Section : uint8_t { DebugInfo, DebugTypes };
 
-  DIERef() = default;
-
   DIERef(Section s, dw_offset_t c, dw_offset_t d)
       : section(s), cu_offset(c), die_offset(d) {}
 
-  explicit DIERef(const DWARFFormValue &form_value);
-
-  explicit operator bool() const {
-    return cu_offset != DW_INVALID_OFFSET || die_offset != DW_INVALID_OFFSET;
-  }
-
-  Section section = Section::DebugInfo;
-  dw_offset_t cu_offset = DW_INVALID_OFFSET;
-  dw_offset_t die_offset = DW_INVALID_OFFSET;
+  Section section;
+  dw_offset_t cu_offset;
+  dw_offset_t die_offset;
 };
 
 typedef std::vector<DIERef> DIEArray;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Wed Jun 19 00:32:39 2019
@@ -651,7 +651,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
 
     type_sp = std::make_shared<Type>(
         die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
-        dwarf->GetUID(DIERef(attrs.type)), encoding_data_type, &attrs.decl,
+        dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl,
         clang_type, resolve_state);
 
     dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
@@ -1077,7 +1077,8 @@ TypeSP DWARFASTParserClang::ParseTypeFro
         &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE()));
     if (!clang_type) {
       if (attrs.type.IsValid()) {
-        Type *enumerator_type = dwarf->ResolveTypeUID(DIERef(attrs.type));
+        Type *enumerator_type =
+            dwarf->ResolveTypeUID(attrs.type.Reference(), true);
         if (enumerator_type)
           enumerator_clang_type = enumerator_type->GetFullCompilerType();
       }
@@ -1106,8 +1107,8 @@ TypeSP DWARFASTParserClang::ParseTypeFro
 
     type_sp = std::make_shared<Type>(
         die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
-        dwarf->GetUID(DIERef(attrs.type)), Type::eEncodingIsUID, &attrs.decl,
-        clang_type, Type::eResolveStateForward);
+        dwarf->GetUID(attrs.type.Reference()), Type::eEncodingIsUID,
+        &attrs.decl, clang_type, Type::eResolveStateForward);
 
     if (ClangASTContext::StartTagDeclarationDefinition(clang_type)) {
       if (die.HasChildren()) {
@@ -1149,7 +1150,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
     Type *func_type = NULL;
 
     if (attrs.type.IsValid())
-      func_type = dwarf->ResolveTypeUID(DIERef(attrs.type));
+      func_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true);
 
     if (func_type)
       return_clang_type = func_type->GetForwardCompilerType();
@@ -1293,8 +1294,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
               // If we have a specification, then the function type should
               // have been made with the specification and not with this
               // die.
-              DWARFDIE spec_die =
-                  dwarf->DebugInfo()->GetDIE(DIERef(attrs.specification));
+              DWARFDIE spec_die = attrs.specification.Reference();
               clang::DeclContext *spec_clang_decl_ctx =
                   GetClangDeclContextForDIE(spec_die);
               if (spec_clang_decl_ctx) {
@@ -1303,7 +1303,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                 dwarf->GetObjectFile()->GetModule()->ReportWarning(
                     "0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x"
                     ") has no decl\n",
-                    die.GetID(), attrs.specification.Reference().GetOffset());
+                    die.GetID(), spec_die.GetOffset());
               }
               type_handled = true;
             } else if (attrs.abstract_origin.IsValid()) {
@@ -1313,8 +1313,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
               // the abstract origin has a valid clang decl context.
               class_type->GetForwardCompilerType();
 
-              DWARFDIE abs_die =
-                  dwarf->DebugInfo()->GetDIE(DIERef(attrs.abstract_origin));
+              DWARFDIE abs_die = attrs.abstract_origin.Reference();
               clang::DeclContext *abs_clang_decl_ctx =
                   GetClangDeclContextForDIE(abs_die);
               if (abs_clang_decl_ctx) {
@@ -1323,7 +1322,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                 dwarf->GetObjectFile()->GetModule()->ReportWarning(
                     "0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x"
                     ") has no decl\n",
-                    die.GetID(), attrs.abstract_origin.Reference().GetOffset());
+                    die.GetID(), abs_die.GetOffset());
               }
               type_handled = true;
             } else {
@@ -1542,8 +1541,8 @@ TypeSP DWARFASTParserClang::ParseTypeFro
     DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
                  DW_TAG_value_to_name(tag), type_name_cstr);
 
-    DIERef type_die_ref(attrs.type);
-    Type *element_type = dwarf->ResolveTypeUID(type_die_ref);
+    DWARFDIE type_die = attrs.type.Reference();
+    Type *element_type = dwarf->ResolveTypeUID(type_die, true);
 
     if (element_type) {
       auto array_info = ParseChildArrayInfo(die);
@@ -1566,7 +1565,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                 "forward declaration, not a complete definition.\nTry "
                 "compiling the source file with -fstandalone-debug or "
                 "disable -gmodules",
-                die.GetOffset(), type_die_ref.die_offset);
+                die.GetOffset(), type_die.GetOffset());
           else
             module_sp->ReportError(
                 "DWARF DW_TAG_array_type DIE at 0x%8.8x has a "
@@ -1574,7 +1573,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                 "forward declaration, not a complete definition.\nPlease "
                 "file a bug against the compiler and include the "
                 "preprocessed output for %s",
-                die.GetOffset(), type_die_ref.die_offset,
+                die.GetOffset(), type_die.GetOffset(),
                 GetUnitName(die).c_str());
         }
 
@@ -1591,7 +1590,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                                  "start its definition.\nPlease file a "
                                  "bug and attach the file at the start "
                                  "of this error message",
-                                 type_die_ref.die_offset);
+                                 type_die.GetOffset());
         }
       }
 
@@ -1616,7 +1615,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
       ConstString empty_name;
       type_sp = std::make_shared<Type>(
           die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr,
-          dwarf->GetUID(type_die_ref), Type::eEncodingIsUID, &attrs.decl,
+          dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl,
           clang_type, Type::eResolveStateFull);
       type_sp->SetEncodingType(element_type);
       m_ast.SetMetadataAsUserID(clang_type.GetOpaqueQualType(), die.GetID());
@@ -1624,8 +1623,9 @@ TypeSP DWARFASTParserClang::ParseTypeFro
   } break;
 
   case DW_TAG_ptr_to_member_type: {
-    Type *pointee_type = dwarf->ResolveTypeUID(DIERef(attrs.type));
-    Type *class_type = dwarf->ResolveTypeUID(DIERef(attrs.containing_type));
+    Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true);
+    Type *class_type =
+        dwarf->ResolveTypeUID(attrs.containing_type.Reference(), true);
 
     CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType();
     CompilerType class_clang_type = class_type->GetLayoutCompilerType();
@@ -1792,7 +1792,7 @@ bool DWARFASTParserClang::ParseTemplateD
 
         case DW_AT_type:
           if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-            Type *lldb_type = die.ResolveTypeUID(DIERef(form_value));
+            Type *lldb_type = die.ResolveTypeUID(form_value.Reference());
             if (lldb_type)
               clang_type = lldb_type->GetForwardCompilerType();
           }
@@ -2634,7 +2634,7 @@ bool DWARFASTParserClang::ParseChildMemb
 
         // Handle static members
         if (is_external && member_byte_offset == UINT32_MAX) {
-          Type *var_type = die.ResolveTypeUID(DIERef(encoding_form));
+          Type *var_type = die.ResolveTypeUID(encoding_form.Reference());
 
           if (var_type) {
             if (accessibility == eAccessNone)
@@ -2647,7 +2647,7 @@ bool DWARFASTParserClang::ParseChildMemb
         }
 
         if (!is_artificial) {
-          Type *member_type = die.ResolveTypeUID(DIERef(encoding_form));
+          Type *member_type = die.ResolveTypeUID(encoding_form.Reference());
 
           clang::FieldDecl *field_decl = nullptr;
           if (tag == DW_TAG_member) {
@@ -2997,7 +2997,7 @@ bool DWARFASTParserClang::ParseChildMemb
           }
         }
 
-        Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form));
+        Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference());
         if (base_class_type == nullptr) {
           module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to "
                                  "resolve the base class at 0x%8.8x"
@@ -3121,7 +3121,8 @@ size_t DWARFASTParserClang::ParseChildPa
               // specification DIEs, so we can't rely upon the name being in
               // the formal parameter DIE...
               (name == nullptr || ::strcmp(name, "this") == 0)) {
-            Type *this_type = die.ResolveTypeUID(DIERef(param_type_die_form));
+            Type *this_type =
+                die.ResolveTypeUID(param_type_die_form.Reference());
             if (this_type) {
               uint32_t encoding_mask = this_type->GetEncodingMask();
               if (encoding_mask & Type::eEncodingIsPointerUID) {
@@ -3138,7 +3139,7 @@ size_t DWARFASTParserClang::ParseChildPa
         }
 
         if (!skip) {
-          Type *type = die.ResolveTypeUID(DIERef(param_type_die_form));
+          Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
           if (type) {
             function_param_types.push_back(type->GetForwardCompilerType());
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp Wed Jun 19 00:32:39 2019
@@ -17,9 +17,9 @@
 
 using namespace lldb_private;
 
-DIERef DWARFBaseDIE::GetDIERef() const {
+llvm::Optional<DIERef> DWARFBaseDIE::GetDIERef() const {
   if (!IsValid())
-    return DIERef();
+    return llvm::None;
 
   dw_offset_t cu_offset = m_cu->GetOffset();
   if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h Wed Jun 19 00:32:39 2019
@@ -54,7 +54,7 @@ public:
 
   DWARFDebugInfoEntry *GetDIE() const { return m_die; }
 
-  DIERef GetDIERef() const;
+  llvm::Optional<DIERef> GetDIERef() const;
 
   lldb_private::TypeSystem *GetTypeSystem() const;
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp Wed Jun 19 00:32:39 2019
@@ -313,12 +313,10 @@ lldb_private::Type *DWARFDIE::ResolveTyp
     return nullptr;
 }
 
-lldb_private::Type *DWARFDIE::ResolveTypeUID(const DIERef &die_ref) const {
-  SymbolFileDWARF *dwarf = GetDWARF();
-  if (dwarf)
-    return dwarf->ResolveTypeUID(dwarf->GetDIE(die_ref), true);
-  else
-    return nullptr;
+lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const {
+  if (SymbolFileDWARF *dwarf = GetDWARF())
+    return dwarf->ResolveTypeUID(die, true);
+  return nullptr;
 }
 
 std::vector<DWARFDIE> DWARFDIE::GetDeclContextDIEs() const {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h Wed Jun 19 00:32:39 2019
@@ -42,7 +42,7 @@ public:
   lldb_private::Type *ResolveType() const;
 
   // Resolve a type by UID using this DIE's DWARF file
-  lldb_private::Type *ResolveTypeUID(const DIERef &die_ref) const;
+  lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const;
 
   // Functions for obtaining DIE relations and references
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Wed Jun 19 00:32:39 2019
@@ -234,7 +234,7 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd
 
   dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
   dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
-  std::vector<DIERef> die_refs;
+  std::vector<DWARFDIE> dies;
   bool set_frame_base_loclist_addr = false;
 
   auto abbrevDecl = GetAbbreviationDeclarationPtr(cu);
@@ -302,11 +302,11 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd
           break;
 
         case DW_AT_abstract_origin:
-          die_refs.emplace_back(form_value);
+          dies.push_back(form_value.Reference());
           break;
 
         case DW_AT_specification:
-          die_refs.emplace_back(form_value);
+          dies.push_back(form_value.Reference());
           break;
 
         case DW_AT_decl_file:
@@ -392,13 +392,11 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd
   }
 
   if (ranges.IsEmpty() || name == nullptr || mangled == nullptr) {
-    for (const DIERef &die_ref : die_refs) {
-      if (die_ref.die_offset != DW_INVALID_OFFSET) {
-        DWARFDIE die = dwarf.GetDIE(die_ref);
-        if (die)
-          die.GetDIE()->GetDIENamesAndRanges(die.GetCU(), name, mangled, ranges,
-                                             decl_file, decl_line, decl_column,
-                                             call_file, call_line, call_column);
+    for (const DWARFDIE &die : dies) {
+      if (die) {
+        die.GetDIE()->GetDIENamesAndRanges(die.GetCU(), name, mangled, ranges,
+                                           decl_file, decl_line, decl_column,
+                                           call_file, call_line, call_column);
       }
     }
   }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp Wed Jun 19 00:32:39 2019
@@ -50,14 +50,15 @@ DebugNamesDWARFIndex::GetUnits(const Deb
   return result;
 }
 
-DIERef DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) {
+llvm::Optional<DIERef>
+DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) {
   llvm::Optional<uint64_t> cu_offset = entry.getCUOffset();
   if (!cu_offset)
-    return DIERef();
+    return llvm::None;
 
   DWARFUnit *cu = m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, *cu_offset);
   if (!cu)
-    return DIERef();
+    return llvm::None;
 
   // This initializes the DWO symbol file. It's not possible for
   // GetDwoSymbolFile to call this automatically because of mutual recursion
@@ -68,13 +69,13 @@ DIERef DebugNamesDWARFIndex::ToDIERef(co
   if (llvm::Optional<uint64_t> die_offset = entry.getDIEUnitOffset())
     return DIERef(DIERef::Section::DebugInfo, *cu_offset, die_bias + *die_offset);
 
-  return DIERef();
+  return llvm::None;
 }
 
 void DebugNamesDWARFIndex::Append(const DebugNames::Entry &entry,
                                   DIEArray &offsets) {
-  if (DIERef ref = ToDIERef(entry))
-    offsets.push_back(ref);
+  if (llvm::Optional<DIERef> ref = ToDIERef(entry))
+    offsets.push_back(*ref);
 }
 
 void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error,
@@ -160,28 +161,28 @@ void DebugNamesDWARFIndex::GetCompleteOb
         entry.tag() != DW_TAG_class_type)
       continue;
 
-    DIERef ref = ToDIERef(entry);
+    llvm::Optional<DIERef> ref = ToDIERef(entry);
     if (!ref)
       continue;
 
-    DWARFUnit *cu =
-        m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, ref.cu_offset);
+    DWARFUnit *cu = m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo,
+                                                 ref->cu_offset);
     if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) {
-      incomplete_types.push_back(ref);
+      incomplete_types.push_back(*ref);
       continue;
     }
 
     // FIXME: We should return DWARFDIEs so we don't have to resolve it twice.
-    DWARFDIE die = m_debug_info.GetDIE(ref);
+    DWARFDIE die = m_debug_info.GetDIE(*ref);
     if (!die)
       continue;
 
     if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) {
       // If we find the complete version we're done.
-      offsets.push_back(ref);
+      offsets.push_back(*ref);
       return;
     } else {
-      incomplete_types.push_back(ref);
+      incomplete_types.push_back(*ref);
     }
   }
 
@@ -234,8 +235,8 @@ void DebugNamesDWARFIndex::GetFunctions(
     if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
       continue;
 
-    if (DIERef ref = ToDIERef(entry))
-      ProcessFunctionDIE(name.GetStringRef(), ref, info, parent_decl_ctx,
+    if (llvm::Optional<DIERef> ref = ToDIERef(entry))
+      ProcessFunctionDIE(name.GetStringRef(), *ref, info, parent_decl_ctx,
                          name_type_mask, v);
   }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h Wed Jun 19 00:32:39 2019
@@ -66,7 +66,7 @@ private:
   std::unique_ptr<DebugNames> m_debug_names_up;
   ManualDWARFIndex m_fallback;
 
-  DIERef ToDIERef(const DebugNames::Entry &entry);
+  llvm::Optional<DIERef> ToDIERef(const DebugNames::Entry &entry);
   void Append(const DebugNames::Entry &entry, DIEArray &offsets);
 
   static void MaybeLogLookupError(llvm::Error error,

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp Wed Jun 19 00:32:39 2019
@@ -117,13 +117,9 @@ const char *DWARFMappedHash::GetAtomType
   return "<invalid>";
 }
 
-DWARFMappedHash::DIEInfo::DIEInfo()
-    : tag(0), type_flags(0), qualified_name_hash(0) {}
-
-DWARFMappedHash::DIEInfo::DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t,
-                                  uint32_t f, uint32_t h)
-    : die_ref(DIERef::Section::DebugInfo, c, o), tag(t), type_flags(f),
-      qualified_name_hash(h) {}
+DWARFMappedHash::DIEInfo::DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f,
+                                  uint32_t h)
+    : die_offset(o), tag(t), type_flags(f), qualified_name_hash(h) {}
 
 DWARFMappedHash::Prologue::Prologue(dw_offset_t _die_base_offset)
     : die_base_offset(_die_base_offset), atoms(), atom_mask(0),
@@ -271,7 +267,7 @@ bool DWARFMappedHash::Header::Read(const
 
     switch (header_data.atoms[i].type) {
     case eAtomTypeDIEOffset: // DIE offset, check form for encoding
-      hash_data.die_ref.die_offset =
+      hash_data.die_offset =
           DWARFFormValue::IsDataForm(form_value.Form())
               ? form_value.Unsigned()
               : form_value.Reference(header_data.die_base_offset);
@@ -294,7 +290,7 @@ bool DWARFMappedHash::Header::Read(const
       break;
     }
   }
-  return true;
+  return hash_data.die_offset != DW_INVALID_OFFSET;
 }
 
 DWARFMappedHash::MemoryTable::MemoryTable(
@@ -506,10 +502,10 @@ size_t DWARFMappedHash::MemoryTable::App
       for (uint32_t i = 0; i < count; ++i) {
         DIEInfo die_info;
         if (m_header.Read(m_data, &hash_data_offset, die_info)) {
-          if (die_info.die_ref.die_offset == 0)
+          if (die_info.die_offset == 0)
             done = true;
-          if (die_offset_start <= die_info.die_ref.die_offset &&
-              die_info.die_ref.die_offset < die_offset_end)
+          if (die_offset_start <= die_info.die_offset &&
+              die_info.die_offset < die_offset_end)
             die_info_array.push_back(die_info);
         }
       }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Wed Jun 19 00:32:39 2019
@@ -48,15 +48,21 @@ public:
   };
 
   struct DIEInfo {
-    DIERef die_ref;
-    dw_tag_t tag;
-    uint32_t type_flags;          // Any flags for this DIEInfo
-    uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name
+    dw_offset_t die_offset = DW_INVALID_OFFSET;
+    dw_tag_t tag = 0;
 
-    DIEInfo();
-    DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
+    /// Any flags for this DIEInfo
+    uint32_t type_flags = 0;
 
-    explicit operator DIERef() const { return die_ref; }
+    /// A 32 bit hash of the fully qualified name
+    uint32_t qualified_name_hash = 0;
+
+    DIEInfo() = default;
+    DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
+
+    explicit operator DIERef() const {
+      return DIERef(DIERef::Section::DebugInfo, DW_INVALID_OFFSET, die_offset);
+    }
   };
 
   struct Atom {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Jun 19 00:32:39 2019
@@ -1199,7 +1199,8 @@ void SymbolFileDWARF::ParseDeclsForConte
       ast_parser->GetDeclForUIDFromDWARF(decl);
 }
 
-SymbolFileDWARF::DecodedUID SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) {
+llvm::Optional<SymbolFileDWARF::DecodedUID>
+SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) {
   // This method can be called without going through the symbol vendor so we
   // need to lock the module.
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -1213,7 +1214,9 @@ SymbolFileDWARF::DecodedUID SymbolFileDW
   if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) {
     SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex(
         debug_map->GetOSOIndexFromUserID(uid));
-    return {dwarf, {DIERef::Section::DebugInfo, DW_INVALID_OFFSET, dw_offset_t(uid)}};
+    return DecodedUID{
+        *dwarf,
+        {DIERef::Section::DebugInfo, DW_INVALID_OFFSET, dw_offset_t(uid)}};
   }
   DIERef::Section section =
       uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo;
@@ -1221,7 +1224,7 @@ SymbolFileDWARF::DecodedUID SymbolFileDW
   dw_offset_t die_offset = uid;
 
   if (die_offset == DW_INVALID_OFFSET)
-    return {nullptr, DIERef()};
+    return llvm::None;
 
   SymbolFileDWARF *dwarf = this;
   if (DebugInfo()) {
@@ -1230,7 +1233,7 @@ SymbolFileDWARF::DecodedUID SymbolFileDW
         dwarf = unit->GetDwoSymbolFile();
     }
   }
-  return {dwarf, {section, DW_INVALID_OFFSET, die_offset}};
+  return DecodedUID{*dwarf, {section, DW_INVALID_OFFSET, die_offset}};
 }
 
 DWARFDIE
@@ -1239,10 +1242,10 @@ SymbolFileDWARF::GetDIE(lldb::user_id_t
   // need to lock the module.
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
 
-  DecodedUID decoded = DecodeUID(uid);
+  llvm::Optional<DecodedUID> decoded = DecodeUID(uid);
 
-  if (decoded.dwarf)
-    return decoded.dwarf->GetDIE(decoded.ref);
+  if (decoded)
+    return decoded->dwarf.GetDIE(decoded->ref);
 
   return DWARFDIE();
 }
@@ -3453,7 +3456,7 @@ VariableSP SymbolFileDWARF::ParseVariabl
 
       if (symbol_context_scope) {
         SymbolFileTypeSP type_sp(
-            new SymbolFileType(*this, GetUID(DIERef(type_die_form))));
+            new SymbolFileType(*this, GetUID(type_die_form.Reference())));
 
         if (const_value.Form() && type_sp && type_sp->GetType())
           location.UpdateValue(const_value.Unsigned(),

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=363767&r1=363766&r2=363767&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Jun 19 00:32:39 2019
@@ -272,6 +272,10 @@ public:
     return GetUID(die.GetDIERef());
   }
 
+  lldb::user_id_t GetUID(const llvm::Optional<DIERef> &ref) {
+    return ref ? GetUID(*ref) : LLDB_INVALID_UID;
+  }
+
   lldb::user_id_t GetUID(const DIERef &ref) {
     return GetID() | ref.die_offset |
            (lldb::user_id_t(ref.section == DIERef::Section::DebugTypes) << 63);
@@ -437,10 +441,10 @@ protected:
   llvm::Optional<uint32_t> GetDWARFUnitIndex(uint32_t cu_idx);
 
   struct DecodedUID {
-    SymbolFileDWARF *dwarf;
+    SymbolFileDWARF &dwarf;
     DIERef ref;
   };
-  DecodedUID DecodeUID(lldb::user_id_t uid);
+  llvm::Optional<DecodedUID> DecodeUID(lldb::user_id_t uid);
 
   SymbolFileDWARFDwp *GetDwpSymbolFile();
 




More information about the lldb-commits mailing list