Skip to content

Commit 147cfc8

Browse files
authored
[lldb][DWARFIndex] Adapt DWARFIndex DIERefCallback to IterationAction (#152001)
Continuation of #151489
1 parent ad623a8 commit 147cfc8

File tree

7 files changed

+87
-93
lines changed

7 files changed

+87
-93
lines changed

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

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ HasImplementationFlag(const llvm::AppleAcceleratorTable::Entry &entry) {
118118
(*Flags & llvm::dwarf::AcceleratorTable::DW_FLAG_type_implementation);
119119
}
120120

121-
void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table,
122-
llvm::StringRef name,
123-
llvm::function_ref<bool(DWARFDIE die)> callback,
124-
std::optional<dw_tag_t> search_for_tag,
125-
std::optional<uint32_t> search_for_qualhash) {
121+
void AppleDWARFIndex::SearchFor(
122+
const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
123+
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
124+
std::optional<dw_tag_t> search_for_tag,
125+
std::optional<uint32_t> search_for_qualhash) {
126126
auto converted_cb = DIERefCallback(callback, name);
127127
for (const auto &entry : table.equal_range(name)) {
128128
if (search_for_qualhash &&
129129
!EntryHasMatchingQualhash(entry, *search_for_qualhash))
130130
continue;
131131
if (search_for_tag && !EntryHasMatchingTag(entry, *search_for_tag))
132132
continue;
133-
if (!converted_cb(entry))
133+
if (converted_cb(entry) == IterationAction::Stop)
134134
break;
135135
}
136136
}
@@ -140,7 +140,7 @@ void AppleDWARFIndex::GetGlobalVariables(
140140
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
141141
if (!m_apple_names_up)
142142
return;
143-
SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback));
143+
SearchFor(*m_apple_names_up, basename, callback);
144144
}
145145

146146
void AppleDWARFIndex::GetGlobalVariables(
@@ -149,14 +149,12 @@ void AppleDWARFIndex::GetGlobalVariables(
149149
if (!m_apple_names_up)
150150
return;
151151

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

156154
for (const auto &entry : m_apple_names_up->entries())
157155
if (std::optional<llvm::StringRef> name = entry.readName();
158156
name && Mangled(*name).NameMatches(regex))
159-
if (!converted_cb(entry.BaseEntry))
157+
if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
160158
return;
161159
}
162160

@@ -172,11 +170,10 @@ void AppleDWARFIndex::GetGlobalVariables(
172170
return val.has_value() && *val >= lower_bound && *val < upper_bound;
173171
};
174172

175-
auto adataped_cb = IterationActionAdaptor(callback);
176-
DIERefCallbackImpl converted_cb = DIERefCallback(adataped_cb);
173+
DIERefCallbackImpl converted_cb = DIERefCallback(callback);
177174
for (auto entry : m_apple_names_up->entries()) {
178175
if (is_in_range(entry.BaseEntry.getDIESectionOffset()))
179-
if (!converted_cb(entry.BaseEntry))
176+
if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
180177
return;
181178
}
182179
}
@@ -186,7 +183,7 @@ void AppleDWARFIndex::GetObjCMethods(
186183
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
187184
if (!m_apple_objc_up)
188185
return;
189-
SearchFor(*m_apple_objc_up, class_name, IterationActionAdaptor(callback));
186+
SearchFor(*m_apple_objc_up, class_name, callback);
190187
}
191188

192189
void AppleDWARFIndex::GetCompleteObjCClass(
@@ -196,8 +193,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
196193
return;
197194

198195
llvm::SmallVector<DIERef> decl_dies;
199-
auto adapted_cb = IterationActionAdaptor(callback);
200-
auto converted_cb = DIERefCallback(adapted_cb, class_name);
196+
auto converted_cb = DIERefCallback(callback, class_name);
201197

202198
for (const auto &entry : m_apple_types_up->equal_range(class_name)) {
203199
if (HasImplementationFlag(entry)) {
@@ -212,7 +208,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
212208
if (must_be_implementation)
213209
return;
214210
for (DIERef ref : decl_dies)
215-
if (!converted_cb(ref))
211+
if (converted_cb(ref) == IterationAction::Stop)
216212
return;
217213
}
218214

@@ -221,7 +217,7 @@ void AppleDWARFIndex::GetTypes(
221217
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
222218
if (!m_apple_types_up)
223219
return;
224-
SearchFor(*m_apple_types_up, name, IterationActionAdaptor(callback));
220+
SearchFor(*m_apple_types_up, name, callback);
225221
}
226222

227223
void AppleDWARFIndex::GetTypes(
@@ -244,16 +240,14 @@ void AppleDWARFIndex::GetTypes(
244240
llvm::djbHash(context.GetQualifiedName());
245241
if (log)
246242
m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
247-
SearchFor(*m_apple_types_up, expected_name,
248-
IterationActionAdaptor(callback), expected_tag,
243+
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag,
249244
expected_qualname_hash);
250245
return;
251246
}
252247

253248
// Historically, if there are no tags, we also ignore qual_hash (why?)
254249
if (!entries_have_tag) {
255-
SearchFor(*m_apple_names_up, expected_name,
256-
IterationActionAdaptor(callback));
250+
SearchFor(*m_apple_names_up, expected_name, callback);
257251
return;
258252
}
259253

@@ -272,16 +266,15 @@ void AppleDWARFIndex::GetTypes(
272266
if (log)
273267
m_module.LogMessage(log, "FindByNameAndTag()");
274268
const dw_tag_t expected_tag = context[0].tag;
275-
SearchFor(*m_apple_types_up, expected_name, IterationActionAdaptor(callback),
276-
expected_tag);
269+
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag);
277270
}
278271

279272
void AppleDWARFIndex::GetNamespaces(
280273
ConstString name,
281274
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
282275
if (!m_apple_namespaces_up)
283276
return;
284-
SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback));
277+
SearchFor(*m_apple_namespaces_up, name, callback);
285278
}
286279

287280
void AppleDWARFIndex::GetFunctions(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ class AppleDWARFIndex : public DWARFIndex {
9494
/// each match. If `search_for_tag` is provided, ignore entries whose tag is
9595
/// not `search_for_tag`. If `search_for_qualhash` is provided, ignore entries
9696
/// whose qualified name hash does not match `search_for_qualhash`.
97-
/// If `callback` returns false for an entry, the search is interrupted.
97+
/// If `callback` returns `IterationAction::Stop` for an entry, the search is
98+
/// interrupted.
9899
void SearchFor(const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
99-
llvm::function_ref<bool(DWARFDIE die)> callback,
100+
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
100101
std::optional<dw_tag_t> search_for_tag = std::nullopt,
101102
std::optional<uint32_t> search_for_qualhash = std::nullopt);
102103
};

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,22 @@ IterationAction DWARFIndex::ProcessFunctionDIE(
8484
}
8585

8686
DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
87-
const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,
87+
const DWARFIndex &index,
88+
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
8889
llvm::StringRef name)
8990
: m_index(index),
9091
m_dwarf(*llvm::cast<SymbolFileDWARF>(
9192
index.m_module.GetSymbolFile()->GetBackingSymbolFile())),
9293
m_callback(callback), m_name(name) {}
9394

94-
bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
95+
IterationAction DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
9596
if (DWARFDIE die = m_dwarf.GetDIE(ref))
9697
return m_callback(die);
9798
m_index.ReportInvalidDIERef(ref, m_name);
98-
return true;
99+
return IterationAction::Continue;
99100
}
100101

101-
bool DWARFIndex::DIERefCallbackImpl::operator()(
102+
IterationAction DWARFIndex::DIERefCallbackImpl::operator()(
102103
const llvm::AppleAcceleratorTable::Entry &entry) const {
103104
return this->operator()(DIERef(std::nullopt, DIERef::Section::DebugInfo,
104105
*entry.getDIESectionOffset()));

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,22 @@ class DWARFIndex {
110110

111111
class DIERefCallbackImpl {
112112
public:
113-
DIERefCallbackImpl(const DWARFIndex &index,
114-
llvm::function_ref<bool(DWARFDIE die)> callback,
115-
llvm::StringRef name);
116-
bool operator()(DIERef ref) const;
117-
bool operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;
113+
DIERefCallbackImpl(
114+
const DWARFIndex &index,
115+
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
116+
llvm::StringRef name);
117+
IterationAction operator()(DIERef ref) const;
118+
IterationAction
119+
operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;
118120

119121
private:
120122
const DWARFIndex &m_index;
121123
SymbolFileDWARF &m_dwarf;
122-
const llvm::function_ref<bool(DWARFDIE die)> m_callback;
124+
const llvm::function_ref<IterationAction(DWARFDIE die)> m_callback;
123125
const llvm::StringRef m_name;
124126
};
125127
DIERefCallbackImpl
126-
DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback,
128+
DIERefCallback(llvm::function_ref<IterationAction(DWARFDIE die)> callback,
127129
llvm::StringRef name = {}) const {
128130
return DIERefCallbackImpl(*this, callback, name);
129131
}

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

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -417,67 +417,61 @@ void ManualDWARFIndex::GetGlobalVariables(
417417
ConstString basename,
418418
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
419419
Index();
420-
m_set.globals.Find(basename, DIERefCallback(IterationActionAdaptor(callback),
421-
basename.GetStringRef()));
420+
m_set.globals.Find(basename,
421+
DIERefCallback(callback, basename.GetStringRef()));
422422
}
423423

424424
void ManualDWARFIndex::GetGlobalVariables(
425425
const RegularExpression &regex,
426426
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
427427
Index();
428-
m_set.globals.Find(
429-
regex, DIERefCallback(IterationActionAdaptor(callback), regex.GetText()));
428+
m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
430429
}
431430

432431
void ManualDWARFIndex::GetGlobalVariables(
433432
DWARFUnit &unit,
434433
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
435434
Index();
436-
m_set.globals.FindAllEntriesForUnit(
437-
unit, DIERefCallback(IterationActionAdaptor(callback)));
435+
m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
438436
}
439437

440438
void ManualDWARFIndex::GetObjCMethods(
441439
ConstString class_name,
442440
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
443441
Index();
444442
m_set.objc_class_selectors.Find(
445-
class_name, DIERefCallback(IterationActionAdaptor(callback),
446-
class_name.GetStringRef()));
443+
class_name, DIERefCallback(callback, class_name.GetStringRef()));
447444
}
448445

449446
void ManualDWARFIndex::GetCompleteObjCClass(
450447
ConstString class_name, bool must_be_implementation,
451448
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
452449
Index();
453-
m_set.types.Find(class_name, DIERefCallback(IterationActionAdaptor(callback),
454-
class_name.GetStringRef()));
450+
m_set.types.Find(class_name,
451+
DIERefCallback(callback, class_name.GetStringRef()));
455452
}
456453

457454
void ManualDWARFIndex::GetTypes(
458455
ConstString name,
459456
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
460457
Index();
461-
m_set.types.Find(name, DIERefCallback(IterationActionAdaptor(callback),
462-
name.GetStringRef()));
458+
m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
463459
}
464460

465461
void ManualDWARFIndex::GetTypes(
466462
const DWARFDeclContext &context,
467463
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
468464
Index();
469465
auto name = context[0].name;
470-
m_set.types.Find(
471-
ConstString(name),
472-
DIERefCallback(IterationActionAdaptor(callback), llvm::StringRef(name)));
466+
m_set.types.Find(ConstString(name),
467+
DIERefCallback(callback, llvm::StringRef(name)));
473468
}
474469

475470
void ManualDWARFIndex::GetNamespaces(
476471
ConstString name,
477472
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
478473
Index();
479-
m_set.namespaces.Find(name, DIERefCallback(IterationActionAdaptor(callback),
480-
name.GetStringRef()));
474+
m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
481475
}
482476

483477
void ManualDWARFIndex::GetFunctions(
@@ -490,39 +484,39 @@ void ManualDWARFIndex::GetFunctions(
490484

491485
if (name_type_mask & eFunctionNameTypeFull) {
492486
if (!m_set.function_fullnames.Find(
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())))
487+
name, DIERefCallback(
488+
[&](DWARFDIE die) {
489+
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
490+
die))
491+
return IterationAction::Continue;
492+
return callback(die);
493+
},
494+
name.GetStringRef())))
500495
return;
501496
}
502497
if (name_type_mask & eFunctionNameTypeBase) {
503498
if (!m_set.function_basenames.Find(
504-
name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
505-
if (!SymbolFileDWARF::DIEInDeclContext(
506-
parent_decl_ctx, die))
507-
return IterationAction::Continue;
508-
return callback(die);
509-
}),
510-
name.GetStringRef())))
499+
name, DIERefCallback(
500+
[&](DWARFDIE die) {
501+
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
502+
die))
503+
return IterationAction::Continue;
504+
return callback(die);
505+
},
506+
name.GetStringRef())))
511507
return;
512508
}
513509

514510
if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
515511
if (!m_set.function_methods.Find(
516-
name, DIERefCallback(IterationActionAdaptor(callback),
517-
name.GetStringRef())))
512+
name, DIERefCallback(callback, name.GetStringRef())))
518513
return;
519514
}
520515

521516
if (name_type_mask & eFunctionNameTypeSelector &&
522517
!parent_decl_ctx.IsValid()) {
523518
if (!m_set.function_selectors.Find(
524-
name, DIERefCallback(IterationActionAdaptor(callback),
525-
name.GetStringRef())))
519+
name, DIERefCallback(callback, name.GetStringRef())))
526520
return;
527521
}
528522
}
@@ -532,13 +526,11 @@ void ManualDWARFIndex::GetFunctions(
532526
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
533527
Index();
534528

535-
if (!m_set.function_basenames.Find(
536-
regex,
537-
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
529+
if (!m_set.function_basenames.Find(regex,
530+
DIERefCallback(callback, regex.GetText())))
538531
return;
539-
if (!m_set.function_fullnames.Find(
540-
regex,
541-
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
532+
if (!m_set.function_fullnames.Find(regex,
533+
DIERefCallback(callback, regex.GetText())))
542534
return;
543535
}
544536

0 commit comments

Comments
 (0)