Skip to content

Commit 4b89704

Browse files
authored
[LLDB][NativePDB] Consolidate simple types (llvm#163209)
This aligns the simple types created by the native plugin with the ones from DIA as well as LLVM and the original cvdump. - A few type names weren't handled when creating the LLDB `Type` name (e.g. `short`) - 64-bit integers were created as `(u)int64_t` and are now created as `(unsigned) long long` (matches DIA) - 128-bit integers (only supported by clang-cl) weren't created as types (they have `SimpleTypeKind::(U)Int128Oct`) - All complex types had the same name - now they have `_Complex <float-type>` Some types like `SimpleTypeKind::Float48` can't be tested because they can't be created in C++.
1 parent f29f237 commit 4b89704

File tree

4 files changed

+101
-27
lines changed

4 files changed

+101
-27
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,17 +946,21 @@ lldb_private::npdb::GetCompilerTypeForSimpleKind(SimpleTypeKind kind) {
946946
case SimpleTypeKind::Complex64:
947947
return lldb::eBasicTypeDoubleComplex;
948948
case SimpleTypeKind::Complex32:
949+
case SimpleTypeKind::Complex32PartialPrecision:
949950
return lldb::eBasicTypeFloatComplex;
950-
case SimpleTypeKind::Float128:
951951
case SimpleTypeKind::Float80:
952952
return lldb::eBasicTypeLongDouble;
953+
case SimpleTypeKind::Float128:
954+
return lldb::eBasicTypeFloat128;
953955
case SimpleTypeKind::Float64:
954956
return lldb::eBasicTypeDouble;
955957
case SimpleTypeKind::Float32:
958+
case SimpleTypeKind::Float32PartialPrecision:
956959
return lldb::eBasicTypeFloat;
957960
case SimpleTypeKind::Float16:
958961
return lldb::eBasicTypeHalf;
959962
case SimpleTypeKind::Int128:
963+
case SimpleTypeKind::Int128Oct:
960964
return lldb::eBasicTypeInt128;
961965
case SimpleTypeKind::Int64:
962966
case SimpleTypeKind::Int64Quad:
@@ -967,6 +971,7 @@ lldb_private::npdb::GetCompilerTypeForSimpleKind(SimpleTypeKind kind) {
967971
case SimpleTypeKind::Int16Short:
968972
return lldb::eBasicTypeShort;
969973
case SimpleTypeKind::UInt128:
974+
case SimpleTypeKind::UInt128Oct:
970975
return lldb::eBasicTypeUnsignedInt128;
971976
case SimpleTypeKind::UInt64:
972977
case SimpleTypeKind::UInt64Quad:
@@ -985,16 +990,27 @@ lldb_private::npdb::GetCompilerTypeForSimpleKind(SimpleTypeKind kind) {
985990
return lldb::eBasicTypeVoid;
986991
case SimpleTypeKind::WideCharacter:
987992
return lldb::eBasicTypeWChar;
988-
default:
993+
994+
// Not supported.
995+
case SimpleTypeKind::Float48:
996+
case SimpleTypeKind::Complex16:
997+
case SimpleTypeKind::Complex48:
998+
case SimpleTypeKind::Complex128:
999+
case SimpleTypeKind::NotTranslated:
1000+
case SimpleTypeKind::None:
9891001
return lldb::eBasicTypeInvalid;
9901002
}
1003+
return lldb::eBasicTypeInvalid;
9911004
}
9921005

9931006
size_t lldb_private::npdb::GetTypeSizeForSimpleKind(SimpleTypeKind kind) {
9941007
switch (kind) {
9951008
case SimpleTypeKind::Boolean128:
1009+
case SimpleTypeKind::Complex128:
9961010
case SimpleTypeKind::Int128:
1011+
case SimpleTypeKind::Int128Oct:
9971012
case SimpleTypeKind::UInt128:
1013+
case SimpleTypeKind::UInt128Oct:
9981014
case SimpleTypeKind::Float128:
9991015
return 16;
10001016
case SimpleTypeKind::Complex80:
@@ -1008,10 +1024,15 @@ size_t lldb_private::npdb::GetTypeSizeForSimpleKind(SimpleTypeKind kind) {
10081024
case SimpleTypeKind::Int64:
10091025
case SimpleTypeKind::Int64Quad:
10101026
return 8;
1027+
case SimpleTypeKind::Complex48:
1028+
case SimpleTypeKind::Float48:
1029+
return 6;
10111030
case SimpleTypeKind::Boolean32:
10121031
case SimpleTypeKind::Character32:
10131032
case SimpleTypeKind::Complex32:
1033+
case SimpleTypeKind::Complex32PartialPrecision:
10141034
case SimpleTypeKind::Float32:
1035+
case SimpleTypeKind::Float32PartialPrecision:
10151036
case SimpleTypeKind::Int32:
10161037
case SimpleTypeKind::Int32Long:
10171038
case SimpleTypeKind::UInt32Long:
@@ -1020,6 +1041,7 @@ size_t lldb_private::npdb::GetTypeSizeForSimpleKind(SimpleTypeKind kind) {
10201041
return 4;
10211042
case SimpleTypeKind::Boolean16:
10221043
case SimpleTypeKind::Character16:
1044+
case SimpleTypeKind::Complex16:
10231045
case SimpleTypeKind::Float16:
10241046
case SimpleTypeKind::Int16:
10251047
case SimpleTypeKind::Int16Short:
@@ -1035,10 +1057,13 @@ size_t lldb_private::npdb::GetTypeSizeForSimpleKind(SimpleTypeKind kind) {
10351057
case SimpleTypeKind::SByte:
10361058
case SimpleTypeKind::Character8:
10371059
return 1;
1060+
10381061
case SimpleTypeKind::Void:
1039-
default:
1062+
case SimpleTypeKind::None:
1063+
case SimpleTypeKind::NotTranslated:
10401064
return 0;
10411065
}
1066+
return 0;
10421067
}
10431068

10441069
PdbTypeSymId lldb_private::npdb::GetBestPossibleDecl(PdbTypeSymId id,

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

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,24 @@ static bool IsFunctionEpilogue(const CompilandIndexItem &cci,
152152
return false;
153153
}
154154

155+
// See llvm::codeview::TypeIndex::simpleTypeName as well as strForPrimitiveTi
156+
// from the original pdbdump:
157+
// https://github.com/microsoft/microsoft-pdb/blob/805655a28bd8198004be2ac27e6e0290121a5e89/pdbdump/pdbdump.cpp#L1896-L1974
158+
//
159+
// For 64bit integers we use "long long" like DIA instead of "__int64".
155160
static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind) {
156161
switch (kind) {
157162
case SimpleTypeKind::Boolean128:
158-
case SimpleTypeKind::Boolean16:
159-
case SimpleTypeKind::Boolean32:
163+
return "__bool128";
160164
case SimpleTypeKind::Boolean64:
165+
return "__bool64";
166+
case SimpleTypeKind::Boolean32:
167+
return "__bool32";
168+
case SimpleTypeKind::Boolean16:
169+
return "__bool16";
161170
case SimpleTypeKind::Boolean8:
162171
return "bool";
172+
163173
case SimpleTypeKind::Byte:
164174
case SimpleTypeKind::UnsignedCharacter:
165175
return "unsigned char";
@@ -168,57 +178,81 @@ static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind) {
168178
case SimpleTypeKind::SignedCharacter:
169179
case SimpleTypeKind::SByte:
170180
return "signed char";
171-
case SimpleTypeKind::Character16:
172-
return "char16_t";
173181
case SimpleTypeKind::Character32:
174182
return "char32_t";
183+
case SimpleTypeKind::Character16:
184+
return "char16_t";
175185
case SimpleTypeKind::Character8:
176186
return "char8_t";
187+
188+
case SimpleTypeKind::Complex128:
189+
return "_Complex __float128";
177190
case SimpleTypeKind::Complex80:
191+
return "_Complex long double";
178192
case SimpleTypeKind::Complex64:
193+
return "_Complex double";
194+
case SimpleTypeKind::Complex48:
195+
return "_Complex __float48";
179196
case SimpleTypeKind::Complex32:
180-
return "complex";
197+
case SimpleTypeKind::Complex32PartialPrecision:
198+
return "_Complex float";
199+
case SimpleTypeKind::Complex16:
200+
return "_Complex _Float16";
201+
181202
case SimpleTypeKind::Float128:
203+
return "__float128";
182204
case SimpleTypeKind::Float80:
183205
return "long double";
184206
case SimpleTypeKind::Float64:
185207
return "double";
208+
case SimpleTypeKind::Float48:
209+
return "__float48";
186210
case SimpleTypeKind::Float32:
211+
case SimpleTypeKind::Float32PartialPrecision:
187212
return "float";
188213
case SimpleTypeKind::Float16:
189-
return "single";
214+
return "_Float16";
215+
216+
case SimpleTypeKind::Int128Oct:
190217
case SimpleTypeKind::Int128:
191218
return "__int128";
192219
case SimpleTypeKind::Int64:
193220
case SimpleTypeKind::Int64Quad:
194-
return "int64_t";
221+
return "long long";
222+
case SimpleTypeKind::Int32Long:
223+
return "long";
195224
case SimpleTypeKind::Int32:
196225
return "int";
197226
case SimpleTypeKind::Int16:
227+
case SimpleTypeKind::Int16Short:
198228
return "short";
229+
230+
case SimpleTypeKind::UInt128Oct:
199231
case SimpleTypeKind::UInt128:
200232
return "unsigned __int128";
201233
case SimpleTypeKind::UInt64:
202234
case SimpleTypeKind::UInt64Quad:
203-
return "uint64_t";
204-
case SimpleTypeKind::HResult:
205-
return "HRESULT";
235+
return "unsigned long long";
206236
case SimpleTypeKind::UInt32:
207237
return "unsigned";
208238
case SimpleTypeKind::UInt16:
209239
case SimpleTypeKind::UInt16Short:
210240
return "unsigned short";
211-
case SimpleTypeKind::Int32Long:
212-
return "long";
213241
case SimpleTypeKind::UInt32Long:
214242
return "unsigned long";
243+
244+
case SimpleTypeKind::HResult:
245+
return "HRESULT";
215246
case SimpleTypeKind::Void:
216247
return "void";
217248
case SimpleTypeKind::WideCharacter:
218249
return "wchar_t";
219-
default:
250+
251+
case SimpleTypeKind::None:
252+
case SimpleTypeKind::NotTranslated:
220253
return "";
221254
}
255+
return "";
222256
}
223257

224258
static bool IsClassRecord(TypeLeafKind kind) {
@@ -598,8 +632,8 @@ lldb::TypeSP SymbolFileNativePDB::CreateSimpleType(TypeIndex ti,
598632
uint64_t uid = toOpaqueUid(PdbTypeSymId(ti, false));
599633
if (ti == TypeIndex::NullptrT()) {
600634
Declaration decl;
601-
return MakeType(uid, ConstString("std::nullptr_t"), 0, nullptr,
602-
LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
635+
return MakeType(uid, ConstString("decltype(nullptr)"), std::nullopt,
636+
nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
603637
Type::ResolveState::Full);
604638
}
605639

lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,12 @@ main: # @main
578578
# CHECK: (lldb) image lookup -a 0x14000104e -v
579579
# CHECK: LineEntry: [0x000000014000104e-0x0000000140001050): C:\src\test\a.cpp:1004
580580
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001011-0x0000000140001050), name="main"
581-
# CHECK-NEXT: Variable: id = {{.*}}, name = "simple_type1", type = "int64_t", valid ranges = <block>, location = [0x000000014000104e, 0x000000014000104f) -> DW_OP_reg26 XMM9, DW_OP_piece 0x4, DW_OP_reg24 XMM7, DW_OP_piece 0x4
581+
# CHECK-NEXT: Variable: id = {{.*}}, name = "simple_type1", type = "long long", valid ranges = <block>, location = [0x000000014000104e, 0x000000014000104f) -> DW_OP_reg26 XMM9, DW_OP_piece 0x4, DW_OP_reg24 XMM7, DW_OP_piece 0x4
582582
# CHECK-EMPTY:
583583
# CHECK: (lldb) image lookup -a 0x14000104f -v
584584
# CHECK: LineEntry: [0x000000014000104e-0x0000000140001050): C:\src\test\a.cpp:1004
585585
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001011-0x0000000140001050), name="main"
586-
# CHECK-NEXT: Variable: id = {{.*}}, name = "simple_type1", type = "int64_t", valid ranges = <block>, location = [0x000000014000104f, 0x0000000140001050) -> DW_OP_reg26 XMM9, DW_OP_piece 0x4, DW_OP_piece 0x4
586+
# CHECK-NEXT: Variable: id = {{.*}}, name = "simple_type1", type = "long long", valid ranges = <block>, location = [0x000000014000104f, 0x0000000140001050) -> DW_OP_reg26 XMM9, DW_OP_piece 0x4, DW_OP_piece 0x4
587587
# CHECK-EMPTY:
588588

589589
.Ltmp26:

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,28 @@ int main() {
5858

5959
MyStruct my_struct;
6060

61+
_Float16 f16;
62+
63+
_Complex float cf;
64+
_Complex double cd;
65+
66+
__int128 i128;
67+
unsigned __int128 ui128;
68+
6169
decltype(nullptr) np;
6270
}
6371

64-
// CHECK-DAG: Type{{.*}} , name = "std::nullptr_t", size = 0, compiler_type = 0x{{[0-9a-f]+}} nullptr_t
72+
// CHECK-DAG: Type{{.*}} , name = "decltype(nullptr)", compiler_type = 0x{{[0-9a-f]+}} nullptr_t
6573

6674
// CHECK-DAG: Type{{.*}} , name = "bool", size = 1, compiler_type = 0x{{[0-9a-f]+}} _Bool
6775
// CHECK-DAG: Type{{.*}} , name = "char", size = 1, compiler_type = 0x{{[0-9a-f]+}} char
6876
// CHECK-DAG: Type{{.*}} , name = "unsigned char", size = 1, compiler_type = 0x{{[0-9a-f]+}} unsigned char
6977
// CHECK-DAG: Type{{.*}} , name = "char8_t", size = 1, compiler_type = 0x{{[0-9a-f]+}} char8_t
7078

71-
// CHECK-DAG: Type{{.*}} , size = 2, compiler_type = 0x{{[0-9a-f]+}} short
72-
// CHECK-DAG: Type{{.*}} , name = "const volatile ", size = 2, compiler_type = 0x{{[0-9a-f]+}} const volatile short
73-
// CHECK-DAG: Type{{.*}} , name = "const ", size = 2, compiler_type = 0x{{[0-9a-f]+}} const short
74-
// CHECK-DAG: Type{{.*}} , name = "volatile ", size = 2, compiler_type = 0x{{[0-9a-f]+}} volatile short
79+
// CHECK-DAG: Type{{.*}} , name = "short", size = 2, compiler_type = 0x{{[0-9a-f]+}} short
80+
// CHECK-DAG: Type{{.*}} , name = "const volatile short", size = 2, compiler_type = 0x{{[0-9a-f]+}} const volatile short
81+
// CHECK-DAG: Type{{.*}} , name = "const short", size = 2, compiler_type = 0x{{[0-9a-f]+}} const short
82+
// CHECK-DAG: Type{{.*}} , name = "volatile short", size = 2, compiler_type = 0x{{[0-9a-f]+}} volatile short
7583

7684
// CHECK-DAG: Type{{.*}} , name = "unsigned short", size = 2, compiler_type = 0x{{[0-9a-f]+}} unsigned short
7785
// CHECK-DAG: Type{{.*}} , name = "wchar_t", size = 2, compiler_type = 0x{{[0-9a-f]+}} wchar_t
@@ -83,12 +91,19 @@ int main() {
8391
// CHECK-DAG: Type{{.*}} , name = "unsigned long", size = 4, compiler_type = 0x{{[0-9a-f]+}} unsigned long
8492
// CHECK-DAG: Type{{.*}} , name = "char32_t", size = 4, compiler_type = 0x{{[0-9a-f]+}} char32_t
8593

86-
// CHECK-DAG: Type{{.*}} , name = "int64_t", size = 8, compiler_type = 0x{{[0-9a-f]+}} long long
87-
// CHECK-DAG: Type{{.*}} , name = "uint64_t", size = 8, compiler_type = 0x{{[0-9a-f]+}} unsigned long long
94+
// CHECK-DAG: Type{{.*}} , name = "long long", size = 8, compiler_type = 0x{{[0-9a-f]+}} long long
95+
// CHECK-DAG: Type{{.*}} , name = "unsigned long long", size = 8, compiler_type = 0x{{[0-9a-f]+}} unsigned long long
8896

97+
// CHECK-DAG: Type{{.*}} , name = "__int128", size = 16, compiler_type = 0x{{[0-9a-f]+}} __int128
98+
// CHECK-DAG: Type{{.*}} , name = "unsigned __int128", size = 16, compiler_type = 0x{{[0-9a-f]+}} unsigned __int128
99+
100+
// CHECK-DAG: Type{{.*}} , name = "_Float16", size = 2, compiler_type = 0x{{[0-9a-f]+}} __fp16
89101
// CHECK-DAG: Type{{.*}} , name = "float", size = 4, compiler_type = 0x{{[0-9a-f]+}} float
90102
// CHECK-DAG: Type{{.*}} , name = "const float", size = 4, compiler_type = 0x{{[0-9a-f]+}} const float
91103

104+
// CHECK-DAG: Type{{.*}} , name = "_Complex float", size = 4, compiler_type = 0x{{[0-9a-f]+}} _Complex float
105+
// CHECK-DAG: Type{{.*}} , name = "_Complex double", size = 8, compiler_type = 0x{{[0-9a-f]+}} _Complex double
106+
92107
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct1", size = 1, decl = simple-types.cpp:21, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct1 {
93108
// CHECK-DAG: Type{{.*}} , name = "ReturnedStruct2", size = 1, decl = simple-types.cpp:22, compiler_type = 0x{{[0-9a-f]+}} struct ReturnedStruct2 {
94109
// CHECK-DAG: Type{{.*}} , name = "MyStruct", size = 1, decl = simple-types.cpp:24, compiler_type = 0x{{[0-9a-f]+}} struct MyStruct {

0 commit comments

Comments
 (0)