Skip to content

Commit 0bdb4a3

Browse files
authored
[lldb][DWARFIndex][NFC] Change GetNamespace/GetGlobalVariables APIs to use IterationAction (#151668)
Continuation from #151489
1 parent a1dfcc6 commit 0bdb4a3

File tree

9 files changed

+128
-101
lines changed

9 files changed

+128
-101
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,22 @@ void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table,
136136
}
137137

138138
void AppleDWARFIndex::GetGlobalVariables(
139-
ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
139+
ConstString basename,
140+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
140141
if (!m_apple_names_up)
141142
return;
142-
SearchFor(*m_apple_names_up, basename, callback);
143+
SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback));
143144
}
144145

145146
void AppleDWARFIndex::GetGlobalVariables(
146147
const RegularExpression &regex,
147-
llvm::function_ref<bool(DWARFDIE die)> callback) {
148+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
148149
if (!m_apple_names_up)
149150
return;
150151

151-
DIERefCallbackImpl converted_cb = DIERefCallback(callback, regex.GetText());
152+
auto adataped_cb = IterationActionAdaptor(callback);
153+
DIERefCallbackImpl converted_cb =
154+
DIERefCallback(adataped_cb, regex.GetText());
152155

153156
for (const auto &entry : m_apple_names_up->entries())
154157
if (std::optional<llvm::StringRef> name = entry.readName();
@@ -158,7 +161,7 @@ void AppleDWARFIndex::GetGlobalVariables(
158161
}
159162

160163
void AppleDWARFIndex::GetGlobalVariables(
161-
DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
164+
DWARFUnit &cu, llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
162165
if (!m_apple_names_up)
163166
return;
164167

@@ -169,7 +172,8 @@ void AppleDWARFIndex::GetGlobalVariables(
169172
return val.has_value() && *val >= lower_bound && *val < upper_bound;
170173
};
171174

172-
DIERefCallbackImpl converted_cb = DIERefCallback(callback);
175+
auto adataped_cb = IterationActionAdaptor(callback);
176+
DIERefCallbackImpl converted_cb = DIERefCallback(adataped_cb);
173177
for (auto entry : m_apple_names_up->entries()) {
174178
if (is_in_range(entry.BaseEntry.getDIESectionOffset()))
175179
if (!converted_cb(entry.BaseEntry))
@@ -267,10 +271,11 @@ void AppleDWARFIndex::GetTypes(
267271
}
268272

269273
void AppleDWARFIndex::GetNamespaces(
270-
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
274+
ConstString name,
275+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
271276
if (!m_apple_namespaces_up)
272277
return;
273-
SearchFor(*m_apple_namespaces_up, name, callback);
278+
SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback));
274279
}
275280

276281
void AppleDWARFIndex::GetFunctions(
@@ -298,7 +303,7 @@ void AppleDWARFIndex::GetFunctions(
298303
void AppleDWARFIndex::GetFunctions(
299304
const RegularExpression &regex,
300305
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
301-
return GetGlobalVariables(regex, IterationActionAdaptor(callback));
306+
return GetGlobalVariables(regex, callback);
302307
}
303308

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

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class AppleDWARFIndex : public DWARFIndex {
4141

4242
void Preload() override {}
4343

44-
void
45-
GetGlobalVariables(ConstString basename,
46-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
47-
void
48-
GetGlobalVariables(const RegularExpression &regex,
49-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
50-
void
51-
GetGlobalVariables(DWARFUnit &cu,
52-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
44+
void GetGlobalVariables(
45+
ConstString basename,
46+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
47+
void GetGlobalVariables(
48+
const RegularExpression &regex,
49+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
50+
void GetGlobalVariables(
51+
DWARFUnit &cu,
52+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
5353
void GetObjCMethods(ConstString class_name,
5454
llvm::function_ref<bool(DWARFDIE die)> callback) override;
5555
void GetCompleteObjCClass(
@@ -59,8 +59,9 @@ class AppleDWARFIndex : public DWARFIndex {
5959
llvm::function_ref<bool(DWARFDIE die)> callback) override;
6060
void GetTypes(const DWARFDeclContext &context,
6161
llvm::function_ref<bool(DWARFDIE die)> callback) override;
62-
void GetNamespaces(ConstString name,
63-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
62+
void GetNamespaces(
63+
ConstString name,
64+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
6465
void GetFunctions(
6566
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
6667
const CompilerDeclContext &parent_decl_ctx,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ bool DWARFIndex::ProcessTypeDIEMatchQuery(
165165

166166
void DWARFIndex::GetNamespacesWithParents(
167167
ConstString name, const CompilerDeclContext &parent_decl_ctx,
168-
llvm::function_ref<bool(DWARFDIE die)> callback) {
168+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
169169
GetNamespaces(name, [&](DWARFDIE die) {
170170
return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, callback);
171171
});
172172
}
173173

174-
bool DWARFIndex::ProcessNamespaceDieMatchParents(
174+
IterationAction DWARFIndex::ProcessNamespaceDieMatchParents(
175175
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die,
176-
llvm::function_ref<bool(DWARFDIE die)> callback) {
176+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
177177
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
178-
return true;
178+
return IterationAction::Continue;
179179
return callback(die);
180180
}

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ class DWARFIndex {
3333
/// Finds global variables with the given base name. Any additional filtering
3434
/// (e.g., to only retrieve variables from a given context) should be done by
3535
/// the consumer.
36-
virtual void
37-
GetGlobalVariables(ConstString basename,
38-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
36+
virtual void GetGlobalVariables(
37+
ConstString basename,
38+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
3939

40-
virtual void
41-
GetGlobalVariables(const RegularExpression &regex,
42-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
40+
virtual void GetGlobalVariables(
41+
const RegularExpression &regex,
42+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
4343
/// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit().
44-
virtual void
45-
GetGlobalVariables(DWARFUnit &cu,
46-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
44+
virtual void GetGlobalVariables(
45+
DWARFUnit &cu,
46+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
4747
virtual void
4848
GetObjCMethods(ConstString class_name,
4949
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
@@ -64,7 +64,7 @@ class DWARFIndex {
6464
llvm::function_ref<bool(DWARFDIE die)> callback);
6565
virtual void
6666
GetNamespaces(ConstString name,
67-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
67+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
6868
/// Get type DIEs meeting requires of \a query.
6969
/// in its decl parent chain as subset. A base implementation is provided,
7070
/// Specializations should override this if they are able to provide a faster
@@ -76,10 +76,9 @@ class DWARFIndex {
7676
/// parent_decl_ctx in its decl parent chain. A base implementation
7777
/// is provided. Specializations should override this if they are able to
7878
/// provide a faster implementation.
79-
virtual void
80-
GetNamespacesWithParents(ConstString name,
81-
const CompilerDeclContext &parent_decl_ctx,
82-
llvm::function_ref<bool(DWARFDIE die)> callback);
79+
virtual void GetNamespacesWithParents(
80+
ConstString name, const CompilerDeclContext &parent_decl_ctx,
81+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
8382
virtual void
8483
GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
8584
const CompilerDeclContext &parent_decl_ctx,
@@ -139,9 +138,9 @@ class DWARFIndex {
139138
bool
140139
ProcessTypeDIEMatchQuery(TypeQuery &query, DWARFDIE die,
141140
llvm::function_ref<bool(DWARFDIE die)> callback);
142-
bool ProcessNamespaceDieMatchParents(
141+
IterationAction ProcessNamespaceDieMatchParents(
143142
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die,
144-
llvm::function_ref<bool(DWARFDIE die)> callback);
143+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
145144

146145
/// Helper to convert callbacks that return an \c IterationAction
147146
/// to a callback that returns a \c bool, where \c true indicates

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,14 @@ void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error,
178178
}
179179

180180
void DebugNamesDWARFIndex::GetGlobalVariables(
181-
ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
181+
ConstString basename,
182+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
182183
for (const DebugNames::Entry &entry :
183184
m_debug_names_up->equal_range(basename.GetStringRef())) {
184185
if (entry.tag() != DW_TAG_variable)
185186
continue;
186187

187-
if (!ProcessEntry(entry, callback))
188+
if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
188189
return;
189190
}
190191

@@ -193,7 +194,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
193194

194195
void DebugNamesDWARFIndex::GetGlobalVariables(
195196
const RegularExpression &regex,
196-
llvm::function_ref<bool(DWARFDIE die)> callback) {
197+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
197198
for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
198199
for (DebugNames::NameTableEntry nte: ni) {
199200
Mangled mangled_name(nte.getString());
@@ -206,7 +207,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
206207
if (entry_or->tag() != DW_TAG_variable)
207208
continue;
208209

209-
if (!ProcessEntry(*entry_or, callback))
210+
if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
210211
return;
211212
}
212213
MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -217,7 +218,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
217218
}
218219

219220
void DebugNamesDWARFIndex::GetGlobalVariables(
220-
DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
221+
DWARFUnit &cu, llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
221222
uint64_t cu_offset = cu.GetOffset();
222223
bool found_entry_for_cu = false;
223224
for (const DebugNames::NameIndex &ni : *m_debug_names_up) {
@@ -242,7 +243,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
242243
continue;
243244

244245
found_entry_for_cu = true;
245-
if (!ProcessEntry(*entry_or, callback))
246+
if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback)))
246247
return;
247248
}
248249
MaybeLogLookupError(entry_or.takeError(), ni, nte.getString());
@@ -482,13 +483,14 @@ void DebugNamesDWARFIndex::GetTypes(
482483
}
483484

484485
void DebugNamesDWARFIndex::GetNamespaces(
485-
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
486+
ConstString name,
487+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
486488
for (const DebugNames::Entry &entry :
487489
m_debug_names_up->equal_range(name.GetStringRef())) {
488490
llvm::dwarf::Tag entry_tag = entry.tag();
489491
if (entry_tag == DW_TAG_namespace ||
490492
entry_tag == DW_TAG_imported_declaration) {
491-
if (!ProcessEntry(entry, callback))
493+
if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
492494
return;
493495
}
494496
}
@@ -566,7 +568,7 @@ void DebugNamesDWARFIndex::GetTypesWithQuery(
566568

567569
void DebugNamesDWARFIndex::GetNamespacesWithParents(
568570
ConstString name, const CompilerDeclContext &parent_decl_ctx,
569-
llvm::function_ref<bool(DWARFDIE die)> callback) {
571+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
570572
std::vector<lldb_private::CompilerContext> parent_contexts =
571573
parent_decl_ctx.GetCompilerContext();
572574
llvm::SmallVector<CompilerContext> parent_named_contexts;
@@ -582,21 +584,22 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents(
582584
getParentChain(entry);
583585
if (!parent_chain) {
584586
// Fallback: use the base class implementation.
585-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
586-
return ProcessNamespaceDieMatchParents(parent_decl_ctx, die,
587-
callback);
588-
}))
587+
if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
588+
return ProcessNamespaceDieMatchParents(
589+
parent_decl_ctx, die, callback);
590+
})))
589591
return;
590592
continue;
591593
}
592594

593595
if (WithinParentChain(parent_named_contexts, *parent_chain)) {
594-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
595-
// After .debug_names filtering still sending to base class for
596-
// further filtering before calling the callback.
597-
return ProcessNamespaceDieMatchParents(parent_decl_ctx, die,
598-
callback);
599-
}))
596+
if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
597+
// After .debug_names filtering still sending to
598+
// base class for further filtering before calling
599+
// the callback.
600+
return ProcessNamespaceDieMatchParents(
601+
parent_decl_ctx, die, callback);
602+
})))
600603
// If the callback returns false, we're done.
601604
return;
602605
}

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h"
1414
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
1515
#include "lldb/Utility/ConstString.h"
16+
#include "lldb/lldb-private-enumerations.h"
1617
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
1718
#include <optional>
1819

@@ -26,15 +27,15 @@ class DebugNamesDWARFIndex : public DWARFIndex {
2627

2728
void Preload() override { m_fallback.Preload(); }
2829

29-
void
30-
GetGlobalVariables(ConstString basename,
31-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
32-
void
33-
GetGlobalVariables(const RegularExpression &regex,
34-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
35-
void
36-
GetGlobalVariables(DWARFUnit &cu,
37-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
30+
void GetGlobalVariables(
31+
ConstString basename,
32+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
33+
void GetGlobalVariables(
34+
const RegularExpression &regex,
35+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
36+
void GetGlobalVariables(
37+
DWARFUnit &cu,
38+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
3839
void
3940
GetObjCMethods(ConstString class_name,
4041
llvm::function_ref<bool(DWARFDIE die)> callback) override {}
@@ -50,14 +51,15 @@ class DebugNamesDWARFIndex : public DWARFIndex {
5051
llvm::function_ref<bool(DWARFDIE die)> callback) override;
5152
void GetTypes(const DWARFDeclContext &context,
5253
llvm::function_ref<bool(DWARFDIE die)> callback) override;
53-
void GetNamespaces(ConstString name,
54-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
54+
void GetNamespaces(
55+
ConstString name,
56+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
5557
void
5658
GetTypesWithQuery(TypeQuery &query,
5759
llvm::function_ref<bool(DWARFDIE die)> callback) override;
5860
void GetNamespacesWithParents(
5961
ConstString name, const CompilerDeclContext &parent_decl_ctx,
60-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
62+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
6163
void GetFunctions(
6264
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
6365
const CompilerDeclContext &parent_decl_ctx,

0 commit comments

Comments
 (0)