Skip to content

Commit aa1fde4

Browse files
committed
[lldb/DWARF] Remove duplicate type filtering
In llvm#108907, the index classes started filtering the DIEs according to the full type query (instead of just the base name). This means that the checks in SymbolFileDWARF are now redundant. I've also moved the non-redundant checks so that now all checking is done in the DWARFIndex class and the caller can expect to get the final filtered list of types.
1 parent 0a1795f commit aa1fde4

File tree

2 files changed

+14
-52
lines changed

2 files changed

+14
-52
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,19 @@ void DWARFIndex::GetTypesWithQuery(
137137
bool DWARFIndex::ProcessTypeDIEMatchQuery(
138138
TypeQuery &query, DWARFDIE die,
139139
llvm::function_ref<bool(DWARFDIE die)> callback) {
140-
// Nothing to match from query
141-
if (query.GetContextRef().size() <= 1)
140+
// Check the language, but only if we have a language filter.
141+
if (query.HasLanguage() &&
142+
!query.LanguageMatches(SymbolFileDWARF::GetLanguageFamily(*die.GetCU())))
143+
return true; // Keep iterating over index types, language mismatch.
144+
145+
// Since mangled names are unique, we only need to check if the names are
146+
// the same.
147+
if (query.GetSearchByMangledName()) {
148+
if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
149+
query.GetTypeBasename().GetStringRef())
150+
return true; // Keep iterating over index types, mangled name mismatch.
142151
return callback(die);
152+
}
143153

144154
std::vector<lldb_private::CompilerContext> die_context;
145155
if (query.GetModuleSearch())

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

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,39 +2726,8 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
27262726
TypeQuery query_full(query);
27272727
bool have_index_match = false;
27282728
m_index->GetTypesWithQuery(query_full, [&](DWARFDIE die) {
2729-
// Check the language, but only if we have a language filter.
2730-
if (query.HasLanguage()) {
2731-
if (!query.LanguageMatches(GetLanguageFamily(*die.GetCU())))
2732-
return true; // Keep iterating over index types, language mismatch.
2733-
}
2734-
2735-
// Since mangled names are unique, we only need to check if the names are
2736-
// the same.
2737-
if (query.GetSearchByMangledName()) {
2738-
if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
2739-
query.GetTypeBasename().GetStringRef())
2740-
return true; // Keep iterating over index types, mangled name mismatch.
2741-
if (Type *matching_type = ResolveType(die, true, true)) {
2742-
results.InsertUnique(matching_type->shared_from_this());
2743-
return !results.Done(query); // Keep iterating if we aren't done.
2744-
}
2745-
return true; // Keep iterating over index types, weren't able to resolve
2746-
// this type
2747-
}
2748-
2749-
// Check the context matches
2750-
std::vector<lldb_private::CompilerContext> die_context;
2751-
if (query.GetModuleSearch())
2752-
die_context = die.GetDeclContext();
2753-
else
2754-
die_context = die.GetTypeLookupContext();
2755-
assert(!die_context.empty());
2756-
if (!query.ContextMatches(die_context))
2757-
return true; // Keep iterating over index types, context mismatch.
2758-
2759-
// Try to resolve the type.
27602729
if (Type *matching_type = ResolveType(die, true, true)) {
2761-
if (matching_type->IsTemplateType()) {
2730+
if (!query.GetSearchByMangledName() && matching_type->IsTemplateType()) {
27622731
// We have to watch out for case where we lookup a type by basename and
27632732
// it matches a template with simple template names. Like looking up
27642733
// "Foo" and if we have simple template names then we will match
@@ -2790,7 +2759,7 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
27902759
// With -gsimple-template-names, a templated type's DW_AT_name will not
27912760
// contain the template parameters. Try again stripping '<' and anything
27922761
// after, filtering out entries with template parameters that don't match.
2793-
if (!have_index_match) {
2762+
if (!have_index_match && !query.GetSearchByMangledName()) {
27942763
// Create a type matcher with a compiler context that is tuned for
27952764
// -gsimple-template-names. We will use this for the index lookup and the
27962765
// context matching, but will use the original "match" to insert matches
@@ -2804,23 +2773,6 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
28042773
// Copy our match's context and update the basename we are looking for
28052774
// so we can use this only to compare the context correctly.
28062775
m_index->GetTypesWithQuery(query_simple, [&](DWARFDIE die) {
2807-
// Check the language, but only if we have a language filter.
2808-
if (query.HasLanguage()) {
2809-
if (!query.LanguageMatches(GetLanguageFamily(*die.GetCU())))
2810-
return true; // Keep iterating over index types, language mismatch.
2811-
}
2812-
2813-
// Check the context matches
2814-
std::vector<lldb_private::CompilerContext> die_context;
2815-
if (query.GetModuleSearch())
2816-
die_context = die.GetDeclContext();
2817-
else
2818-
die_context = die.GetTypeLookupContext();
2819-
assert(!die_context.empty());
2820-
if (!query_simple.ContextMatches(die_context))
2821-
return true; // Keep iterating over index types, context mismatch.
2822-
2823-
// Try to resolve the type.
28242776
if (Type *matching_type = ResolveType(die, true, true)) {
28252777
ConstString name = matching_type->GetQualifiedName();
28262778
// We have found a type that still might not match due to template

0 commit comments

Comments
 (0)