llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

<details>
<summary>Changes</summary>

Continuation of https://github.com/llvm/llvm-project/pull/151489

---
Full diff: https://github.com/llvm/llvm-project/pull/152001.diff


7 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp (+19-26) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h (+3-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp (+5-4) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h (+9-7) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp (+33-41) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (+12-8) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h (+6-5) 


``````````diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
index 86de1b5c7859f..a5f83e137eb83 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
@@ -118,11 +118,11 @@ HasImplementationFlag(const 
llvm::AppleAcceleratorTable::Entry &entry) {
          (*Flags & llvm::dwarf::AcceleratorTable::DW_FLAG_type_implementation);
 }
 
-void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table,
-                                llvm::StringRef name,
-                                llvm::function_ref<bool(DWARFDIE die)> 
callback,
-                                std::optional<dw_tag_t> search_for_tag,
-                                std::optional<uint32_t> search_for_qualhash) {
+void AppleDWARFIndex::SearchFor(
+    const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
+    llvm::function_ref<IterationAction(DWARFDIE die)> callback,
+    std::optional<dw_tag_t> search_for_tag,
+    std::optional<uint32_t> search_for_qualhash) {
   auto converted_cb = DIERefCallback(callback, name);
   for (const auto &entry : table.equal_range(name)) {
     if (search_for_qualhash &&
@@ -130,7 +130,7 @@ void AppleDWARFIndex::SearchFor(const 
llvm::AppleAcceleratorTable &table,
       continue;
     if (search_for_tag && !EntryHasMatchingTag(entry, *search_for_tag))
       continue;
-    if (!converted_cb(entry))
+    if (converted_cb(entry) == IterationAction::Stop)
       break;
   }
 }
@@ -140,7 +140,7 @@ void AppleDWARFIndex::GetGlobalVariables(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   if (!m_apple_names_up)
     return;
-  SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback));
+  SearchFor(*m_apple_names_up, basename, callback);
 }
 
 void AppleDWARFIndex::GetGlobalVariables(
@@ -149,14 +149,12 @@ void AppleDWARFIndex::GetGlobalVariables(
   if (!m_apple_names_up)
     return;
 
-  auto adataped_cb = IterationActionAdaptor(callback);
-  DIERefCallbackImpl converted_cb =
-      DIERefCallback(adataped_cb, regex.GetText());
+  DIERefCallbackImpl converted_cb = DIERefCallback(callback, regex.GetText());
 
   for (const auto &entry : m_apple_names_up->entries())
     if (std::optional<llvm::StringRef> name = entry.readName();
         name && Mangled(*name).NameMatches(regex))
-      if (!converted_cb(entry.BaseEntry))
+      if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
         return;
 }
 
@@ -172,11 +170,10 @@ void AppleDWARFIndex::GetGlobalVariables(
     return val.has_value() && *val >= lower_bound && *val < upper_bound;
   };
 
-  auto adataped_cb = IterationActionAdaptor(callback);
-  DIERefCallbackImpl converted_cb = DIERefCallback(adataped_cb);
+  DIERefCallbackImpl converted_cb = DIERefCallback(callback);
   for (auto entry : m_apple_names_up->entries()) {
     if (is_in_range(entry.BaseEntry.getDIESectionOffset()))
-      if (!converted_cb(entry.BaseEntry))
+      if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
         return;
   }
 }
@@ -186,7 +183,7 @@ void AppleDWARFIndex::GetObjCMethods(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   if (!m_apple_objc_up)
     return;
-  SearchFor(*m_apple_objc_up, class_name, IterationActionAdaptor(callback));
+  SearchFor(*m_apple_objc_up, class_name, callback);
 }
 
 void AppleDWARFIndex::GetCompleteObjCClass(
@@ -196,8 +193,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
     return;
 
   llvm::SmallVector<DIERef> decl_dies;
-  auto adapted_cb = IterationActionAdaptor(callback);
-  auto converted_cb = DIERefCallback(adapted_cb, class_name);
+  auto converted_cb = DIERefCallback(callback, class_name);
 
   for (const auto &entry : m_apple_types_up->equal_range(class_name)) {
     if (HasImplementationFlag(entry)) {
@@ -212,7 +208,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
   if (must_be_implementation)
     return;
   for (DIERef ref : decl_dies)
-    if (!converted_cb(ref))
+    if (converted_cb(ref) == IterationAction::Stop)
       return;
 }
 
@@ -221,7 +217,7 @@ void AppleDWARFIndex::GetTypes(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   if (!m_apple_types_up)
     return;
-  SearchFor(*m_apple_types_up, name, IterationActionAdaptor(callback));
+  SearchFor(*m_apple_types_up, name, callback);
 }
 
 void AppleDWARFIndex::GetTypes(
@@ -244,16 +240,14 @@ void AppleDWARFIndex::GetTypes(
         llvm::djbHash(context.GetQualifiedName());
     if (log)
       m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
-    SearchFor(*m_apple_types_up, expected_name,
-              IterationActionAdaptor(callback), expected_tag,
+    SearchFor(*m_apple_types_up, expected_name, callback, expected_tag,
               expected_qualname_hash);
     return;
   }
 
   // Historically, if there are no tags, we also ignore qual_hash (why?)
   if (!entries_have_tag) {
-    SearchFor(*m_apple_names_up, expected_name,
-              IterationActionAdaptor(callback));
+    SearchFor(*m_apple_names_up, expected_name, callback);
     return;
   }
 
@@ -272,8 +266,7 @@ void AppleDWARFIndex::GetTypes(
   if (log)
     m_module.LogMessage(log, "FindByNameAndTag()");
   const dw_tag_t expected_tag = context[0].tag;
-  SearchFor(*m_apple_types_up, expected_name, IterationActionAdaptor(callback),
-            expected_tag);
+  SearchFor(*m_apple_types_up, expected_name, callback, expected_tag);
 }
 
 void AppleDWARFIndex::GetNamespaces(
@@ -281,7 +274,7 @@ void AppleDWARFIndex::GetNamespaces(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   if (!m_apple_namespaces_up)
     return;
-  SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback));
+  SearchFor(*m_apple_namespaces_up, name, callback);
 }
 
 void AppleDWARFIndex::GetFunctions(
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h 
b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
index a8ccb6f93d1ca..6da0cce565a29 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
@@ -94,9 +94,10 @@ class AppleDWARFIndex : public DWARFIndex {
   /// each match. If `search_for_tag` is provided, ignore entries whose tag is
   /// not `search_for_tag`. If `search_for_qualhash` is provided, ignore 
entries
   /// whose qualified name hash does not match `search_for_qualhash`.
-  /// If `callback` returns false for an entry, the search is interrupted.
+  /// If `callback` returns `IterationAction::Stop` for an entry, the search is
+  /// interrupted.
   void SearchFor(const llvm::AppleAcceleratorTable &table, llvm::StringRef 
name,
-                 llvm::function_ref<bool(DWARFDIE die)> callback,
+                 llvm::function_ref<IterationAction(DWARFDIE die)> callback,
                  std::optional<dw_tag_t> search_for_tag = std::nullopt,
                  std::optional<uint32_t> search_for_qualhash = std::nullopt);
 };
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index acbbaeb52bc69..64a8005308454 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -84,21 +84,22 @@ IterationAction DWARFIndex::ProcessFunctionDIE(
 }
 
 DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
-    const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,
+    const DWARFIndex &index,
+    llvm::function_ref<IterationAction(DWARFDIE die)> callback,
     llvm::StringRef name)
     : m_index(index),
       m_dwarf(*llvm::cast<SymbolFileDWARF>(
           index.m_module.GetSymbolFile()->GetBackingSymbolFile())),
       m_callback(callback), m_name(name) {}
 
-bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
+IterationAction 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;
+  return IterationAction::Continue;
 }
 
-bool DWARFIndex::DIERefCallbackImpl::operator()(
+IterationAction DWARFIndex::DIERefCallbackImpl::operator()(
     const llvm::AppleAcceleratorTable::Entry &entry) const {
   return this->operator()(DIERef(std::nullopt, DIERef::Section::DebugInfo,
                                  *entry.getDIESectionOffset()));
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
index 710bb4e826882..7b2551647935d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
@@ -110,20 +110,22 @@ class DWARFIndex {
 
   class DIERefCallbackImpl {
   public:
-    DIERefCallbackImpl(const DWARFIndex &index,
-                       llvm::function_ref<bool(DWARFDIE die)> callback,
-                       llvm::StringRef name);
-    bool operator()(DIERef ref) const;
-    bool operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;
+    DIERefCallbackImpl(
+        const DWARFIndex &index,
+        llvm::function_ref<IterationAction(DWARFDIE die)> callback,
+        llvm::StringRef name);
+    IterationAction operator()(DIERef ref) const;
+    IterationAction
+    operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;
 
   private:
     const DWARFIndex &m_index;
     SymbolFileDWARF &m_dwarf;
-    const llvm::function_ref<bool(DWARFDIE die)> m_callback;
+    const llvm::function_ref<IterationAction(DWARFDIE die)> m_callback;
     const llvm::StringRef m_name;
   };
   DIERefCallbackImpl
-  DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback,
+  DIERefCallback(llvm::function_ref<IterationAction(DWARFDIE die)> callback,
                  llvm::StringRef name = {}) const {
     return DIERefCallbackImpl(*this, callback, name);
   }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index 94bdd795cb12b..d90108f687f84 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -417,24 +417,22 @@ void ManualDWARFIndex::GetGlobalVariables(
     ConstString basename,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.Find(basename, DIERefCallback(IterationActionAdaptor(callback),
-                                              basename.GetStringRef()));
+  m_set.globals.Find(basename,
+                     DIERefCallback(callback, basename.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetGlobalVariables(
     const RegularExpression &regex,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.Find(
-      regex, DIERefCallback(IterationActionAdaptor(callback), 
regex.GetText()));
+  m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
 }
 
 void ManualDWARFIndex::GetGlobalVariables(
     DWARFUnit &unit,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.globals.FindAllEntriesForUnit(
-      unit, DIERefCallback(IterationActionAdaptor(callback)));
+  m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
 }
 
 void ManualDWARFIndex::GetObjCMethods(
@@ -442,24 +440,22 @@ void ManualDWARFIndex::GetObjCMethods(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
   m_set.objc_class_selectors.Find(
-      class_name, DIERefCallback(IterationActionAdaptor(callback),
-                                 class_name.GetStringRef()));
+      class_name, DIERefCallback(callback, class_name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetCompleteObjCClass(
     ConstString class_name, bool must_be_implementation,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.types.Find(class_name, DIERefCallback(IterationActionAdaptor(callback),
-                                              class_name.GetStringRef()));
+  m_set.types.Find(class_name,
+                   DIERefCallback(callback, class_name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetTypes(
     ConstString name,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.types.Find(name, DIERefCallback(IterationActionAdaptor(callback),
-                                        name.GetStringRef()));
+  m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetTypes(
@@ -467,17 +463,15 @@ void ManualDWARFIndex::GetTypes(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
   auto name = context[0].name;
-  m_set.types.Find(
-      ConstString(name),
-      DIERefCallback(IterationActionAdaptor(callback), llvm::StringRef(name)));
+  m_set.types.Find(ConstString(name),
+                   DIERefCallback(callback, llvm::StringRef(name)));
 }
 
 void ManualDWARFIndex::GetNamespaces(
     ConstString name,
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
-  m_set.namespaces.Find(name, DIERefCallback(IterationActionAdaptor(callback),
-                                             name.GetStringRef()));
+  m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
 }
 
 void ManualDWARFIndex::GetFunctions(
@@ -490,39 +484,39 @@ void ManualDWARFIndex::GetFunctions(
 
   if (name_type_mask & eFunctionNameTypeFull) {
     if (!m_set.function_fullnames.Find(
-            name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
-                                   if (!SymbolFileDWARF::DIEInDeclContext(
-                                           parent_decl_ctx, die))
-                                     return IterationAction::Continue;
-                                   return callback(die);
-                                 }),
-                                 name.GetStringRef())))
+            name, DIERefCallback(
+                      [&](DWARFDIE die) {
+                        if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
+                                                               die))
+                          return IterationAction::Continue;
+                        return callback(die);
+                      },
+                      name.GetStringRef())))
       return;
   }
   if (name_type_mask & eFunctionNameTypeBase) {
     if (!m_set.function_basenames.Find(
-            name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
-                                   if (!SymbolFileDWARF::DIEInDeclContext(
-                                           parent_decl_ctx, die))
-                                     return IterationAction::Continue;
-                                   return callback(die);
-                                 }),
-                                 name.GetStringRef())))
+            name, DIERefCallback(
+                      [&](DWARFDIE die) {
+                        if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
+                                                               die))
+                          return IterationAction::Continue;
+                        return callback(die);
+                      },
+                      name.GetStringRef())))
       return;
   }
 
   if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
     if (!m_set.function_methods.Find(
-            name, DIERefCallback(IterationActionAdaptor(callback),
-                                 name.GetStringRef())))
+            name, DIERefCallback(callback, name.GetStringRef())))
       return;
   }
 
   if (name_type_mask & eFunctionNameTypeSelector &&
       !parent_decl_ctx.IsValid()) {
     if (!m_set.function_selectors.Find(
-            name, DIERefCallback(IterationActionAdaptor(callback),
-                                 name.GetStringRef())))
+            name, DIERefCallback(callback, name.GetStringRef())))
       return;
   }
 }
@@ -532,13 +526,11 @@ void ManualDWARFIndex::GetFunctions(
     llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   Index();
 
-  if (!m_set.function_basenames.Find(
-          regex,
-          DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
+  if (!m_set.function_basenames.Find(regex,
+                                     DIERefCallback(callback, 
regex.GetText())))
     return;
-  if (!m_set.function_fullnames.Find(
-          regex,
-          DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
+  if (!m_set.function_fullnames.Find(regex,
+                                     DIERefCallback(callback, 
regex.GetText())))
     return;
 }
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
index 44d90648700cf..b34fda5740924 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StreamString.h"
+#include "lldb/lldb-private-enumerations.h"
 #include <optional>
 
 using namespace lldb;
@@ -31,26 +32,29 @@ void NameToDIE::Insert(ConstString name, const DIERef 
&die_ref) {
   m_map.Append(name, die_ref);
 }
 
-bool NameToDIE::Find(ConstString name,
-                     llvm::function_ref<bool(DIERef ref)> callback) const {
+bool NameToDIE::Find(
+    ConstString name,
+    llvm::function_ref<IterationAction(DIERef ref)> callback) const {
   for (const auto &entry : m_map.equal_range(name))
-    if (!callback(entry.value))
+    if (callback(entry.value) == IterationAction::Stop)
       return false;
   return true;
 }
 
-bool NameToDIE::Find(const RegularExpression &regex,
-                     llvm::function_ref<bool(DIERef ref)> callback) const {
+bool NameToDIE::Find(
+    const RegularExpression &regex,
+    llvm::function_ref<IterationAction(DIERef ref)> callback) const {
   for (const auto &entry : m_map)
     if (regex.Execute(entry.cstring.GetCString())) {
-      if (!callback(entry.value))
+      if (callback(entry.value) == IterationAction::Stop)
         return false;
     }
   return true;
 }
 
 void NameToDIE::FindAllEntriesForUnit(
-    DWARFUnit &s_unit, llvm::function_ref<bool(DIERef ref)> callback) const {
+    DWARFUnit &s_unit,
+    llvm::function_ref<IterationAction(DIERef ref)> callback) const {
   const DWARFUnit &ns_unit = s_unit.GetNonSkeletonUnit();
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
@@ -59,7 +63,7 @@ void NameToDIE::FindAllEntriesForUnit(
         ns_unit.GetDebugSection() == die_ref.section() &&
         ns_unit.GetOffset() <= die_ref.die_offset() &&
         die_ref.die_offset() < ns_unit.GetNextUnitOffset()) {
-      if (!callback(die_ref))
+      if (callback(die_ref) == IterationAction::Stop)
         return;
     }
   }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h 
b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
index 90eac1fa37338..9f9b631f178ee 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
@@ -15,6 +15,7 @@
 #include "lldb/Core/UniqueCStringMap.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/lldb-defines.h"
+#include "lldb/lldb-private-enumerations.h"
 
 namespace lldb_private::plugin {
 namespace dwarf {
@@ -35,15 +36,15 @@ class NameToDIE {
   void Finalize();
 
   bool Find(ConstString name,
-            llvm::function_ref<bool(DIERef ref)> callback) const;
+            llvm::function_ref<IterationAction(DIERef ref)> callback) const;
 
   bool Find(const RegularExpression &regex,
-            llvm::function_ref<bool(DIERef ref)> callback) const;
+            llvm::function_ref<IterationAction(DIERef ref)> callback) const;
 
   /// \a unit must be the skeleton unit if possible, not GetNonSkeletonUnit().
-  void
-  FindAllEntriesForUnit(DWARFUnit &unit,
-                        llvm::function_ref<bool(DIERef ref)> callback) const;
+  void FindAllEntriesForUnit(
+      DWARFUnit &unit,
+      llvm::function_ref<IterationAction(DIERef ref)> callback) const;
 
   void
   ForEach(std::function<bool(ConstString name, const DIERef &die_ref)> const

``````````

</details>


https://github.com/llvm/llvm-project/pull/152001
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to