Skip to content

Commit 51cecd3

Browse files
authored
[LLDB][NativePDB] Create simple types from function arguments and return types (#163621)
When creating all types in a compilation unit, simple types (~> primitive and pointer types) that were only used in function arguments or return types weren't created as LLDB `Type`s. With this PR, they're created when creating the function/method types. This makes it possible to run the `SymbolFile/PDB/typedefs.test` with both plugins.
1 parent 30f1004 commit 51cecd3

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ TypeSP SymbolFileNativePDB::CreateArrayType(PdbTypeSymId type_id,
754754
TypeSP SymbolFileNativePDB::CreateFunctionType(PdbTypeSymId type_id,
755755
const MemberFunctionRecord &mfr,
756756
CompilerType ct) {
757+
if (mfr.ReturnType.isSimple())
758+
GetOrCreateType(mfr.ReturnType);
759+
CreateSimpleArgumentListTypes(mfr.ArgumentList);
760+
757761
Declaration decl;
758762
return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
759763
LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
@@ -763,12 +767,33 @@ TypeSP SymbolFileNativePDB::CreateFunctionType(PdbTypeSymId type_id,
763767
TypeSP SymbolFileNativePDB::CreateProcedureType(PdbTypeSymId type_id,
764768
const ProcedureRecord &pr,
765769
CompilerType ct) {
770+
if (pr.ReturnType.isSimple())
771+
GetOrCreateType(pr.ReturnType);
772+
CreateSimpleArgumentListTypes(pr.ArgumentList);
773+
766774
Declaration decl;
767775
return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
768776
LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
769777
ct, lldb_private::Type::ResolveState::Full);
770778
}
771779

780+
void SymbolFileNativePDB::CreateSimpleArgumentListTypes(
781+
llvm::codeview::TypeIndex arglist_ti) {
782+
if (arglist_ti.isNoneType())
783+
return;
784+
785+
CVType arglist_cvt = m_index->tpi().getType(arglist_ti);
786+
if (arglist_cvt.kind() != LF_ARGLIST)
787+
return; // invalid debug info
788+
789+
ArgListRecord alr;
790+
llvm::cantFail(
791+
TypeDeserializer::deserializeAs<ArgListRecord>(arglist_cvt, alr));
792+
for (TypeIndex id : alr.getIndices())
793+
if (!id.isNoneType() && id.isSimple())
794+
GetOrCreateType(id);
795+
}
796+
772797
TypeSP SymbolFileNativePDB::CreateType(PdbTypeSymId type_id, CompilerType ct) {
773798
if (type_id.index.isSimple())
774799
return CreateSimpleType(type_id.index, ct);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class SymbolFileNativePDB : public SymbolFileCommon {
255255
VariableList &variables);
256256
size_t ParseVariablesForBlock(PdbCompilandSymId block_id);
257257

258+
void CreateSimpleArgumentListTypes(llvm::codeview::TypeIndex arglist_ti);
259+
258260
llvm::Expected<uint32_t> GetFileIndex(const CompilandIndexItem &cii,
259261
uint32_t file_id);
260262

lldb/test/Shell/SymbolFile/NativePDB/simple-types.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Test that simple types can be found
44
// RUN: %build --std=c++20 --nodefaultlib --compiler=clang-cl --arch=64 -o %t.exe -- %s
55
// RUN: lldb-test symbols %t.exe | FileCheck %s
6-
// RUN: lldb-test symbols %t.exe | FileCheck --check-prefix=FUNC-PARAMS %s
76

87
bool *PB;
98
bool &RB = *PB;
@@ -101,12 +100,14 @@ int main() {
101100
// CHECK-DAG: Type{{.*}} , name = "float", size = 4, compiler_type = 0x{{[0-9a-f]+}} float
102101
// CHECK-DAG: Type{{.*}} , name = "const float", size = 4, compiler_type = 0x{{[0-9a-f]+}} const float
103102

103+
// CHECK-DAG: Type{{.*}} , name = "double", size = 8, compiler_type = 0x{{[0-9a-f]+}} double
104+
104105
// CHECK-DAG: Type{{.*}} , name = "_Complex float", size = 4, compiler_type = 0x{{[0-9a-f]+}} _Complex float
105106
// CHECK-DAG: Type{{.*}} , name = "_Complex double", size = 8, compiler_type = 0x{{[0-9a-f]+}} _Complex double
106107

107-
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct1", size = 1, decl = simple-types.cpp:21, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct1 {
108-
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct2", size = 1, decl = simple-types.cpp:22, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct2 {
109-
// CHECK-DAG: Type{{.*}} , name = "MyStruct", size = 1, decl = simple-types.cpp:24, compiler_type = 0x{{[0-9a-f]+}} struct MyStruct {
108+
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct1", size = 1, decl = simple-types.cpp:20, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct1 {
109+
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct2", size = 1, decl = simple-types.cpp:21, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct2 {
110+
// CHECK-DAG: Type{{.*}} , name = "MyStruct", size = 1, decl = simple-types.cpp:23, compiler_type = 0x{{[0-9a-f]+}} struct MyStruct {
110111

111112
// CHECK-DAG: Type{{.*}} , size = 8, compiler_type = 0x{{[0-9a-f]+}} struct MyStruct *const
112113
// CHECK-DAG: Type{{.*}} , size = 8, compiler_type = 0x{{[0-9a-f]+}} const struct MyStruct *const
@@ -137,6 +138,3 @@ int main() {
137138
// CHECK-DAG: Type{{.*}} , size = 0, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct2 (char *)
138139

139140
// CHECK-DAG: Type{{.*}} , size = 8, compiler_type = 0x{{[0-9a-f]+}} long[2]
140-
141-
// double is used as a parameter to `PF`, but not created as an LLDB type
142-
// FUNC-PARAMS-NOT: Type{{.*}} , name = "double"

lldb/test/Shell/SymbolFile/PDB/typedefs.test

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
REQUIRES: system-windows, msvc
22
RUN: mkdir -p %t.dir
33
RUN: %build --compiler=msvc --arch=32 --nodefaultlib --output=%t.dir/SimpleTypesTest.cpp.typedefs.exe %S/Inputs/SimpleTypesTest.cpp
4-
RUN: lldb-test symbols %t.dir/SimpleTypesTest.cpp.typedefs.exe | FileCheck %s
4+
RUN: env LLDB_USE_NATIVE_PDB_READER=0 lldb-test symbols %t.dir/SimpleTypesTest.cpp.typedefs.exe | FileCheck %s
5+
RUN: env LLDB_USE_NATIVE_PDB_READER=1 lldb-test symbols %t.dir/SimpleTypesTest.cpp.typedefs.exe | FileCheck %s
56

67
; Generate 32-bit target
78

@@ -13,7 +14,7 @@ RUN: lldb-test symbols %t.dir/SimpleTypesTest.cpp.typedefs.exe | FileCheck %s
1314
; both of them is the same.
1415

1516
CHECK: Module [[MOD:.*]]
16-
CHECK: SymbolFile pdb ([[MOD]])
17+
CHECK: SymbolFile {{(native-)?}}pdb ([[MOD]])
1718
CHECK-DAG: name = "char32_t", size = 4, compiler_type = {{.*}} char32_t
1819
CHECK-DAG: name = "char16_t", size = 2, compiler_type = {{.*}} char16_t
1920
CHECK-DAG: Type{{.*}} , name = "unsigned long", size = 4, compiler_type = {{.*}} unsigned long
@@ -23,7 +24,7 @@ CHECK-DAG: Type{{.*}} , size = 40, compiler_type = {{.*}} unsigned long[10]
2324
CHECK-DAG: Type{{.*}} , name = "double", size = 8, compiler_type = {{.*}} double
2425
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} double *
2526
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} double *&
26-
CHECK-DAG: Type{{.*}} , name = "RefTypedef", compiler_type = {{.*}} typedef RefTypedef
27+
CHECK-DAG: Type{{.*}} , name = "RefTypedef"{{(, size = 4)?}}, compiler_type = {{.*}} typedef RefTypedef
2728

2829
CHECK-DAG: Type{{.*}} , name = "wchar_t", size = 2, compiler_type = {{.*}} wchar_t
2930

@@ -37,23 +38,23 @@ CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} short *
3738
CHECK-DAG: Type{{.*}} , name = "const double", size = 8, compiler_type = {{.*}} const double
3839
CHECK-DAG: Type{{.*}} , name = "volatile bool", size = 1, compiler_type = {{.*}} volatile _Bool
3940
CHECK-DAG: Type{{.*}} , name = "long long", size = 8, compiler_type = {{.*}} long long
40-
CHECK-DAG: Type{{.*}} , compiler_type = {{.*}} long long (int &, unsigned char **, short *, const double, volatile _Bool)
41-
CHECK-DAG: Type{{.*}} , name = "FuncPtrTypedef", compiler_type = {{.*}} typedef FuncPtrTypedef
41+
CHECK-DAG: Type{{.*}} {{(, size = 0)?}}, compiler_type = {{.*}} long long (int &, unsigned char **, short *, const double, volatile _Bool)
42+
CHECK-DAG: Type{{.*}} , name = "FuncPtrTypedef"{{(, size = 4)?}}, compiler_type = {{.*}} typedef FuncPtrTypedef
4243

43-
CHECK-DAG: Type{{.*}} , name = "void", compiler_type = {{.*}} void
44+
CHECK-DAG: Type{{.*}} , name = "void"{{(, size = 0)?}}, compiler_type = {{.*}} void
4445
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} void *
4546
CHECK-DAG: Type{{.*}} , name = "long", size = 4, compiler_type = {{.*}} long
4647
CHECK-DAG: Type{{.*}} , name = "unsigned short", size = 2, compiler_type = {{.*}} unsigned short
47-
CHECK-DAG: Type{{.*}} , name = "unsigned int", size = 4, compiler_type = {{.*}} unsigned int
48+
CHECK-DAG: Type{{.*}} , name = "unsigned{{( int)?}}", size = 4, compiler_type = {{.*}} unsigned int
4849
CHECK-DAG: Type{{.*}} , name = "char", size = 1, compiler_type = {{.*}} char
4950
CHECK-DAG: Type{{.*}} , name = "signed char", size = 1, compiler_type = {{.*}} signed char
50-
CHECK-DAG: Type{{.*}} , compiler_type = {{.*}} char (void *, long, unsigned short, unsigned int, ...)
51+
CHECK-DAG: Type{{.*}} {{(, size = 0)?}}, compiler_type = {{.*}} char (void *, long, unsigned short, unsigned int, ...)
5152
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} char (*)(void *, long, unsigned short, unsigned int, ...)
52-
CHECK-DAG: Type{{.*}} , name = "VarArgsFuncTypedef", compiler_type = {{.*}} typedef VarArgsFuncTypedef
53+
CHECK-DAG: Type{{.*}} , name = "VarArgsFuncTypedef"{{(, size = 4)?}}, compiler_type = {{.*}} typedef VarArgsFuncTypedef
5354

5455
CHECK-DAG: Type{{.*}} , name = "float", size = 4, compiler_type = {{.*}} float
55-
CHECK-DAG: Type{{.*}} , compiler_type = {{.*}} float (...)
56+
CHECK-DAG: Type{{.*}} {{(, size = 0)?}}, compiler_type = {{.*}} float (...)
5657
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} float (*)(...)
57-
CHECK-DAG: Type{{.*}} , name = "VarArgsFuncTypedefA", compiler_type = {{.*}} typedef VarArgsFuncTypedefA
58+
CHECK-DAG: Type{{.*}} , name = "VarArgsFuncTypedefA"{{(, size = 4)?}}, compiler_type = {{.*}} typedef VarArgsFuncTypedefA
5859

5960
CHECK-DAG: {{^[0-9A-F]+}}: CompileUnit{{[{]0x[0-9a-f]+[}]}}, language = "c++", file = '{{.*}}\SimpleTypesTest.cpp'

0 commit comments

Comments
 (0)