Skip to content

Commit 5218418

Browse files
committed
[lldb][DWARFIndex] Adapt DWARFIndex GetTypes APIs to IterationAction
Continuation of llvm#151489
1 parent 8d9afb8 commit 5218418

File tree

9 files changed

+102
-76
lines changed

9 files changed

+102
-76
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,16 @@ void AppleDWARFIndex::GetCompleteObjCClass(
217217
}
218218

219219
void AppleDWARFIndex::GetTypes(
220-
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
220+
ConstString name,
221+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
221222
if (!m_apple_types_up)
222223
return;
223-
SearchFor(*m_apple_types_up, name, callback);
224+
SearchFor(*m_apple_types_up, name, IterationActionAdaptor(callback));
224225
}
225226

226227
void AppleDWARFIndex::GetTypes(
227228
const DWARFDeclContext &context,
228-
llvm::function_ref<bool(DWARFDIE die)> callback) {
229+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
229230
if (!m_apple_types_up)
230231
return;
231232

@@ -243,14 +244,16 @@ void AppleDWARFIndex::GetTypes(
243244
llvm::djbHash(context.GetQualifiedName());
244245
if (log)
245246
m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
246-
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag,
247-
expected_qualname_hash);
247+
SearchFor(*m_apple_types_up, expected_name,
248+
IterationActionAdaptor(callback), expected_tag,
249+
expected_qualname_hash);
248250
return;
249251
}
250252

251253
// Historically, if there are no tags, we also ignore qual_hash (why?)
252254
if (!entries_have_tag) {
253-
SearchFor(*m_apple_names_up, expected_name, callback);
255+
SearchFor(*m_apple_names_up, expected_name,
256+
IterationActionAdaptor(callback));
254257
return;
255258
}
256259

@@ -269,7 +272,8 @@ void AppleDWARFIndex::GetTypes(
269272
if (log)
270273
m_module.LogMessage(log, "FindByNameAndTag()");
271274
const dw_tag_t expected_tag = context[0].tag;
272-
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag);
275+
SearchFor(*m_apple_types_up, expected_name, IterationActionAdaptor(callback),
276+
expected_tag);
273277
}
274278

275279
void AppleDWARFIndex::GetNamespaces(

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ class AppleDWARFIndex : public DWARFIndex {
5757
void GetCompleteObjCClass(
5858
ConstString class_name, bool must_be_implementation,
5959
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
60-
void GetTypes(ConstString name,
61-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
62-
void GetTypes(const DWARFDeclContext &context,
63-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
60+
void
61+
GetTypes(ConstString name,
62+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
63+
void
64+
GetTypes(const DWARFDeclContext &context,
65+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
6466
void GetNamespaces(
6567
ConstString name,
6668
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,42 +113,43 @@ void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {
113113

114114
void DWARFIndex::GetFullyQualifiedType(
115115
const DWARFDeclContext &context,
116-
llvm::function_ref<bool(DWARFDIE die)> callback) {
116+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
117117
GetTypes(context, [&](DWARFDIE die) {
118118
return GetFullyQualifiedTypeImpl(context, die, callback);
119119
});
120120
}
121121

122-
bool DWARFIndex::GetFullyQualifiedTypeImpl(
122+
IterationAction DWARFIndex::GetFullyQualifiedTypeImpl(
123123
const DWARFDeclContext &context, DWARFDIE die,
124-
llvm::function_ref<bool(DWARFDIE die)> callback) {
124+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
125125
DWARFDeclContext dwarf_decl_ctx = die.GetDWARFDeclContext();
126126
if (dwarf_decl_ctx == context)
127127
return callback(die);
128-
return true;
128+
return IterationAction::Continue;
129129
}
130130

131131
void DWARFIndex::GetTypesWithQuery(
132-
TypeQuery &query, llvm::function_ref<bool(DWARFDIE die)> callback) {
132+
TypeQuery &query,
133+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
133134
GetTypes(query.GetTypeBasename(), [&](DWARFDIE die) {
134135
return ProcessTypeDIEMatchQuery(query, die, callback);
135136
});
136137
}
137138

138-
bool DWARFIndex::ProcessTypeDIEMatchQuery(
139+
IterationAction DWARFIndex::ProcessTypeDIEMatchQuery(
139140
TypeQuery &query, DWARFDIE die,
140-
llvm::function_ref<bool(DWARFDIE die)> callback) {
141+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
141142
// Check the language, but only if we have a language filter.
142143
if (query.HasLanguage() &&
143144
!query.LanguageMatches(SymbolFileDWARF::GetLanguageFamily(*die.GetCU())))
144-
return true; // Keep iterating over index types, language mismatch.
145+
return IterationAction::Continue;
145146

146147
// Since mangled names are unique, we only need to check if the names are
147148
// the same.
148149
if (query.GetSearchByMangledName()) {
149150
if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
150151
query.GetTypeBasename().GetStringRef())
151-
return true; // Keep iterating over index types, mangled name mismatch.
152+
return IterationAction::Continue;
152153
return callback(die);
153154
}
154155

@@ -159,7 +160,7 @@ bool DWARFIndex::ProcessTypeDIEMatchQuery(
159160
die_context = die.GetTypeLookupContext();
160161

161162
if (!query.ContextMatches(die_context))
162-
return true;
163+
return IterationAction::Continue;
163164
return callback(die);
164165
}
165166

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ class DWARFIndex {
5050
virtual void GetCompleteObjCClass(
5151
ConstString class_name, bool must_be_implementation,
5252
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
53-
virtual void GetTypes(ConstString name,
54-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
55-
virtual void GetTypes(const DWARFDeclContext &context,
56-
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
53+
virtual void
54+
GetTypes(ConstString name,
55+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
56+
virtual void
57+
GetTypes(const DWARFDeclContext &context,
58+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
5759

5860
/// Finds all DIEs whose fully qualified name matches `context`. A base
5961
/// implementation is provided, and it uses the entire CU to check the DIE
6062
/// parent hierarchy. Specializations should override this if they are able
6163
/// to provide a faster implementation.
62-
virtual void
63-
GetFullyQualifiedType(const DWARFDeclContext &context,
64-
llvm::function_ref<bool(DWARFDIE die)> callback);
64+
virtual void GetFullyQualifiedType(
65+
const DWARFDeclContext &context,
66+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
6567
virtual void
6668
GetNamespaces(ConstString name,
6769
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
@@ -71,7 +73,7 @@ class DWARFIndex {
7173
/// implementation.
7274
virtual void
7375
GetTypesWithQuery(TypeQuery &query,
74-
llvm::function_ref<bool(DWARFDIE die)> callback);
76+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
7577
/// Get namespace DIEs whose base name match \param name with \param
7678
/// parent_decl_ctx in its decl parent chain. A base implementation
7779
/// is provided. Specializations should override this if they are able to
@@ -130,14 +132,14 @@ class DWARFIndex {
130132

131133
/// Implementation of `GetFullyQualifiedType` to check a single entry,
132134
/// shareable with derived classes.
133-
bool
134-
GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die,
135-
llvm::function_ref<bool(DWARFDIE die)> callback);
135+
IterationAction GetFullyQualifiedTypeImpl(
136+
const DWARFDeclContext &context, DWARFDIE die,
137+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
136138

137139
/// Check if the type \a die can meet the requirements of \a query.
138-
bool
139-
ProcessTypeDIEMatchQuery(TypeQuery &query, DWARFDIE die,
140-
llvm::function_ref<bool(DWARFDIE die)> callback);
140+
IterationAction ProcessTypeDIEMatchQuery(
141+
TypeQuery &query, DWARFDIE die,
142+
llvm::function_ref<IterationAction(DWARFDIE die)> callback);
141143
IterationAction ProcessNamespaceDieMatchParents(
142144
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die,
143145
llvm::function_ref<IterationAction(DWARFDIE die)> callback);

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ getParentChain(Entry entry,
329329

330330
void DebugNamesDWARFIndex::GetFullyQualifiedType(
331331
const DWARFDeclContext &context,
332-
llvm::function_ref<bool(DWARFDIE die)> callback) {
332+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
333333
if (context.GetSize() == 0)
334334
return;
335335

@@ -358,15 +358,16 @@ void DebugNamesDWARFIndex::GetFullyQualifiedType(
358358

359359
if (!parent_chain) {
360360
// Fallback: use the base class implementation.
361-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
362-
return GetFullyQualifiedTypeImpl(context, die, callback);
363-
}))
361+
if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
362+
return GetFullyQualifiedTypeImpl(context, die,
363+
callback);
364+
})))
364365
return;
365366
continue;
366367
}
367368

368369
if (SameParentChain(parent_names, *parent_chain)) {
369-
if (!ProcessEntry(entry, callback))
370+
if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
370371
return;
371372
}
372373
}
@@ -456,11 +457,12 @@ bool DebugNamesDWARFIndex::WithinParentChain(
456457
}
457458

458459
void DebugNamesDWARFIndex::GetTypes(
459-
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
460+
ConstString name,
461+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
460462
for (const DebugNames::Entry &entry :
461463
m_debug_names_up->equal_range(name.GetStringRef())) {
462464
if (isType(entry.tag())) {
463-
if (!ProcessEntry(entry, callback))
465+
if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
464466
return;
465467
}
466468
}
@@ -470,11 +472,11 @@ void DebugNamesDWARFIndex::GetTypes(
470472

471473
void DebugNamesDWARFIndex::GetTypes(
472474
const DWARFDeclContext &context,
473-
llvm::function_ref<bool(DWARFDIE die)> callback) {
475+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
474476
auto name = context[0].name;
475477
for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name)) {
476478
if (entry.tag() == context[0].tag) {
477-
if (!ProcessEntry(entry, callback))
479+
if (!ProcessEntry(entry, IterationActionAdaptor(callback)))
478480
return;
479481
}
480482
}
@@ -521,7 +523,8 @@ DebugNamesDWARFIndex::GetTypeQueryParentContexts(TypeQuery &query) {
521523
}
522524

523525
void DebugNamesDWARFIndex::GetTypesWithQuery(
524-
TypeQuery &query, llvm::function_ref<bool(DWARFDIE die)> callback) {
526+
TypeQuery &query,
527+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
525528
ConstString name = query.GetTypeBasename();
526529
std::vector<lldb_private::CompilerContext> query_context =
527530
query.GetContextRef();
@@ -546,19 +549,20 @@ void DebugNamesDWARFIndex::GetTypesWithQuery(
546549
getParentChain(entry);
547550
if (!parent_chain) {
548551
// Fallback: use the base class implementation.
549-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
550-
return ProcessTypeDIEMatchQuery(query, die, callback);
551-
}))
552+
if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
553+
return ProcessTypeDIEMatchQuery(query, die, callback);
554+
})))
552555
return;
553556
continue;
554557
}
555558

556559
if (WithinParentChain(parent_contexts, *parent_chain)) {
557-
if (!ProcessEntry(entry, [&](DWARFDIE die) {
558-
// After .debug_names filtering still sending to base class for
559-
// further filtering before calling the callback.
560-
return ProcessTypeDIEMatchQuery(query, die, callback);
561-
}))
560+
if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) {
561+
// After .debug_names filtering still sending to base
562+
// class for further filtering before calling the
563+
// callback.
564+
return ProcessTypeDIEMatchQuery(query, die, callback);
565+
})))
562566
// If the callback returns false, we're done.
563567
return;
564568
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ class DebugNamesDWARFIndex : public DWARFIndex {
4646
/// Uses DWARF5's IDX_parent fields, when available, to speed up this query.
4747
void GetFullyQualifiedType(
4848
const DWARFDeclContext &context,
49-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
50-
void GetTypes(ConstString name,
51-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
52-
void GetTypes(const DWARFDeclContext &context,
53-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
49+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
50+
void
51+
GetTypes(ConstString name,
52+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
53+
void
54+
GetTypes(const DWARFDeclContext &context,
55+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
5456
void GetNamespaces(
5557
ConstString name,
5658
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
57-
void
58-
GetTypesWithQuery(TypeQuery &query,
59-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
59+
void GetTypesWithQuery(
60+
TypeQuery &query,
61+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
6062
void GetNamespacesWithParents(
6163
ConstString name, const CompilerDeclContext &parent_decl_ctx,
6264
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,21 @@ void ManualDWARFIndex::GetCompleteObjCClass(
455455
}
456456

457457
void ManualDWARFIndex::GetTypes(
458-
ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
458+
ConstString name,
459+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
459460
Index();
460-
m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
461+
m_set.types.Find(name, DIERefCallback(IterationActionAdaptor(callback),
462+
name.GetStringRef()));
461463
}
462464

463465
void ManualDWARFIndex::GetTypes(
464466
const DWARFDeclContext &context,
465-
llvm::function_ref<bool(DWARFDIE die)> callback) {
467+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
466468
Index();
467469
auto name = context[0].name;
468-
m_set.types.Find(ConstString(name),
469-
DIERefCallback(callback, llvm::StringRef(name)));
470+
m_set.types.Find(
471+
ConstString(name),
472+
DIERefCallback(IterationActionAdaptor(callback), llvm::StringRef(name)));
470473
}
471474

472475
void ManualDWARFIndex::GetNamespaces(

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class ManualDWARFIndex : public DWARFIndex {
4646
void GetCompleteObjCClass(
4747
ConstString class_name, bool must_be_implementation,
4848
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
49-
void GetTypes(ConstString name,
50-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
51-
void GetTypes(const DWARFDeclContext &context,
52-
llvm::function_ref<bool(DWARFDIE die)> callback) override;
49+
void
50+
GetTypes(ConstString name,
51+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
52+
void
53+
GetTypes(const DWARFDeclContext &context,
54+
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
5355
void GetNamespaces(
5456
ConstString name,
5557
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

0 commit comments

Comments
 (0)