nerix 852cc9200f
[LLDB][NativePDB] Implement FindNamespace (#151950)
`FindNamespace` was not implemented for `SymbolFileNativePDB`. Without
it, it wasn't possible to lookup items through namespaces when
evaluating expressions.

This is mostly the same as in
[SymbolFilePDB](f1eb869bae/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (L1664-L1696))
as well as
[PDBAstParser](f1eb869bae/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp (L1126-L1150)):
The AST parser/builder saves the created namespaces in a map to lookup
when a namespace is requested.

This is working towards making
[Shell/SymbolFile/PDB/expressions.test](f1eb869bae/lldb/test/Shell/SymbolFile/PDB/expressions.test)
pass with the native PDB plugin.
2025-08-05 11:10:27 +01:00

161 lines
3.6 KiB
Plaintext

# REQUIRES: target-windows
# Test namespace lookup.
# RUN: split-file %s %t
# RUN: %build --nodefaultlib -o %t.exe -- %t/main.cpp
# RUN: %lldb -f %t.exe -s \
# RUN: %t/commands.input 2>&1 | FileCheck %s
#--- main.cpp
struct S {
char a[1];
};
namespace Outer {
struct S {
char a[2];
};
namespace Inner1 {
struct S {
char a[3];
};
namespace Inner2 {
struct S {
char a[4];
};
} // namespace Inner2
} // namespace Inner1
namespace Inner2 {
struct S {
char a[5];
};
} // namespace Inner2
namespace {
struct A {
char a[6];
};
} // namespace
} // namespace Outer
namespace {
struct A {
char a[7];
};
} // namespace
int main(int argc, char **argv) {
S s;
Outer::S os;
Outer::Inner1::S oi1s;
Outer::Inner1::Inner2::S oi1i2s;
Outer::Inner2::S oi2s;
A a1;
Outer::A a2;
return sizeof(s) + sizeof(os) + sizeof(oi1s) + sizeof(oi1i2s) + sizeof(oi2s) + sizeof(a1) + sizeof(a2);
}
#--- commands.input
b main
r
type lookup S
type lookup ::S
type lookup Outer::S
type lookup Outer::Inner1::S
type lookup Inner1::S
type lookup Outer::Inner1::Inner2::S
type lookup Inner2::S
type lookup Outer::Inner2::S
type lookup Outer::A
type lookup A
type lookup ::A
# Test that Clang can find the namespaces as well
expr sizeof(S)
expr sizeof(::S)
expr sizeof(Outer::S)
expr sizeof(Outer::Inner1::S)
expr sizeof(Inner1::S)
expr sizeof(Outer::Inner1::Inner2::S)
expr sizeof(Outer::Inner2::S)
expr sizeof(Outer::A)
expr sizeof(A)
expr sizeof(::A)
quit
# CHECK: (lldb) type lookup S
# CHECK: struct S {
# CHECK: struct S {
# CHECK: struct S {
# CHECK: struct S {
# CHECK: struct S {
# CHECK: }
# CHECK-NEXT: (lldb) type lookup ::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[1];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Outer::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[2];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Outer::Inner1::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[3];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Inner1::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[3];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Outer::Inner1::Inner2::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[4];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Inner2::S
# CHECK-NEXT: struct S {
# CHECK: struct S {
# CHECK: }
# CHECK-NEXT: (lldb) type lookup Outer::Inner2::S
# CHECK-NEXT: struct S {
# CHECK-NEXT: char a[5];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup Outer::A
# CHECK-NEXT: struct A {
# CHECK-NEXT: char a[6];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) type lookup A
# CHECK-NEXT: struct A {
# CHECK: struct A {
# CHECK: }
# CHECK-NEXT: (lldb) type lookup ::A
# CHECK-NEXT: struct A {
# CHECK-NEXT: char a[7];
# CHECK-NEXT: }
# CHECK-NEXT: (lldb) expr sizeof(S)
# CHECK-NEXT: (__size_t) $0 = 1
# CHECK-NEXT: (lldb) expr sizeof(::S)
# CHECK-NEXT: (__size_t) $1 = 1
# CHECK-NEXT: (lldb) expr sizeof(Outer::S)
# CHECK-NEXT: (__size_t) $2 = 2
# CHECK-NEXT: (lldb) expr sizeof(Outer::Inner1::S)
# CHECK-NEXT: (__size_t) $3 = 3
# CHECK-NEXT: (lldb) expr sizeof(Inner1::S)
# CHECK-NEXT: (__size_t) $4 = 3
# CHECK-NEXT: (lldb) expr sizeof(Outer::Inner1::Inner2::S)
# CHECK-NEXT: (__size_t) $5 = 4
# CHECK-NEXT: (lldb) expr sizeof(Outer::Inner2::S)
# CHECK-NEXT: (__size_t) $6 = 5
# CHECK-NEXT: (lldb) expr sizeof(Outer::A)
# CHECK-NEXT: (__size_t) $7 = 6
# CHECK-NEXT: (lldb) expr sizeof(A)
# CHECK-NEXT: (__size_t) $8 = 7
# CHECK-NEXT: (lldb) expr sizeof(::A)
# CHECK-NEXT: (__size_t) $9 = 7