Skip to content

Commit eab35bd

Browse files
committed
[lldb] Extend FindTypes to optionally search by mangled type name
Swift types have mangled type names. This adds functionality to look up those types through the FindTypes API by searching for the mangled type name instead of the regular name.
1 parent dca43a1 commit eab35bd

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

lldb/include/lldb/Symbol/Type.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ FLAGS_ENUM(TypeQueryOptions){
8484
/// matching type is found. When false, the type query should find all
8585
/// matching types.
8686
e_find_one = (1u << 4),
87+
// If set, treat TypeQuery::m_name as a mangled name that should be
88+
// searched.
89+
e_search_by_mangled_name = (1u << 5),
8790
};
8891
LLDB_MARK_AS_BITMASK_ENUM(TypeQueryOptions)
8992

@@ -300,6 +303,12 @@ class TypeQuery {
300303
m_options &= ~e_find_one;
301304
}
302305

306+
/// Returns true if the type query is supposed to treat the name to be
307+
/// searched as a mangled name.
308+
bool GetSearchByMangledName() const {
309+
return (m_options & e_search_by_mangled_name) != 0;
310+
}
311+
303312
/// Access the internal compiler context array.
304313
///
305314
/// Clients can use this to populate the context manually.

lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,11 +1032,17 @@ void SymbolFileCTF::FindTypes(const lldb_private::TypeQuery &match,
10321032

10331033
ConstString name = match.GetTypeBasename();
10341034
for (TypeSP type_sp : GetTypeList().Types()) {
1035-
if (type_sp && type_sp->GetName() == name) {
1036-
results.InsertUnique(type_sp);
1037-
if (results.Done(match))
1038-
return;
1039-
}
1035+
if (!type_sp)
1036+
continue;
1037+
auto type_name =
1038+
match.GetSearchByMangledName()
1039+
? type_sp->GetForwardCompilerType().GetMangledTypeName()
1040+
: type_sp->GetName();
1041+
if (type_name != name)
1042+
continue;
1043+
results.InsertUnique(type_sp);
1044+
if (results.Done(match))
1045+
return;
10401046
}
10411047
}
10421048

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,15 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
27582758
return true; // Keep iterating over index types, language mismatch.
27592759
}
27602760

2761+
// Since mangled names are unique, we only need to check if the names are
2762+
// the same.
2763+
if (query.GetSearchByMangledName()) {
2764+
if (die.GetMangledName() == query.GetTypeBasename().GetStringRef())
2765+
if (Type *matching_type = ResolveType(die, true, true))
2766+
results.InsertUnique(matching_type->shared_from_this());
2767+
return !results.Done(query); // Keep iterating if we aren't done.
2768+
}
2769+
27612770
// Check the context matches
27622771
std::vector<lldb_private::CompilerContext> die_context;
27632772
if (query.GetModuleSearch())

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,10 @@ void SymbolFileNativePDB::FindTypes(const lldb_private::TypeQuery &query,
17351735
continue;
17361736

17371737
// We resolved a type. Get the fully qualified name to ensure it matches.
1738-
ConstString name = type_sp->GetQualifiedName();
1738+
ConstString name =
1739+
query.GetSearchByMangledName()
1740+
? type_sp->GetForwardCompilerType().GetMangledTypeName()
1741+
: type_sp->GetQualifiedName();
17391742
TypeQuery type_match(name.GetStringRef(), TypeQueryOptions::e_exact_match);
17401743
if (query.ContextMatches(type_match.GetContextRef())) {
17411744
results.InsertUnique(type_sp);

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,10 @@ void SymbolFilePDB::FindTypes(const lldb_private::TypeQuery &query,
15611561
if (iter == m_types.end())
15621562
continue;
15631563
// We resolved a type. Get the fully qualified name to ensure it matches.
1564-
ConstString name = iter->second->GetQualifiedName();
1564+
ConstString name =
1565+
query.GetSearchByMangledName()
1566+
? iter->second->GetForwardCompilerType().GetMangledTypeName()
1567+
: iter->second->GetQualifiedName();
15651568
TypeQuery type_match(name.GetStringRef(), TypeQueryOptions::e_exact_match);
15661569
if (query.ContextMatches(type_match.GetContextRef())) {
15671570
type_results.InsertUnique(iter->second);

0 commit comments

Comments
 (0)