[Lldb-commits] [lldb] [lldb][DWARFIndex][NFC] Change GetFunctions return type to IterationAction (PR #151489)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 31 03:32:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Michael Buch (Michael137)
<details>
<summary>Changes</summary>
The ultimate goal is to replace the return types of all the `DWARFIndex` callbacks to `IterationAction`. To reduce the blast radius and do this incrementally I'm doing this for `GetFunctions` only here. I added a `IterationActionAdaptor` helper (that will ultimately get removed once all APIs have been migrated) to avoid having to change too many other APIs that `GetFunctions` interacts with.
---
Full diff: https://github.com/llvm/llvm-project/pull/151489.diff
9 Files Affected:
- (modified) lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp (+6-4)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h (+7-6)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp (+7-6)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h (+26-5)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (+10-9)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h (+7-6)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp (+27-24)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h (+7-6)
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+4-3)
``````````diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
index 4bfbb4d81f5da..9762ead3273da 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Symbol/Function.h"
+#include "lldb/lldb-private-enumerations.h"
#include "llvm/Support/DJB.h"
using namespace lldb;
@@ -275,7 +276,7 @@ void AppleDWARFIndex::GetNamespaces(
void AppleDWARFIndex::GetFunctions(
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_names_up)
return;
@@ -288,15 +289,16 @@ void AppleDWARFIndex::GetFunctions(
ReportInvalidDIERef(die_ref, name);
continue;
}
- if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx, callback))
+ if (ProcessFunctionDIE(lookup_info, die, parent_decl_ctx, callback) ==
+ IterationAction::Stop)
return;
}
}
void AppleDWARFIndex::GetFunctions(
const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
- return GetGlobalVariables(regex, callback);
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
+ return GetGlobalVariables(regex, IterationActionAdaptor(callback));
}
void AppleDWARFIndex::Dump(Stream &s) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
index 73de75b583bd4..c0f0eb646ee98 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
@@ -61,12 +61,13 @@ class AppleDWARFIndex : public DWARFIndex {
llvm::function_ref<bool(DWARFDIE die)> callback) override;
void GetNamespaces(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const Module::LookupInfo &lookup_info,
- SymbolFileDWARF &dwarf,
- const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
+ const CompilerDeclContext &parent_decl_ctx,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const RegularExpression ®ex,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void Dump(Stream &s) override;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index 30c890d6d0138..a8065061fdf21 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -16,6 +16,7 @@
#include "lldb/Core/Mangled.h"
#include "lldb/Core/Module.h"
#include "lldb/Target/Language.h"
+#include "lldb/lldb-private-enumerations.h"
using namespace lldb_private;
using namespace lldb;
@@ -23,10 +24,10 @@ using namespace lldb_private::plugin::dwarf;
DWARFIndex::~DWARFIndex() = default;
-bool DWARFIndex::ProcessFunctionDIE(
+IterationAction DWARFIndex::ProcessFunctionDIE(
const Module::LookupInfo &lookup_info, DWARFDIE die,
const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
llvm::StringRef name = lookup_info.GetLookupName().GetStringRef();
FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
@@ -43,7 +44,7 @@ bool DWARFIndex::ProcessFunctionDIE(
if (!lookup_info.NameMatchesLookupInfo(name_to_match_against,
lookup_info.GetLanguageType()))
- return true;
+ return IterationAction::Continue;
}
// Exit early if we're searching exclusively for methods or selectors and
@@ -51,12 +52,12 @@ bool DWARFIndex::ProcessFunctionDIE(
uint32_t looking_for_nonmethods =
name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector);
if (!looking_for_nonmethods && parent_decl_ctx.IsValid())
- return true;
+ return IterationAction::Continue;
// Otherwise, we need to also check that the context matches. If it does not
// match, we do nothing.
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
- return true;
+ return IterationAction::Continue;
// In case of a full match, we just insert everything we find.
if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)
@@ -79,7 +80,7 @@ bool DWARFIndex::ProcessFunctionDIE(
return callback(die);
}
- return true;
+ return IterationAction::Continue;
}
DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
index 15d85033434e7..3578824e720fb 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
@@ -16,6 +16,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Target/Statistics.h"
+#include "lldb/lldb-private-enumerations.h"
namespace lldb_private::plugin {
namespace dwarf {
@@ -82,10 +83,10 @@ class DWARFIndex {
virtual void
GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
virtual void
GetFunctions(const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
virtual void Dump(Stream &s) = 0;
@@ -101,9 +102,10 @@ class DWARFIndex {
/// the function given by "die" matches search criteria given by
/// "parent_decl_ctx" and "name_type_mask", it calls the callback with the
/// given die.
- bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DWARFDIE die,
- const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback);
+ IterationAction ProcessFunctionDIE(
+ const Module::LookupInfo &lookup_info, DWARFDIE die,
+ const CompilerDeclContext &parent_decl_ctx,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback);
class DIERefCallbackImpl {
public:
@@ -140,6 +142,25 @@ class DWARFIndex {
bool ProcessNamespaceDieMatchParents(
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die,
llvm::function_ref<bool(DWARFDIE die)> callback);
+
+ /// Helper to convert callbacks that return an \c IterationAction
+ /// to a callback that returns a \c bool, where \c true indicates
+ /// we should continue iterating. This will be used to incrementally
+ /// migrate the callbacks to return an \c IterationAction.
+ ///
+ /// FIXME: remove once all callbacks in the DWARFIndex APIs return
+ /// IterationAction.
+ struct IterationActionAdaptor {
+ IterationActionAdaptor(
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback)
+ : m_callback_ref(callback) {}
+
+ bool operator()(DWARFDIE die) {
+ return m_callback_ref(std::move(die)) == IterationAction::Continue;
+ }
+
+ llvm::function_ref<IterationAction(DWARFDIE die)> m_callback_ref;
+ };
};
} // namespace dwarf
} // namespace lldb_private::plugin
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
index ff1a76b1dd1dc..3ae9fcc70893b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -14,6 +14,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Stream.h"
+#include "lldb/lldb-private-enumerations.h"
#include "llvm/ADT/Sequence.h"
#include <optional>
@@ -607,7 +608,7 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents(
void DebugNamesDWARFIndex::GetFunctions(
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
ConstString name = lookup_info.GetLookupName();
std::set<DWARFDebugInfoEntry *> seen;
for (const DebugNames::Entry &entry :
@@ -617,12 +618,12 @@ void DebugNamesDWARFIndex::GetFunctions(
continue;
if (DWARFDIE die = GetDIE(entry)) {
- if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx,
- [&](DWARFDIE die) {
- if (!seen.insert(die.GetDIE()).second)
- return true;
- return callback(die);
- }))
+ if (ProcessFunctionDIE(lookup_info, die, parent_decl_ctx,
+ [&](DWARFDIE die) {
+ if (!seen.insert(die.GetDIE()).second)
+ return IterationAction::Continue;
+ return callback(die);
+ }) == IterationAction::Stop)
return;
}
}
@@ -632,7 +633,7 @@ void DebugNamesDWARFIndex::GetFunctions(
void DebugNamesDWARFIndex::GetFunctions(
const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
for (DebugNames::NameTableEntry nte: ni) {
if (!regex.Execute(nte.getString()))
@@ -645,7 +646,7 @@ void DebugNamesDWARFIndex::GetFunctions(
if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
continue;
- if (!ProcessEntry(*entry_or, callback))
+ if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
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 ab6cde12623f6..210591904e419 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
@@ -58,12 +58,13 @@ class DebugNamesDWARFIndex : public DWARFIndex {
void GetNamespacesWithParents(
ConstString name, const CompilerDeclContext &parent_decl_ctx,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const Module::LookupInfo &lookup_info,
- SymbolFileDWARF &dwarf,
- const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
+ const CompilerDeclContext &parent_decl_ctx,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const RegularExpression ®ex,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void Dump(Stream &s) override;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index c858ce2161384..f96ac7e8793e4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -21,6 +21,7 @@
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/Timer.h"
+#include "lldb/lldb-private-enumerations.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ThreadPool.h"
#include <atomic>
@@ -471,60 +472,62 @@ void ManualDWARFIndex::GetNamespaces(
void ManualDWARFIndex::GetFunctions(
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
ConstString name = lookup_info.GetLookupName();
FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
if (name_type_mask & eFunctionNameTypeFull) {
if (!m_set.function_fullnames.Find(
- name, DIERefCallback(
- [&](DWARFDIE die) {
- if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
- die))
- return true;
- return callback(die);
- },
- name.GetStringRef())))
+ name, DIERefCallback(IterationActionAdaptor([&](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(
- [&](DWARFDIE die) {
- if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
- die))
- return true;
- return callback(die);
- },
- name.GetStringRef())))
+ name, DIERefCallback(IterationActionAdaptor([&](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(callback, name.GetStringRef())))
+ name, DIERefCallback(IterationActionAdaptor(callback),
+ name.GetStringRef())))
return;
}
if (name_type_mask & eFunctionNameTypeSelector &&
!parent_decl_ctx.IsValid()) {
if (!m_set.function_selectors.Find(
- name, DIERefCallback(callback, name.GetStringRef())))
+ name, DIERefCallback(IterationActionAdaptor(callback),
+ name.GetStringRef())))
return;
}
}
void ManualDWARFIndex::GetFunctions(
const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) {
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
- if (!m_set.function_basenames.Find(regex,
- DIERefCallback(callback, regex.GetText())))
+ if (!m_set.function_basenames.Find(
+ regex,
+ DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
return;
- if (!m_set.function_fullnames.Find(regex,
- DIERefCallback(callback, regex.GetText())))
+ if (!m_set.function_fullnames.Find(
+ regex,
+ DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
return;
}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
index 04627b0ad91e6..5685ba456f423 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
@@ -50,12 +50,13 @@ class ManualDWARFIndex : public DWARFIndex {
llvm::function_ref<bool(DWARFDIE die)> callback) override;
void GetNamespaces(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const Module::LookupInfo &lookup_info,
- SymbolFileDWARF &dwarf,
- const CompilerDeclContext &parent_decl_ctx,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
- void GetFunctions(const RegularExpression ®ex,
- llvm::function_ref<bool(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
+ const CompilerDeclContext &parent_decl_ctx,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
+ void GetFunctions(
+ const RegularExpression ®ex,
+ llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void Dump(Stream &s) override;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 41ab8d1b75b34..2c3f050c5c12d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -74,6 +74,7 @@
#include "ManualDWARFIndex.h"
#include "SymbolFileDWARFDebugMap.h"
#include "SymbolFileDWARFDwo.h"
+#include "lldb/lldb-private-enumerations.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
@@ -2539,7 +2540,7 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
m_index->GetFunctions(lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
if (resolved_dies.insert(die.GetDIE()).second)
ResolveFunction(die, include_inlines, sc_list);
- return true;
+ return IterationAction::Continue;
});
// With -gsimple-template-names, a templated type's DW_AT_name will not
// contain the template parameters. Try again stripping '<' and anything
@@ -2556,7 +2557,7 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
[&](DWARFDIE die) {
if (resolved_dies.insert(die.GetDIE()).second)
ResolveFunction(die, include_inlines, sc_list);
- return true;
+ return IterationAction::Continue;
});
}
}
@@ -2592,7 +2593,7 @@ void SymbolFileDWARF::FindFunctions(const RegularExpression ®ex,
m_index->GetFunctions(regex, [&](DWARFDIE die) {
if (resolved_dies.insert(die.GetDIE()).second)
ResolveFunction(die, include_inlines, sc_list);
- return true;
+ return IterationAction::Continue;
});
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/151489
More information about the lldb-commits
mailing list