Skip to content

Commit 550058c

Browse files
authored
[lldb][DWARFIndex][NFC] Change GetFunctions return type to IterationAction (#151489)
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.
1 parent 955ece4 commit 550058c

File tree

9 files changed

+101
-69
lines changed

9 files changed

+101
-69
lines changed

lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "lldb/Core/Module.h"
1515
#include "lldb/Symbol/Function.h"
16+
#include "lldb/lldb-private-enumerations.h"
1617
#include "llvm/Support/DJB.h"
1718

1819
using namespace lldb;
@@ -275,7 +276,7 @@ void AppleDWARFIndex::GetNamespaces(
275276
void AppleDWARFIndex::GetFunctions(
276277
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
277278
const CompilerDeclContext &parent_decl_ctx,
278-
llvm::function_ref<bool(DWARFDIE die)> callback) {
279+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
279280
if (!m_apple_names_up)
280281
return;
281282

@@ -288,15 +289,16 @@ void AppleDWARFIndex::GetFunctions(
288289
ReportInvalidDIERef(die_ref, name);
289290
continue;
290291
}
291-
if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx, callback))
292+
if (ProcessFunctionDIE(lookup_info, die, parent_decl_ctx, callback) ==
293+
IterationAction::Stop)
292294
return;
293295
}
294296
}
295297

296298
void AppleDWARFIndex::GetFunctions(
297299
const RegularExpression &regex,
298-
llvm::function_ref<bool(DWARFDIE die)> callback) {
299-
return GetGlobalVariables(regex, callback);
300+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
301+
return GetGlobalVariables(regex, IterationActionAdaptor(callback));
300302
}
301303

302304
void AppleDWARFIndex::Dump(Stream &s) {

lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ class AppleDWARFIndex : public DWARFIndex {
6161
llvm::function_ref<bool(DWARFDIE die)> callback) override;
6262
void GetNamespaces(ConstString name,
6363
llvm::function_ref<bool(DWARFDIE die)> callback) override;
64-
void GetFunctions(const Module::LookupInfo &lookup_info,
65-
SymbolFileDWARF &dwarf,
66-
const CompilerDeclContext &parent_decl_ctx,
67-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
68-
void GetFunctions(const RegularExpression &regex,
69-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
64+
void GetFunctions(
65+
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
66+
const CompilerDeclContext &parent_decl_ctx,
67+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
68+
void GetFunctions(
69+
const RegularExpression &regex,
70+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
7071

7172
void Dump(Stream &s) override;
7273

lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
#include "lldb/Core/Mangled.h"
1717
#include "lldb/Core/Module.h"
1818
#include "lldb/Target/Language.h"
19+
#include "lldb/lldb-private-enumerations.h"
1920

2021
using namespace lldb_private;
2122
using namespace lldb;
2223
using namespace lldb_private::plugin::dwarf;
2324

2425
DWARFIndex::~DWARFIndex() = default;
2526

26-
bool DWARFIndex::ProcessFunctionDIE(
27+
IterationAction DWARFIndex::ProcessFunctionDIE(
2728
const Module::LookupInfo &lookup_info, DWARFDIE die,
2829
const CompilerDeclContext &parent_decl_ctx,
29-
llvm::function_ref<bool(DWARFDIE die)> callback) {
30+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
3031
llvm::StringRef name = lookup_info.GetLookupName().GetStringRef();
3132
FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
3233

@@ -43,20 +44,20 @@ bool DWARFIndex::ProcessFunctionDIE(
4344

4445
if (!lookup_info.NameMatchesLookupInfo(name_to_match_against,
4546
lookup_info.GetLanguageType()))
46-
return true;
47+
return IterationAction::Continue;
4748
}
4849

4950
// Exit early if we're searching exclusively for methods or selectors and
5051
// we have a context specified (no methods in namespaces).
5152
uint32_t looking_for_nonmethods =
5253
name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector);
5354
if (!looking_for_nonmethods && parent_decl_ctx.IsValid())
54-
return true;
55+
return IterationAction::Continue;
5556

5657
// Otherwise, we need to also check that the context matches. If it does not
5758
// match, we do nothing.
5859
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
59-
return true;
60+
return IterationAction::Continue;
6061

6162
// In case of a full match, we just insert everything we find.
6263
if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)
@@ -79,7 +80,7 @@ bool DWARFIndex::ProcessFunctionDIE(
7980
return callback(die);
8081
}
8182

82-
return true;
83+
return IterationAction::Continue;
8384
}
8485

8586
DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(

lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "lldb/Core/Module.h"
1818
#include "lldb/Target/Statistics.h"
19+
#include "lldb/lldb-private-enumerations.h"
1920

2021
namespace lldb_private::plugin {
2122
namespace dwarf {
@@ -82,10 +83,10 @@ class DWARFIndex {
8283
virtual void
8384
GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
8485
const CompilerDeclContext &parent_decl_ctx,
85-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
86+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
8687
virtual void
8788
GetFunctions(const RegularExpression &regex,
88-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
89+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
8990

9091
virtual void Dump(Stream &s) = 0;
9192

@@ -101,9 +102,10 @@ class DWARFIndex {
101102
/// the function given by "die" matches search criteria given by
102103
/// "parent_decl_ctx" and "name_type_mask", it calls the callback with the
103104
/// given die.
104-
bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DWARFDIE die,
105-
const CompilerDeclContext &parent_decl_ctx,
106-
llvm::function_ref<bool(DWARFDIE die)> callback);
105+
IterationAction ProcessFunctionDIE(
106+
const Module::LookupInfo &lookup_info, DWARFDIE die,
107+
const CompilerDeclContext &parent_decl_ctx,
108+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
107109

108110
class DIERefCallbackImpl {
109111
public:
@@ -140,6 +142,25 @@ class DWARFIndex {
140142
bool ProcessNamespaceDieMatchParents(
141143
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die,
142144
llvm::function_ref<bool(DWARFDIE die)> callback);
145+
146+
/// Helper to convert callbacks that return an \c IterationAction
147+
/// to a callback that returns a \c bool, where \c true indicates
148+
/// we should continue iterating. This will be used to incrementally
149+
/// migrate the callbacks to return an \c IterationAction.
150+
///
151+
/// FIXME: remove once all callbacks in the DWARFIndex APIs return
152+
/// IterationAction.
153+
struct IterationActionAdaptor {
154+
IterationActionAdaptor(
155+
llvm::function_ref<IterationAction(DWARFDIE die)> callback)
156+
: m_callback_ref(callback) {}
157+
158+
bool operator()(DWARFDIE die) {
159+
return m_callback_ref(std::move(die)) == IterationAction::Continue;
160+
}
161+
162+
llvm::function_ref<IterationAction(DWARFDIE die)> m_callback_ref;
163+
};
143164
};
144165
} // namespace dwarf
145166
} // namespace lldb_private::plugin

lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lldb/Core/Module.h"
1515
#include "lldb/Utility/RegularExpression.h"
1616
#include "lldb/Utility/Stream.h"
17+
#include "lldb/lldb-private-enumerations.h"
1718
#include "llvm/ADT/Sequence.h"
1819
#include <optional>
1920

@@ -607,7 +608,7 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents(
607608
void DebugNamesDWARFIndex::GetFunctions(
608609
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
609610
const CompilerDeclContext &parent_decl_ctx,
610-
llvm::function_ref<bool(DWARFDIE die)> callback) {
611+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
611612
ConstString name = lookup_info.GetLookupName();
612613
std::set<DWARFDebugInfoEntry *> seen;
613614
for (const DebugNames::Entry &entry :
@@ -617,12 +618,12 @@ void DebugNamesDWARFIndex::GetFunctions(
617618
continue;
618619

619620
if (DWARFDIE die = GetDIE(entry)) {
620-
if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx,
621-
[&](DWARFDIE die) {
622-
if (!seen.insert(die.GetDIE()).second)
623-
return true;
624-
return callback(die);
625-
}))
621+
if (ProcessFunctionDIE(lookup_info, die, parent_decl_ctx,
622+
[&](DWARFDIE die) {
623+
if (!seen.insert(die.GetDIE()).second)
624+
return IterationAction::Continue;
625+
return callback(die);
626+
}) == IterationAction::Stop)
626627
return;
627628
}
628629
}
@@ -632,7 +633,7 @@ void DebugNamesDWARFIndex::GetFunctions(
632633

633634
void DebugNamesDWARFIndex::GetFunctions(
634635
const RegularExpression &regex,
635-
llvm::function_ref<bool(DWARFDIE die)> callback) {
636+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
636637
for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
637638
for (DebugNames::NameTableEntry nte: ni) {
638639
if (!regex.Execute(nte.getString()))
@@ -645,7 +646,7 @@ void DebugNamesDWARFIndex::GetFunctions(
645646
if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
646647
continue;
647648

648-
if (!ProcessEntry(*entry_or, callback))
649+
if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
649650
return;
650651
}
651652
MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());

lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ class DebugNamesDWARFIndex : public DWARFIndex {
5858
void GetNamespacesWithParents(
5959
ConstString name, const CompilerDeclContext &parent_decl_ctx,
6060
llvm::function_ref<bool(DWARFDIE die)> callback) override;
61-
void GetFunctions(const Module::LookupInfo &lookup_info,
62-
SymbolFileDWARF &dwarf,
63-
const CompilerDeclContext &parent_decl_ctx,
64-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
65-
void GetFunctions(const RegularExpression &regex,
66-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
61+
void GetFunctions(
62+
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
63+
const CompilerDeclContext &parent_decl_ctx,
64+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
65+
void GetFunctions(
66+
const RegularExpression &regex,
67+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
6768

6869
void Dump(Stream &s) override;
6970

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Utility/DataExtractor.h"
2222
#include "lldb/Utility/Stream.h"
2323
#include "lldb/Utility/Timer.h"
24+
#include "lldb/lldb-private-enumerations.h"
2425
#include "llvm/Support/FormatVariadic.h"
2526
#include "llvm/Support/ThreadPool.h"
2627
#include <atomic>
@@ -471,60 +472,62 @@ void ManualDWARFIndex::GetNamespaces(
471472
void ManualDWARFIndex::GetFunctions(
472473
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
473474
const CompilerDeclContext &parent_decl_ctx,
474-
llvm::function_ref<bool(DWARFDIE die)> callback) {
475+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
475476
Index();
476477
ConstString name = lookup_info.GetLookupName();
477478
FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
478479

479480
if (name_type_mask & eFunctionNameTypeFull) {
480481
if (!m_set.function_fullnames.Find(
481-
name, DIERefCallback(
482-
[&](DWARFDIE die) {
483-
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
484-
die))
485-
return true;
486-
return callback(die);
487-
},
488-
name.GetStringRef())))
482+
name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
483+
if (!SymbolFileDWARF::DIEInDeclContext(
484+
parent_decl_ctx, die))
485+
return IterationAction::Continue;
486+
return callback(die);
487+
}),
488+
name.GetStringRef())))
489489
return;
490490
}
491491
if (name_type_mask & eFunctionNameTypeBase) {
492492
if (!m_set.function_basenames.Find(
493-
name, DIERefCallback(
494-
[&](DWARFDIE die) {
495-
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
496-
die))
497-
return true;
498-
return callback(die);
499-
},
500-
name.GetStringRef())))
493+
name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
494+
if (!SymbolFileDWARF::DIEInDeclContext(
495+
parent_decl_ctx, die))
496+
return IterationAction::Continue;
497+
return callback(die);
498+
}),
499+
name.GetStringRef())))
501500
return;
502501
}
503502

504503
if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
505504
if (!m_set.function_methods.Find(
506-
name, DIERefCallback(callback, name.GetStringRef())))
505+
name, DIERefCallback(IterationActionAdaptor(callback),
506+
name.GetStringRef())))
507507
return;
508508
}
509509

510510
if (name_type_mask & eFunctionNameTypeSelector &&
511511
!parent_decl_ctx.IsValid()) {
512512
if (!m_set.function_selectors.Find(
513-
name, DIERefCallback(callback, name.GetStringRef())))
513+
name, DIERefCallback(IterationActionAdaptor(callback),
514+
name.GetStringRef())))
514515
return;
515516
}
516517
}
517518

518519
void ManualDWARFIndex::GetFunctions(
519520
const RegularExpression &regex,
520-
llvm::function_ref<bool(DWARFDIE die)> callback) {
521+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
521522
Index();
522523

523-
if (!m_set.function_basenames.Find(regex,
524-
DIERefCallback(callback, regex.GetText())))
524+
if (!m_set.function_basenames.Find(
525+
regex,
526+
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
525527
return;
526-
if (!m_set.function_fullnames.Find(regex,
527-
DIERefCallback(callback, regex.GetText())))
528+
if (!m_set.function_fullnames.Find(
529+
regex,
530+
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
528531
return;
529532
}
530533

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ class ManualDWARFIndex : public DWARFIndex {
5050
llvm::function_ref<bool(DWARFDIE die)> callback) override;
5151
void GetNamespaces(ConstString name,
5252
llvm::function_ref<bool(DWARFDIE die)> callback) override;
53-
void GetFunctions(const Module::LookupInfo &lookup_info,
54-
SymbolFileDWARF &dwarf,
55-
const CompilerDeclContext &parent_decl_ctx,
56-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
57-
void GetFunctions(const RegularExpression &regex,
58-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
53+
void GetFunctions(
54+
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
55+
const CompilerDeclContext &parent_decl_ctx,
56+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
57+
void GetFunctions(
58+
const RegularExpression &regex,
59+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
5960

6061
void Dump(Stream &s) override;
6162

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "ManualDWARFIndex.h"
7575
#include "SymbolFileDWARFDebugMap.h"
7676
#include "SymbolFileDWARFDwo.h"
77+
#include "lldb/lldb-private-enumerations.h"
7778

7879
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
7980
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
@@ -2539,7 +2540,7 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
25392540
m_index->GetFunctions(lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
25402541
if (resolved_dies.insert(die.GetDIE()).second)
25412542
ResolveFunction(die, include_inlines, sc_list);
2542-
return true;
2543+
return IterationAction::Continue;
25432544
});
25442545
// With -gsimple-template-names, a templated type's DW_AT_name will not
25452546
// contain the template parameters. Try again stripping '<' and anything
@@ -2556,7 +2557,7 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
25562557
[&](DWARFDIE die) {
25572558
if (resolved_dies.insert(die.GetDIE()).second)
25582559
ResolveFunction(die, include_inlines, sc_list);
2559-
return true;
2560+
return IterationAction::Continue;
25602561
});
25612562
}
25622563
}
@@ -2592,7 +2593,7 @@ void SymbolFileDWARF::FindFunctions(const RegularExpression &regex,
25922593
m_index->GetFunctions(regex, [&](DWARFDIE die) {
25932594
if (resolved_dies.insert(die.GetDIE()).second)
25942595
ResolveFunction(die, include_inlines, sc_list);
2595-
return true;
2596+
return IterationAction::Continue;
25962597
});
25972598
}
25982599

0 commit comments

Comments
 (0)