labath created this revision.
labath added reviewers: JDevlieghere, clayborg, aprantl.
Herald added a subscriber: arphaman.
labath marked an inline comment as done.
labath added inline comments.


================
Comment at: source/Plugins/SymbolFile/DWARF/DIERef.cpp:1
 //===-- DIERef.cpp ----------------------------------------------*- C++ 
-*-===//
 //
----------------
I'm not deleting this file, because I'm going to add some stuff to it in the 
next patch in this series.


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.


https://reviews.llvm.org/D63399

Files:
  source/Plugins/SymbolFile/DWARF/DIERef.cpp
  source/Plugins/SymbolFile/DWARF/DIERef.h
  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/DWARFDIE.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
  source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
  source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
  source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -269,7 +269,13 @@
   DWARFDIE GetDIE(lldb::user_id_t uid);
 
   lldb::user_id_t GetUID(const DWARFBaseDIE &die) {
-    return GetUID(die.GetDIERef());
+    if (die)
+      return GetUID(*die.GetDIERef());
+    return LLDB_INVALID_UID;
+  }
+
+  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) {
@@ -437,10 +443,10 @@
   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();
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1199,7 +1199,8 @@
       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 @@
   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 @@
   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 @@
         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 @@
   // 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 @@
 
       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(),
Index: source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -48,15 +48,21 @@
   };
 
   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 {
Index: source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -117,13 +117,9 @@
   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 @@
 
     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 @@
       break;
     }
   }
-  return true;
+  return hash_data.die_offset != DW_INVALID_OFFSET;
 }
 
 DWARFMappedHash::MemoryTable::MemoryTable(
@@ -506,10 +502,10 @@
       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);
         }
       }
Index: source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
+++ source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
@@ -66,7 +66,7 @@
   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,
Index: source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -50,14 +50,15 @@
   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 @@
   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 @@
         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 @@
     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);
   }
 
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -234,7 +234,7 @@
 
   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 @@
           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 @@
   }
 
   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);
       }
     }
   }
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.h
@@ -42,7 +42,7 @@
   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
 
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -313,12 +313,10 @@
     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 {
Index: source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
+++ source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
@@ -54,7 +54,7 @@
 
   DWARFDebugInfoEntry *GetDIE() const { return m_die; }
 
-  DIERef GetDIERef() const;
+  llvm::Optional<DIERef> GetDIERef() const;
 
   lldb_private::TypeSystem *GetTypeSystem() const;
 
Index: source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
@@ -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)
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -651,7 +651,7 @@
 
     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 @@
         &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 @@
 
     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 @@
     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 @@
               // 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 @@
                 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 @@
               // 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 @@
                 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 @@
     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 @@
                 "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 @@
                 "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 @@
                                  "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 @@
       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 @@
   } 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 @@
 
         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 @@
 
         // 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 @@
         }
 
         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 @@
           }
         }
 
-        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 @@
               // 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 @@
         }
 
         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());
 
Index: source/Plugins/SymbolFile/DWARF/DIERef.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DIERef.h
+++ source/Plugins/SymbolFile/DWARF/DIERef.h
@@ -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;
Index: source/Plugins/SymbolFile/DWARF/DIERef.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DIERef.cpp
+++ source/Plugins/SymbolFile/DWARF/DIERef.cpp
@@ -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();
-    }
-  }
-}
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to