Skip to content

Commit 38e1ac7

Browse files
committed
refactor: convert test to use split-file
1 parent 288b5f7 commit 38e1ac7

File tree

7 files changed

+207
-146
lines changed

7 files changed

+207
-146
lines changed

lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ struct CVTagRecord {
7272
return cvunion.Name;
7373
}
7474

75+
CompilerContextKind contextKind() const {
76+
if (m_kind == Struct || m_kind == Class)
77+
return CompilerContextKind::ClassOrStruct;
78+
if (m_kind == Enum)
79+
return CompilerContextKind::Enum;
80+
return CompilerContextKind::Union;
81+
}
82+
7583
private:
7684
CVTagRecord(llvm::codeview::ClassRecord &&c);
7785
CVTagRecord(llvm::codeview::UnionRecord &&u);

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

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,14 +1727,15 @@ void SymbolFileNativePDB::FindTypes(const lldb_private::TypeQuery &query,
17271727
m_type_base_names.GetValues(query.GetTypeBasename(), matches);
17281728

17291729
for (uint32_t match_idx : matches) {
1730-
TypeSP type_sp = GetOrCreateType(TypeIndex(match_idx));
1731-
if (!type_sp)
1730+
std::vector context = GetContextForType(TypeIndex(match_idx));
1731+
if (context.empty())
17321732
continue;
17331733

1734-
// We resolved a type. Get the fully qualified name to ensure it matches.
1735-
ConstString name = type_sp->GetQualifiedName();
1736-
TypeQuery type_match(name.GetStringRef(), TypeQueryOptions::e_exact_match);
1737-
if (query.ContextMatches(type_match.GetContextRef())) {
1734+
if (query.ContextMatches(context)) {
1735+
TypeSP type_sp = GetOrCreateType(TypeIndex(match_idx));
1736+
if (!type_sp)
1737+
continue;
1738+
17381739
results.InsertUnique(type_sp);
17391740
if (results.Done(query))
17401741
return;
@@ -2362,3 +2363,52 @@ SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) {
23622363
return std::nullopt;
23632364
return parent_iter->second;
23642365
}
2366+
2367+
std::vector<CompilerContext>
2368+
SymbolFileNativePDB::GetContextForType(TypeIndex ti) {
2369+
CVType type = m_index->tpi().getType(ti);
2370+
if (!IsTagRecord(type))
2371+
return {};
2372+
2373+
CVTagRecord tag = CVTagRecord::create(type);
2374+
2375+
std::optional<Type::ParsedName> parsed_name =
2376+
Type::GetTypeScopeAndBasename(tag.name());
2377+
if (!parsed_name)
2378+
return {{tag.contextKind(), ConstString(tag.name())}};
2379+
2380+
std::vector<CompilerContext> ctx;
2381+
// assume everything is a namespace at first
2382+
for (llvm::StringRef scope : parsed_name->scope) {
2383+
ctx.emplace_back(CompilerContextKind::Namespace, ConstString(scope));
2384+
}
2385+
// we know the kind of our own type
2386+
ctx.emplace_back(tag.contextKind(), ConstString(parsed_name->basename));
2387+
2388+
// try to find the kind of parents
2389+
for (auto &el : llvm::reverse(llvm::drop_end(ctx))) {
2390+
std::optional<TypeIndex> parent = GetParentType(ti);
2391+
if (!parent)
2392+
break;
2393+
2394+
ti = *parent;
2395+
type = m_index->tpi().getType(ti);
2396+
switch (type.kind()) {
2397+
case LF_CLASS:
2398+
case LF_STRUCTURE:
2399+
case LF_INTERFACE:
2400+
el.kind = CompilerContextKind::ClassOrStruct;
2401+
continue;
2402+
case LF_UNION:
2403+
el.kind = CompilerContextKind::Union;
2404+
continue;
2405+
case LF_ENUM:
2406+
el.kind = CompilerContextKind::Enum;
2407+
continue;
2408+
default:
2409+
break;
2410+
}
2411+
break;
2412+
}
2413+
return ctx;
2414+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ class SymbolFileNativePDB : public SymbolFileCommon {
258258

259259
void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr);
260260

261+
std::vector<CompilerContext> GetContextForType(llvm::codeview::TypeIndex ti);
262+
261263
llvm::BumpPtrAllocator m_allocator;
262264

263265
lldb::addr_t m_obj_load_address = 0;

lldb/source/Symbol/Type.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ bool TypeQuery::ContextMatches(
134134
if (ctx == ctx_end)
135135
return false; // Pattern too long.
136136

137-
if ((ctx->kind & CompilerContextKind::Namespace) ==
138-
CompilerContextKind::Namespace &&
139-
ctx->name.IsEmpty()) {
137+
if (ctx->kind == CompilerContextKind::Namespace && ctx->name.IsEmpty()) {
140138
// We're matching an anonymous namespace. These are optional, so we check
141139
// if the pattern expects an anonymous namespace.
142140
if (pat->name.IsEmpty() && (pat->kind & CompilerContextKind::Namespace) ==
@@ -166,9 +164,7 @@ bool TypeQuery::ContextMatches(
166164
auto should_skip = [this](const CompilerContext &ctx) {
167165
if (ctx.kind == CompilerContextKind::Module)
168166
return GetIgnoreModules();
169-
if ((ctx.kind & CompilerContextKind::Namespace) ==
170-
CompilerContextKind::Namespace &&
171-
ctx.name.IsEmpty())
167+
if (ctx.kind == CompilerContextKind::Namespace && ctx.name.IsEmpty())
172168
return !GetStrictNamespaces();
173169
return false;
174170
};
@@ -820,10 +816,12 @@ Type::GetTypeScopeAndBasename(llvm::StringRef name) {
820816
case ':':
821817
if (prev_is_colon && template_depth == 0) {
822818
llvm::StringRef scope_name = name.slice(name_begin, pos.index() - 1);
823-
// The itanium demangler uses this string to represent anonymous
819+
// The demanglers use these strings to represent anonymous
824820
// namespaces. Convert it to a more language-agnostic form (which is
825821
// also used in DWARF).
826-
if (scope_name == "(anonymous namespace)")
822+
if (scope_name == "(anonymous namespace)" ||
823+
scope_name == "`anonymous namespace'" ||
824+
scope_name == "`anonymous-namespace'")
827825
scope_name = "";
828826
result.scope.push_back(scope_name);
829827
name_begin = pos.index() + 1;

lldb/test/Shell/SymbolFile/NativePDB/Inputs/namespace-access.lldbinit

Lines changed: 0 additions & 18 deletions
This file was deleted.

lldb/test/Shell/SymbolFile/NativePDB/namespace-access.cpp

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)