OSDN Git Service

[nfc] [lldb] DWARF callbacks: DIERef -> DWARFDIE
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 22 Apr 2020 14:46:29 +0000 (16:46 +0200)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 22 Apr 2020 15:11:50 +0000 (17:11 +0200)
Pavel Labath wrote in D73206:
The internal representation of DebugNames and Apple indexes is fixed by
the relevant (pseudo-)standards, so we can't really change it. The
question is how to efficiently (and cleanly) convert from the internal
representation to some common thing. The conversion from AppleIndex to
DIERef is trivial (which is not surprising as it was the first and the
overall design was optimized for that). With debug_names, the situation
gets more tricky. The internal representation of debug_names uses
CU-relative DIE offsets, but DIERef wants an absolute offset. That means
the index has to do more work to produce the common representation. And
it needs to do that for all results, even though a lot of the index
users are really interested only in a single entry. With the switch to
user_id_t, _all_ indexes would have to do some extra work to encode it,
only for their users to have to immediately decode it back. Having
a iterator/callback based api would allow us to minimize the impact of
that, as it would only need to happen for the entries that are really
used. And /I think/ we could make it interface returns DWARFDies
directly, and each index converts to that using the most direct approach
available.

Jan Kratochvil:
It also makes all the callers shorter as they no longer need to fetch
DWARFDIE from DIERef (and handling if not found by ReportInvalidDIERef)
but the callers are already served DWARFDIE which they need.
In some cases the DWARFDIE had to be fetched both by callee (DWARFIndex
implementation) and caller.

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

13 files changed:
lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h

index ad34a75..33ab11a 100644 (file)
@@ -53,59 +53,69 @@ std::unique_ptr<AppleDWARFIndex> AppleDWARFIndex::Create(
 }
 
 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 @@ void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context,
     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 @@ void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context,
 
     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(
 
 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) {
index fcb02a3..a7032f5 100644 (file)
@@ -34,32 +34,31 @@ public:
 
   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:
index da7cb3b..1540bdb 100644 (file)
@@ -2013,11 +2013,8 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
     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;
         });
 
index ab3fd1f..683033d 100644 (file)
@@ -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,24 @@ bool DWARFIndex::ProcessFunctionDIE(
 
   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 {
+  if (DWARFDIE die = m_dwarf.GetDIE(ref))
+    return m_callback(die);
+  m_index.ReportInvalidDIERef(ref, m_name);
+  return true;
+}
+
+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());
+}
index 2181b67..ecf82a9 100644 (file)
@@ -29,35 +29,36 @@ public:
   /// 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,27 @@ protected:
                           const CompilerDeclContext &parent_decl_ctx,
                           uint32_t name_type_mask,
                           llvm::function_ref<bool(DWARFDIE die)> callback);
+
+  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
 
index 23e9b0b..cb3e662 100644 (file)
@@ -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 @@ DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) {
 
 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::MaybeLogLookupError(llvm::Error error,
 }
 
 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(
 
 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 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
         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(
 }
 
 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 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
         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::GetGlobalVariables(
 
 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 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
       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(
 
 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::GetTypes(
 }
 
 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(
 
 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 @@ void DebugNamesDWARFIndex::GetFunctions(
         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());
index 204007b..5d041c3 100644 (file)
@@ -27,32 +27,32 @@ public:
 
   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 @@ private:
 
   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,
index 3fe38e7..f405a21 100644 (file)
@@ -321,53 +321,59 @@ void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit,
 }
 
 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 @@ void ManualDWARFIndex::GetFunctions(
   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;
 }
 
index 72a5c8f..baff989 100644 (file)
@@ -28,32 +28,31 @@ public:
 
   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:
index b13331c..5eebc96 100644 (file)
@@ -1464,7 +1464,7 @@ SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) {
 }
 
 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 @@ void SymbolFileDWARF::FindGlobalVariables(
   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 @@ void SymbolFileDWARF::FindGlobalVariables(const RegularExpression &regex,
   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 @@ void SymbolFileDWARF::FindFunctions(const RegularExpression &regex,
         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 @@ void SymbolFileDWARF::FindTypes(
   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 @@ void SymbolFileDWARF::FindTypes(
   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 @@ SymbolFileDWARF::FindNamespace(ConstString name,
   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 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
     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 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
         }
       }
 
-      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 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) {
         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) {
index 255fc90..de81145 100644 (file)
@@ -238,7 +238,7 @@ public:
   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);
 
index 5b23202..3aaa7d3 100644 (file)
@@ -97,7 +97,7 @@ SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() {
 
 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);
 }
 
index d43579e..93538aa 100644 (file)
@@ -32,7 +32,7 @@ public:
   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;