-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[lldb][DWARFIndex][NFC] Change GetFunctions return type to IterationAction #151489
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
[lldb][DWARFIndex][NFC] Change GetFunctions return type to IterationAction #151489
Conversation
…ction 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.
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesThe ultimate goal is to replace the return types of all the Full diff: https://github.com/llvm/llvm-project/pull/151489.diff 9 Files Affected:
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;
});
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM! When I was working on the accelerator tables in the past, this API really bothered me, so I'll be happy to see it changed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wunderbar
…bles APIs to use IterationAction (#151668) Continuation from llvm/llvm-project#151489
…Action (#151839) Continuation of llvm/llvm-project#151489
…tionAction (#151992) Continuation of llvm/llvm-project#151489
…ationAction (#152001) Continuation of llvm/llvm-project#151489
…y to IterationAction (#152025) Continuation of llvm/llvm-project#151489
The ultimate goal is to replace the return types of all the
DWARFIndex
callbacks toIterationAction
. To reduce the blast radius and do this incrementally I'm doing this forGetFunctions
only here. I added aIterationActionAdaptor
helper (that will ultimately get removed once all APIs have been migrated) to avoid having to change too many other APIs thatGetFunctions
interacts with.