Skip to content

[lldb][DWARFIndex] Adapt DebugNamesDWARFIndex::ProcessEntry to IterationAction #152025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Michael137
Copy link
Member

Continuation of #151489

@llvmbot llvmbot added the lldb label Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

Continuation of #151489


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

2 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (+35-38)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h (+3-2)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
index 9fe03dc5ba1a7..fa5baf1a0eeb1 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -152,17 +152,17 @@ DWARFDIE DebugNamesDWARFIndex::GetDIE(const DebugNames::Entry &entry) const {
   return DWARFDIE();
 }
 
-bool DebugNamesDWARFIndex::ProcessEntry(
+IterationAction DebugNamesDWARFIndex::ProcessEntry(
     const DebugNames::Entry &entry,
-    llvm::function_ref<bool(DWARFDIE die)> callback) {
+    llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
   DWARFDIE die = GetDIE(entry);
   if (!die)
-    return true;
+    return IterationAction::Continue;
   // Clang used to erroneously emit index entries for declaration DIEs in case
   // when the definition is in a type unit (llvm.org/pr77696).
   if (die.IsStructUnionOrClass() &&
       die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
-    return true;
+    return IterationAction::Continue;
   return callback(die);
 }
 
@@ -185,7 +185,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
     if (entry.tag() != DW_TAG_variable)
       continue;
 
-    if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
+    if (ProcessEntry(entry, callback) == IterationAction::Stop)
       return;
   }
 
@@ -207,7 +207,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
         if (entry_or->tag() != DW_TAG_variable)
           continue;
 
-        if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
+        if (ProcessEntry(*entry_or, callback) == IterationAction::Stop)
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -243,7 +243,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
           continue;
 
         found_entry_for_cu = true;
-        if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
+        if (ProcessEntry(*entry_or, callback) == IterationAction::Stop)
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -358,16 +358,15 @@ void DebugNamesDWARFIndex::GetFullyQualifiedType(
 
     if (!parent_chain) {
       // Fallback: use the base class implementation.
-      if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
-                          return GetFullyQualifiedTypeImpl(context, die,
-                                                           callback);
-                        })))
+      if (ProcessEntry(entry, [&](DWARFDIE die) {
+            return GetFullyQualifiedTypeImpl(context, die, callback);
+          }) == IterationAction::Stop)
         return;
       continue;
     }
 
     if (SameParentChain(parent_names, *parent_chain)) {
-      if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
+      if (ProcessEntry(entry, callback) == IterationAction::Stop)
         return;
     }
   }
@@ -462,7 +461,7 @@ void DebugNamesDWARFIndex::GetTypes(
   for (const DebugNames::Entry &entry :
        m_debug_names_up->equal_range(name.GetStringRef())) {
     if (isType(entry.tag())) {
-      if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
+      if (ProcessEntry(entry, callback) == IterationAction::Stop)
         return;
     }
   }
@@ -476,7 +475,7 @@ void DebugNamesDWARFIndex::GetTypes(
   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, IterationActionAdaptor(callback)))
+      if (ProcessEntry(entry, callback) == IterationAction::Stop)
         return;
     }
   }
@@ -492,7 +491,7 @@ void DebugNamesDWARFIndex::GetNamespaces(
     llvm::dwarf::Tag entry_tag = entry.tag();
     if (entry_tag == DW_TAG_namespace ||
         entry_tag == DW_TAG_imported_declaration) {
-      if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
+      if (ProcessEntry(entry, callback) == IterationAction::Stop)
         return;
     }
   }
@@ -549,21 +548,20 @@ void DebugNamesDWARFIndex::GetTypesWithQuery(
         getParentChain(entry);
     if (!parent_chain) {
       // Fallback: use the base class implementation.
-      if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
-                          return ProcessTypeDIEMatchQuery(query, die, callback);
-                        })))
+      if (ProcessEntry(entry, [&](DWARFDIE die) {
+            return ProcessTypeDIEMatchQuery(query, die, callback);
+          }) == IterationAction::Stop)
         return;
       continue;
     }
 
     if (WithinParentChain(parent_contexts, *parent_chain)) {
-      if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
-                          // After .debug_names filtering still sending to base
-                          // class for further filtering before calling the
-                          // callback.
-                          return ProcessTypeDIEMatchQuery(query, die, callback);
-                        })))
-        // If the callback returns false, we're done.
+      if (ProcessEntry(entry, [&](DWARFDIE die) {
+            // After .debug_names filtering still sending to base
+            // class for further filtering before calling the
+            // callback.
+            return ProcessTypeDIEMatchQuery(query, die, callback);
+          }) == IterationAction::Stop)
         return;
     }
   }
@@ -588,23 +586,22 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents(
           getParentChain(entry);
       if (!parent_chain) {
         // Fallback: use the base class implementation.
-        if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
-                            return ProcessNamespaceDieMatchParents(
-                                parent_decl_ctx, die, callback);
-                          })))
+        if (ProcessEntry(entry, [&](DWARFDIE die) {
+              return ProcessNamespaceDieMatchParents(parent_decl_ctx, die,
+                                                     callback);
+            }) == IterationAction::Stop)
           return;
         continue;
       }
 
       if (WithinParentChain(parent_named_contexts, *parent_chain)) {
-        if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
-                            // After .debug_names filtering still sending to
-                            // base class for further filtering before calling
-                            // the callback.
-                            return ProcessNamespaceDieMatchParents(
-                                parent_decl_ctx, die, callback);
-                          })))
-          // If the callback returns false, we're done.
+        if (ProcessEntry(entry, [&](DWARFDIE die) {
+              // After .debug_names filtering still sending to
+              // base class for further filtering before calling
+              // the callback.
+              return ProcessNamespaceDieMatchParents(parent_decl_ctx, die,
+                                                     callback);
+            }) == IterationAction::Stop)
           return;
       }
     }
@@ -653,7 +650,7 @@ void DebugNamesDWARFIndex::GetFunctions(
         if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
           continue;
 
-        if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
+        if (ProcessEntry(*entry_or, callback) == IterationAction::Stop)
           return;
       }
       MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
index 0587f0401f718..5ebd4f6deb5d4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
@@ -122,8 +122,9 @@ class DebugNamesDWARFIndex : public DWARFIndex {
   std::optional<DWARFTypeUnit *>
   GetForeignTypeUnit(const DebugNames::Entry &entry) const;
 
-  bool ProcessEntry(const DebugNames::Entry &entry,
-                    llvm::function_ref<bool(DWARFDIE die)> callback);
+  IterationAction
+  ProcessEntry(const DebugNames::Entry &entry,
+               llvm::function_ref<IterationAction(DWARFDIE die)> callback);
 
   /// Returns true if `parent_entries` have identical names to `parent_names`.
   bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,

@Michael137 Michael137 merged commit d276569 into llvm:main Aug 4, 2025
11 checks passed
@Michael137 Michael137 deleted the lldb/dwarf-index-iteration-action-debug-names branch August 4, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants