Skip to content

[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

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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 &regex,
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) {
Expand Down
13 changes: 7 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &regex,
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 &regex,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

void Dump(Stream &s) override;

Expand Down
13 changes: 7 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
#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;
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();

Expand All @@ -43,20 +44,20 @@ 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
// we have a context specified (no methods in namespaces).
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)
Expand All @@ -79,7 +80,7 @@ bool DWARFIndex::ProcessFunctionDIE(
return callback(die);
}

return true;
return IterationAction::Continue;
}

DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
Expand Down
31 changes: 26 additions & 5 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 &regex,
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;

virtual void Dump(Stream &s) = 0;

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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 :
Expand All @@ -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;
}
}
Expand All @@ -632,7 +633,7 @@ void DebugNamesDWARFIndex::GetFunctions(

void DebugNamesDWARFIndex::GetFunctions(
const RegularExpression &regex,
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()))
Expand All @@ -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());
Expand Down
13 changes: 7 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &regex,
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 &regex,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

void Dump(Stream &s) override;

Expand Down
51 changes: 27 additions & 24 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 &regex,
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;
}

Expand Down
13 changes: 7 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &regex,
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 &regex,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

void Dump(Stream &s) override;

Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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;
});
}
}
Expand Down Expand Up @@ -2592,7 +2593,7 @@ void SymbolFileDWARF::FindFunctions(const RegularExpression &regex,
m_index->GetFunctions(regex, [&](DWARFDIE die) {
if (resolved_dies.insert(die.GetDIE()).second)
ResolveFunction(die, include_inlines, sc_list);
return true;
return IterationAction::Continue;
});
}

Expand Down
Loading