diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
@@ -34,32 +34,31 @@
 
   void
   GetGlobalVariables(ConstString basename,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const RegularExpression &regex,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const DWARFUnit &cu,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetObjCMethods(ConstString class_name,
-                      llvm::function_ref<bool(DIERef ref)> callback) override;
-  void
-  GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
-                       llvm::function_ref<bool(DIERef ref)> callback) override;
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
+  void GetCompleteObjCClass(
+      ConstString class_name, bool must_be_implementation,
+      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetNamespaces(ConstString name,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
                     const CompilerDeclContext &parent_decl_ctx,
                     uint32_t name_type_mask,
                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(const RegularExpression &regex,
-                    llvm::function_ref<bool(DIERef ref)> callback) override;
+                    llvm::function_ref<bool(DWARFDIE die)> callback) override;
 
-  void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override;
   void Dump(Stream &s) override;
 
 private:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
@@ -53,59 +53,69 @@
 }
 
 void AppleDWARFIndex::GetGlobalVariables(
-    ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_names_up)
     return;
-  m_apple_names_up->FindByName(basename.GetStringRef(), callback);
+  m_apple_names_up->FindByName(
+      basename.GetStringRef(),
+      DIERefCallback(callback, basename.GetStringRef()));
 }
 
 void AppleDWARFIndex::GetGlobalVariables(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_names_up)
     return;
 
   DWARFMappedHash::DIEInfoArray hash_data;
   m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data);
-  DWARFMappedHash::ExtractDIEArray(hash_data, callback);
+  // This is not really the DIE name.
+  DWARFMappedHash::ExtractDIEArray(hash_data,
+                                   DIERefCallback(callback, regex.GetText()));
 }
 
 void AppleDWARFIndex::GetGlobalVariables(
-    const DWARFUnit &cu, llvm::function_ref<bool(DIERef ref)> callback) {
+    const DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_names_up)
     return;
 
   DWARFMappedHash::DIEInfoArray hash_data;
   m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), cu.GetNextUnitOffset(),
                                          hash_data);
-  DWARFMappedHash::ExtractDIEArray(hash_data, callback);
+  DWARFMappedHash::ExtractDIEArray(hash_data, DIERefCallback(callback));
 }
 
 void AppleDWARFIndex::GetObjCMethods(
-    ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_objc_up)
     return;
-  m_apple_objc_up->FindByName(class_name.GetStringRef(), callback);
+  m_apple_objc_up->FindByName(
+      class_name.GetStringRef(),
+      DIERefCallback(callback, class_name.GetStringRef()));
 }
 
 void AppleDWARFIndex::GetCompleteObjCClass(
     ConstString class_name, bool must_be_implementation,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_types_up)
     return;
   m_apple_types_up->FindCompleteObjCClassByName(
-      class_name.GetStringRef(), callback, must_be_implementation);
+      class_name.GetStringRef(),
+      DIERefCallback(callback, class_name.GetStringRef()),
+      must_be_implementation);
 }
 
-void AppleDWARFIndex::GetTypes(ConstString name,
-                               llvm::function_ref<bool(DIERef ref)> callback) {
+void AppleDWARFIndex::GetTypes(
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_types_up)
     return;
-  m_apple_types_up->FindByName(name.GetStringRef(), callback);
+  m_apple_types_up->FindByName(name.GetStringRef(),
+                               DIERefCallback(callback, name.GetStringRef()));
 }
 
-void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context,
-                               llvm::function_ref<bool(DIERef ref)> callback) {
+void AppleDWARFIndex::GetTypes(
+    const DWARFDeclContext &context,
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_types_up)
     return;
 
@@ -125,7 +135,8 @@
     if (log)
       m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
     m_apple_types_up->FindByNameAndTagAndQualifiedNameHash(
-        type_name.GetStringRef(), tag, qualified_name_hash, callback);
+        type_name.GetStringRef(), tag, qualified_name_hash,
+        DIERefCallback(callback, type_name.GetStringRef()));
     return;
   }
 
@@ -146,18 +157,23 @@
 
     if (log)
       m_module.LogMessage(log, "FindByNameAndTag()");
-    m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, callback);
+    m_apple_types_up->FindByNameAndTag(
+        type_name.GetStringRef(), tag,
+        DIERefCallback(callback, type_name.GetStringRef()));
     return;
   }
 
-  m_apple_types_up->FindByName(type_name.GetStringRef(), callback);
+  m_apple_types_up->FindByName(
+      type_name.GetStringRef(),
+      DIERefCallback(callback, type_name.GetStringRef()));
 }
 
 void AppleDWARFIndex::GetNamespaces(
-    ConstString name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_namespaces_up)
     return;
-  m_apple_namespaces_up->FindByName(name.GetStringRef(), callback);
+  m_apple_namespaces_up->FindByName(
+      name.GetStringRef(), DIERefCallback(callback, name.GetStringRef()));
 }
 
 void AppleDWARFIndex::GetFunctions(
@@ -172,21 +188,14 @@
 
 void AppleDWARFIndex::GetFunctions(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   if (!m_apple_names_up)
     return;
 
   DWARFMappedHash::DIEInfoArray hash_data;
   m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data);
-  DWARFMappedHash::ExtractDIEArray(hash_data, callback);
-}
-
-void AppleDWARFIndex::ReportInvalidDIERef(const DIERef &ref,
-                                          llvm::StringRef name) {
-  m_module.ReportErrorIfModifyDetected(
-      "the DWARF debug information has been modified (accelerator table had "
-      "bad die 0x%8.8x for '%s')\n",
-      ref.die_offset(), name.str().c_str());
+  DWARFMappedHash::ExtractDIEArray(hash_data,
+                                   DIERefCallback(callback, regex.GetText()));
 }
 
 void AppleDWARFIndex::Dump(Stream &s) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2013,11 +2013,8 @@
     if (class_language == eLanguageTypeObjC) {
       ConstString class_name(clang_type.GetTypeName());
       if (class_name) {
-        dwarf->GetObjCMethods(class_name, [&](DIERef die_ref) {
-          DWARFDebugInfo &debug_info = dwarf->DebugInfo();
-          DWARFDIE method_die = debug_info.GetDIE(die_ref);
-          if (method_die)
-            method_die.ResolveType();
+        dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) {
+          method_die.ResolveType();
           return true;
         });
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
@@ -29,35 +29,36 @@
   /// the consumer.
   virtual void
   GetGlobalVariables(ConstString basename,
-                     llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
 
   virtual void
   GetGlobalVariables(const RegularExpression &regex,
-                     llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void
   GetGlobalVariables(const DWARFUnit &cu,
-                     llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void
   GetObjCMethods(ConstString class_name,
-                 llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                 llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void
   GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
-                       llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                       llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void GetTypes(ConstString name,
-                        llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                        llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void GetTypes(const DWARFDeclContext &context,
-                        llvm::function_ref<bool(DIERef ref)> callback) = 0;
-  virtual void GetNamespaces(ConstString name,
-                             llvm::function_ref<bool(DIERef ref)> callback) = 0;
+                        llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
+  virtual void
+  GetNamespaces(ConstString name,
+                llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
   virtual void
   GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
                const CompilerDeclContext &parent_decl_ctx,
                uint32_t name_type_mask,
                llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
-  virtual void GetFunctions(const RegularExpression &regex,
-                            llvm::function_ref<bool(DIERef ref)> callback) = 0;
+  virtual void
+  GetFunctions(const RegularExpression &regex,
+               llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
 
-  virtual void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) = 0;
   virtual void Dump(Stream &s) = 0;
 
 protected:
@@ -72,6 +73,33 @@
                           const CompilerDeclContext &parent_decl_ctx,
                           uint32_t name_type_mask,
                           llvm::function_ref<bool(DWARFDIE die)> callback);
+
+  /// std::function can capture at most X pointers from DIERefCallbackImpl's
+  /// lambda function, otherwise it will allocate memory during each call.
+  /// libstdc++9 can capture at most 2 pointers, libcxx9 can capture 3 pointers.
+  /// DIERefCallbackImpl does reduce the capture size to prevent allocations.
+  /// Be careful to keep DIERefCallbackImpl alive during the lifetime
+  /// of the returned function.
+  class DIERefCallbackImpl {
+  public:
+    DIERefCallbackImpl(const DWARFIndex &index,
+                       llvm::function_ref<bool(DWARFDIE die)> callback,
+                       llvm::StringRef name);
+    bool operator()(DIERef ref) const;
+
+  private:
+    const DWARFIndex &m_index;
+    SymbolFileDWARF &m_dwarf;
+    const llvm::function_ref<bool(DWARFDIE die)> m_callback;
+    const llvm::StringRef m_name;
+  };
+  DIERefCallbackImpl
+  DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback,
+                 llvm::StringRef name = {}) const {
+    return DIERefCallbackImpl(*this, callback, name);
+  }
+
+  void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const;
 };
 } // namespace lldb_private
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -11,6 +11,8 @@
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 
+#include "lldb/Core/Module.h"
+
 using namespace lldb_private;
 using namespace lldb;
 
@@ -61,3 +63,26 @@
 
   return true;
 }
+
+DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
+    const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,
+    llvm::StringRef name)
+    : m_index(index),
+      m_dwarf(*llvm::cast<SymbolFileDWARF>(index.m_module.GetSymbolFile())),
+      m_callback(callback), m_name(name) {}
+
+bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
+  DWARFDIE die = m_dwarf.GetDIE(ref);
+  if (!die) {
+    m_index.ReportInvalidDIERef(ref, m_name);
+    return true;
+  }
+  return m_callback(die);
+}
+
+void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {
+  m_module.ReportErrorIfModifyDetected(
+      "the DWARF debug information has been modified (accelerator table had "
+      "bad die 0x%8.8x for '%s')\n",
+      ref.die_offset(), name.str().c_str());
+}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
@@ -27,32 +27,32 @@
 
   void
   GetGlobalVariables(ConstString basename,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const RegularExpression &regex,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const DWARFUnit &cu,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
-  void GetObjCMethods(ConstString class_name,
-                      llvm::function_ref<bool(DIERef ref)> callback) override {}
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
-  GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
-                       llvm::function_ref<bool(DIERef ref)> callback) override;
+  GetObjCMethods(ConstString class_name,
+                 llvm::function_ref<bool(DWARFDIE die)> callback) override {}
+  void GetCompleteObjCClass(
+      ConstString class_name, bool must_be_implementation,
+      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetNamespaces(ConstString name,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
                     const CompilerDeclContext &parent_decl_ctx,
                     uint32_t name_type_mask,
                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(const RegularExpression &regex,
-                    llvm::function_ref<bool(DIERef ref)> callback) override;
+                    llvm::function_ref<bool(DWARFDIE die)> callback) override;
 
-  void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {}
   void Dump(Stream &s) override;
 
 private:
@@ -79,7 +79,8 @@
 
   llvm::Optional<DIERef> ToDIERef(const DebugNames::Entry &entry);
   bool ProcessEntry(const DebugNames::Entry &entry,
-                    llvm::function_ref<bool(DIERef ref)> callback);
+                    llvm::function_ref<bool(DWARFDIE die)> callback,
+                    llvm::StringRef name);
 
   static void MaybeLogLookupError(llvm::Error error,
                                   const DebugNames::NameIndex &ni,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -10,6 +10,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
+#include "lldb/Core/Module.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
 
@@ -59,10 +60,16 @@
 
 bool DebugNamesDWARFIndex::ProcessEntry(
     const DebugNames::Entry &entry,
-    llvm::function_ref<bool(DIERef ref)> callback) {
-  if (llvm::Optional<DIERef> ref = ToDIERef(entry))
-    return callback(*ref);
-  return true;
+    llvm::function_ref<bool(DWARFDIE die)> callback, llvm::StringRef name) {
+  llvm::Optional<DIERef> ref = ToDIERef(entry);
+  if (!ref)
+    return true;
+  SymbolFileDWARF &dwarf =
+      *llvm::cast<SymbolFileDWARF>(m_module.GetSymbolFile());
+  DWARFDIE die = dwarf.GetDIE(*ref);
+  if (!die)
+    return true;
+  return callback(die);
 }
 
 void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error,
@@ -77,13 +84,13 @@
 }
 
 void DebugNamesDWARFIndex::GetGlobalVariables(
-    ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::Entry &entry :
        m_debug_names_up->equal_range(basename.GetStringRef())) {
     if (entry.tag() != DW_TAG_variable)
       continue;
 
-    if (!ProcessEntry(entry, callback))
+    if (!ProcessEntry(entry, callback, basename.GetStringRef()))
       return;
   }
 
@@ -92,7 +99,7 @@
 
 void DebugNamesDWARFIndex::GetGlobalVariables(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
     for (DebugNames::NameTableEntry nte: ni) {
       if (!regex.Execute(nte.getString()))
@@ -104,7 +111,8 @@
         if (entry_or->tag() != DW_TAG_variable)
           continue;
 
-        if (!ProcessEntry(*entry_or, callback))
+        if (!ProcessEntry(*entry_or, callback,
+                          llvm::StringRef(nte.getString())))
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -115,7 +123,7 @@
 }
 
 void DebugNamesDWARFIndex::GetGlobalVariables(
-    const DWARFUnit &cu, llvm::function_ref<bool(DIERef ref)> callback) {
+    const DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
   uint64_t cu_offset = cu.GetOffset();
   for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
     for (DebugNames::NameTableEntry nte: ni) {
@@ -127,7 +135,8 @@
         if (entry_or->getCUOffset() != cu_offset)
           continue;
 
-        if (!ProcessEntry(*entry_or, callback))
+        if (!ProcessEntry(*entry_or, callback,
+                          llvm::StringRef(nte.getString())))
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -139,7 +148,7 @@
 
 void DebugNamesDWARFIndex::GetCompleteObjCClass(
     ConstString class_name, bool must_be_implementation,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   // Keep a list of incomplete types as fallback for when we don't find the
   // complete type.
   DIEArray incomplete_types;
@@ -160,32 +169,34 @@
       continue;
     }
 
-    // FIXME: We should return DWARFDIEs so we don't have to resolve it twice.
     DWARFDIE die = m_debug_info.GetDIE(*ref);
-    if (!die)
+    if (!die) {
+      ReportInvalidDIERef(*ref, class_name.GetStringRef());
       continue;
+    }
 
     if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) {
       // If we find the complete version we're done.
-      callback(*ref);
+      callback(die);
       return;
     }
     incomplete_types.push_back(*ref);
   }
 
+  auto dierefcallback = DIERefCallback(callback, class_name.GetStringRef());
   for (DIERef ref : incomplete_types)
-    if (!callback(ref))
+    if (!dierefcallback(ref))
       return;
 
   m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, callback);
 }
 
 void DebugNamesDWARFIndex::GetTypes(
-    ConstString name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::Entry &entry :
        m_debug_names_up->equal_range(name.GetStringRef())) {
     if (isType(entry.tag())) {
-      if (!ProcessEntry(entry, callback))
+      if (!ProcessEntry(entry, callback, name.GetStringRef()))
         return;
     }
   }
@@ -195,11 +206,11 @@
 
 void DebugNamesDWARFIndex::GetTypes(
     const DWARFDeclContext &context,
-    llvm::function_ref<bool(DIERef ref)> callback) {
-  for (const DebugNames::Entry &entry :
-       m_debug_names_up->equal_range(context[0].name)) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
+  auto name = context[0].name;
+  for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name)) {
     if (entry.tag() == context[0].tag) {
-      if (!ProcessEntry(entry, callback))
+      if (!ProcessEntry(entry, callback, name))
         return;
     }
   }
@@ -208,11 +219,11 @@
 }
 
 void DebugNamesDWARFIndex::GetNamespaces(
-    ConstString name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::Entry &entry :
        m_debug_names_up->equal_range(name.GetStringRef())) {
     if (entry.tag() == DW_TAG_namespace) {
-      if (!ProcessEntry(entry, callback))
+      if (!ProcessEntry(entry, callback, name.GetStringRef()))
         return;
     }
   }
@@ -249,7 +260,7 @@
 
 void DebugNamesDWARFIndex::GetFunctions(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
     for (DebugNames::NameTableEntry nte: ni) {
       if (!regex.Execute(nte.getString()))
@@ -262,7 +273,8 @@
         if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
           continue;
 
-        if (!ProcessEntry(*entry_or, callback))
+        if (!ProcessEntry(*entry_or, callback,
+                          llvm::StringRef(nte.getString())))
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
@@ -28,32 +28,31 @@
 
   void
   GetGlobalVariables(ConstString basename,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const RegularExpression &regex,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void
   GetGlobalVariables(const DWARFUnit &unit,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetObjCMethods(ConstString class_name,
-                      llvm::function_ref<bool(DIERef ref)> callback) override;
-  void
-  GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
-                       llvm::function_ref<bool(DIERef ref)> callback) override;
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
+  void GetCompleteObjCClass(
+      ConstString class_name, bool must_be_implementation,
+      llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(ConstString name,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetTypes(const DWARFDeclContext &context,
-                llvm::function_ref<bool(DIERef ref)> callback) override;
+                llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetNamespaces(ConstString name,
-                     llvm::function_ref<bool(DIERef ref)> callback) override;
+                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(ConstString name, SymbolFileDWARF &dwarf,
                     const CompilerDeclContext &parent_decl_ctx,
                     uint32_t name_type_mask,
                     llvm::function_ref<bool(DWARFDIE die)> callback) override;
   void GetFunctions(const RegularExpression &regex,
-                    llvm::function_ref<bool(DIERef ref)> callback) override;
+                    llvm::function_ref<bool(DWARFDIE die)> callback) override;
 
-  void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {}
   void Dump(Stream &s) override;
 
 private:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -321,53 +321,59 @@
 }
 
 void ManualDWARFIndex::GetGlobalVariables(
-    ConstString basename, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.Find(basename, callback);
+  m_set.globals.Find(basename,
+                     DIERefCallback(callback, basename.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetGlobalVariables(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.Find(regex, callback);
+  m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
 }
 
 void ManualDWARFIndex::GetGlobalVariables(
-    const DWARFUnit &unit, llvm::function_ref<bool(DIERef ref)> callback) {
+    const DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.FindAllEntriesForUnit(unit, callback);
+  m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
 }
 
 void ManualDWARFIndex::GetObjCMethods(
-    ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.objc_class_selectors.Find(class_name, callback);
+  m_set.objc_class_selectors.Find(
+      class_name, DIERefCallback(callback, class_name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetCompleteObjCClass(
     ConstString class_name, bool must_be_implementation,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.types.Find(class_name, callback);
+  m_set.types.Find(class_name,
+                   DIERefCallback(callback, class_name.GetStringRef()));
 }
 
-void ManualDWARFIndex::GetTypes(ConstString name,
-                                llvm::function_ref<bool(DIERef ref)> callback) {
+void ManualDWARFIndex::GetTypes(
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.types.Find(name, callback);
+  m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
 }
 
-void ManualDWARFIndex::GetTypes(const DWARFDeclContext &context,
-                                llvm::function_ref<bool(DIERef ref)> callback) {
+void ManualDWARFIndex::GetTypes(
+    const DWARFDeclContext &context,
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.types.Find(ConstString(context[0].name), callback);
+  auto name = context[0].name;
+  m_set.types.Find(ConstString(name),
+                   DIERefCallback(callback, llvm::StringRef(name)));
 }
 
 void ManualDWARFIndex::GetNamespaces(
-    ConstString name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
-  m_set.namespaces.Find(name, callback);
+  m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetFunctions(
@@ -377,58 +383,54 @@
   Index();
 
   if (name_type_mask & eFunctionNameTypeFull) {
-    if (!m_set.function_fullnames.Find(name, [&](DIERef die_ref) {
-          DWARFDIE die = dwarf.GetDIE(die_ref);
-          if (!die)
-            return true;
-          if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
-            return true;
-          return callback(die);
-        }))
+    if (!m_set.function_fullnames.Find(
+            name, DIERefCallback(
+                      [&](DWARFDIE die) {
+                        if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
+                                                               die))
+                          return true;
+                        return callback(die);
+                      },
+                      name.GetStringRef())))
       return;
   }
   if (name_type_mask & eFunctionNameTypeBase) {
-    if (!m_set.function_basenames.Find(name, [&](DIERef die_ref) {
-          DWARFDIE die = dwarf.GetDIE(die_ref);
-          if (!die)
-            return true;
-          if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
-            return true;
-          return callback(die);
-        }))
+    if (!m_set.function_basenames.Find(
+            name, DIERefCallback(
+                      [&](DWARFDIE die) {
+                        if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
+                                                               die))
+                          return true;
+                        return callback(die);
+                      },
+                      name.GetStringRef())))
       return;
   }
 
   if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
-    if (!m_set.function_methods.Find(name, [&](DIERef die_ref) {
-          DWARFDIE die = dwarf.GetDIE(die_ref);
-          if (!die)
-            return true;
-          return callback(die);
-        }))
+    if (!m_set.function_methods.Find(
+            name, DIERefCallback(callback, name.GetStringRef())))
       return;
   }
 
   if (name_type_mask & eFunctionNameTypeSelector &&
       !parent_decl_ctx.IsValid()) {
-    if (!m_set.function_selectors.Find(name, [&](DIERef die_ref) {
-          DWARFDIE die = dwarf.GetDIE(die_ref);
-          if (!die)
-            return true;
-          return callback(die);
-        }))
+    if (!m_set.function_selectors.Find(
+            name, DIERefCallback(callback, name.GetStringRef())))
       return;
   }
 }
 
 void ManualDWARFIndex::GetFunctions(
     const RegularExpression &regex,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   Index();
 
-  if (!m_set.function_basenames.Find(regex, callback))
+  if (!m_set.function_basenames.Find(regex,
+                                     DIERefCallback(callback, regex.GetText())))
     return;
-  if (!m_set.function_fullnames.Find(regex, callback))
+  if (!m_set.function_fullnames.Find(regex,
+                                     DIERefCallback(callback, regex.GetText())))
     return;
 }
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -238,7 +238,7 @@
   GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu);
 
   virtual void GetObjCMethods(lldb_private::ConstString class_name,
-                              llvm::function_ref<bool(DIERef ref)> callback);
+                              llvm::function_ref<bool(DWARFDIE die)> callback);
 
   bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu);
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1464,7 +1464,7 @@
 }
 
 void SymbolFileDWARF::GetObjCMethods(
-    ConstString class_name, llvm::function_ref<bool(DIERef ref)> callback) {
+    ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
   m_index->GetObjCMethods(class_name, callback);
 }
 
@@ -2051,17 +2051,11 @@
   uint32_t pruned_idx = original_size;
 
   SymbolContext sc;
-  m_index->GetGlobalVariables(ConstString(basename), [&](DIERef die_ref) {
+  m_index->GetGlobalVariables(ConstString(basename), [&](DWARFDIE die) {
     if (!sc.module_sp)
       sc.module_sp = m_objfile_sp->GetModule();
     assert(sc.module_sp);
 
-    DWARFDIE die = GetDIE(die_ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
-      return true;
-    }
-
     if (die.Tag() != DW_TAG_variable)
       return true;
 
@@ -2123,17 +2117,11 @@
   const uint32_t original_size = variables.GetSize();
 
   SymbolContext sc;
-  m_index->GetGlobalVariables(regex, [&](DIERef die_ref) {
+  m_index->GetGlobalVariables(regex, [&](DWARFDIE die) {
     if (!sc.module_sp)
       sc.module_sp = m_objfile_sp->GetModule();
     assert(sc.module_sp);
 
-    DWARFDIE die = GetDIE(die_ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(die_ref, regex.GetText());
-      return true;
-    }
-
     DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU());
     if (!dwarf_cu)
       return true;
@@ -2292,14 +2280,8 @@
         regex.GetText().str().c_str());
   }
 
-  DWARFDebugInfo &info = DebugInfo();
   llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies;
-  m_index->GetFunctions(regex, [&](DIERef ref) {
-    DWARFDIE die = info.GetDIE(ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(ref, regex.GetText());
-      return true;
-    }
+  m_index->GetFunctions(regex, [&](DWARFDIE die) {
     if (resolved_dies.insert(die.GetDIE()).second)
       ResolveFunction(die, include_inlines, sc_list);
     return true;
@@ -2359,13 +2341,7 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
     return;
 
-  m_index->GetTypes(name, [&](DIERef die_ref) {
-    DWARFDIE die = GetDIE(die_ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
-      return true;
-    }
-
+  m_index->GetTypes(name, [&](DWARFDIE die) {
     if (!DIEInDeclContext(parent_decl_ctx, die))
       return true; // The containing decl contexts don't match
 
@@ -2427,13 +2403,7 @@
   if (!name)
     return;
 
-  m_index->GetTypes(name, [&](DIERef die_ref) {
-    DWARFDIE die = GetDIE(die_ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
-      return true;
-    }
-
+  m_index->GetTypes(name, [&](DWARFDIE die) {
     if (!languages[GetLanguage(*die.GetCU())])
       return true;
 
@@ -2478,13 +2448,7 @@
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
     return namespace_decl_ctx;
 
-  m_index->GetNamespaces(name, [&](DIERef die_ref) {
-    DWARFDIE die = GetDIE(die_ref);
-    if (!die) {
-      m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
-      return true;
-    }
-
+  m_index->GetNamespaces(name, [&](DWARFDIE die) {
     if (!DIEInDeclContext(parent_decl_ctx, die))
       return true; // The containing decl contexts don't match
 
@@ -2650,13 +2614,7 @@
     return type_sp;
 
   m_index->GetCompleteObjCClass(
-      type_name, must_be_implementation, [&](DIERef die_ref) {
-        DWARFDIE type_die = GetDIE(die_ref);
-        if (!type_die) {
-          m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef());
-          return true;
-        }
-
+      type_name, must_be_implementation, [&](DWARFDIE type_die) {
         bool try_resolving_type = false;
 
         // Don't try and resolve the DIE we are looking for with the DIE
@@ -2827,13 +2785,7 @@
         }
       }
 
-      m_index->GetTypes(dwarf_decl_ctx, [&](DIERef die_ref) {
-        DWARFDIE type_die = GetDIE(die_ref);
-        if (!type_die) {
-          m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef());
-          return true;
-        }
-
+      m_index->GetTypes(dwarf_decl_ctx, [&](DWARFDIE type_die) {
         // Make sure type_die's langauge matches the type system we are
         // looking for. We don't want to find a "Foo" type from Java if we
         // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
@@ -3055,12 +3007,7 @@
         sc.comp_unit->SetVariableList(variables);
 
         m_index->GetGlobalVariables(
-            dwarf_cu->GetNonSkeletonUnit(), [&](DIERef die_ref) {
-              DWARFDIE die = GetDIE(die_ref);
-              if (!die) {
-                m_index->ReportInvalidDIERef(die_ref, "");
-                return true;
-              }
+            dwarf_cu->GetNonSkeletonUnit(), [&](DWARFDIE die) {
               VariableSP var_sp(
                   ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
               if (var_sp) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
@@ -32,7 +32,7 @@
   DWARFCompileUnit *GetDWOCompileUnitForHash(uint64_t hash);
 
   void GetObjCMethods(lldb_private::ConstString class_name,
-                      llvm::function_ref<bool(DIERef ref)> callback) override;
+                      llvm::function_ref<bool(DWARFDIE die)> callback) override;
 
   llvm::Expected<lldb_private::TypeSystem &>
   GetTypeSystemForLanguage(lldb::LanguageType language) override;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
@@ -97,7 +97,7 @@
 
 void SymbolFileDWARFDwo::GetObjCMethods(
     lldb_private::ConstString class_name,
-    llvm::function_ref<bool(DIERef ref)> callback) {
+    llvm::function_ref<bool(DWARFDIE die)> callback) {
   GetBaseSymbolFile().GetObjCMethods(class_name, callback);
 }