Skip to content

Commit 4625c8f

Browse files
authored
[LLDB][NativePDB] Add modifiers to modified type name (#159296)
When creating LLDB types from `LF_MODIFIER` records, the type name of the modified type was used. This didn't include the modifiers (`const`/`volatile`/`__unaligned`). With this PR, they're included. The DIA plugin had a test for this. That test also assumed that function types had a name. I removed that check here, because function/procedure types themselves in PDB don't have a name: ``` 0x1015 | LF_ARGLIST [size = 20, hash = 0xBCB6] 0x0074 (int): `int` 0x1013: `int* __restrict` 0x1014: `int& __restrict` 0x1016 | LF_PROCEDURE [size = 16, hash = 0x3F611] return type = 0x0003 (void), # args = 3, param list = 0x1015 calling conv = cdecl, options = None ``` I assume DIA gets the name from the function symbol itself. In the native plugin, that name isn't included and multiple functions with the same signature will reuse one type, whereas DIA would create a new type for each function. The [Shell/SymbolFile/PDB/func-symbols.test](https://github.com/llvm/llvm-project/blob/b29c7ded31d81ca47aed0157c543c8b6a0f5866c/lldb/test/Shell/SymbolFile/PDB/func-symbols.test) also relies on this.
1 parent c5062d7 commit 4625c8f

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,18 @@ lldb::TypeSP SymbolFileNativePDB::CreateModifierType(PdbTypeSymId type_id,
549549
TpiStream &stream = m_index->tpi();
550550

551551
std::string name;
552+
553+
if ((mr.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
554+
name += "const ";
555+
if ((mr.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
556+
name += "volatile ";
557+
if ((mr.Modifiers & ModifierOptions::Unaligned) != ModifierOptions::None)
558+
name += "__unaligned ";
559+
552560
if (mr.ModifiedType.isSimple())
553-
name = std::string(GetSimpleTypeName(mr.ModifiedType.getSimpleKind()));
561+
name += GetSimpleTypeName(mr.ModifiedType.getSimpleKind());
554562
else
555-
name = computeTypeName(stream.typeCollection(), mr.ModifiedType);
563+
name += computeTypeName(stream.typeCollection(), mr.ModifiedType);
556564
Declaration decl;
557565
lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType);
558566

lldb/test/Shell/SymbolFile/NativePDB/inline_sites.test

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
# CHECK: LineEntry: [0x0000000140001004-0x000000014000100c): /tmp/a.h:5
7575
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
7676
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = <empty>, decl =
77-
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
77+
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
7878
# CHECK-NEXT: Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = <block>, location = [0x0000000140001000, 0x000000014000102d) -> DW_OP_reg26 XMM9
7979
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
80-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
80+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
8181

8282
# CHECK-LABEL: (lldb) image lookup -a 0x140001010 -v
8383
# CHECK: Summary: {{.*}}`main + 16 [inlined] Namespace1::foo + 12 at a.h:7
@@ -88,10 +88,10 @@
8888
# CHECK: LineEntry: [0x0000000140001010-0x0000000140001018): /tmp/a.h:7
8989
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
9090
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = <empty>, decl =
91-
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
91+
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
9292
# CHECK-NEXT: Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = <block>, location = [0x0000000140001000, 0x000000014000102d) -> DW_OP_reg26 XMM9
9393
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
94-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
94+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
9595

9696
# CHECK-LABEL: (lldb) image lookup -a 0x14000101c -v
9797
# CHECK: Summary: {{.*}}`main + 28 [inlined] Class1::bar at b.h:5
@@ -104,12 +104,12 @@
104104
# CHECK: LineEntry: [0x000000014000101c-0x0000000140001022): /tmp/b.h:5
105105
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
106106
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = [0x000000014000101c, 0x000000014000101e) -> DW_OP_reg24 XMM7
107-
# CHECK-NEXT: Variable: id = {{.*}}, name = "bar_local", type = "int", valid ranges = <block>, location = [0x000000014000101c, 0x0000000140001039) -> DW_OP_breg7 RSP+52
107+
# CHECK-NEXT: Variable: id = {{.*}}, name = "bar_local", type = "volatile int", valid ranges = <block>, location = [0x000000014000101c, 0x0000000140001039) -> DW_OP_breg7 RSP+52
108108
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = <empty>, decl =
109-
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
109+
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
110110
# CHECK-NEXT: Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = <block>, location = [0x0000000140001000, 0x000000014000102d) -> DW_OP_reg26 XMM9
111111
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
112-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
112+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
113113

114114
# CHECK-LABEL: (lldb) image lookup -a 0x14000102a -v
115115
# CHECK: Summary: {{.*}}`main + 42 [inlined] Namespace2::Class2::func at c.h:5
@@ -124,13 +124,13 @@
124124
# CHECK: LineEntry: [0x000000014000102a-0x0000000140001031): /tmp/c.h:5
125125
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
126126
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = [0x000000014000102a, 0x0000000140001039) -> DW_OP_reg24 XMM7
127-
# CHECK-NEXT: Variable: id = {{.*}}, name = "func_local", type = "int", valid ranges = <block>, location = [0x000000014000102a, 0x0000000140001039) -> DW_OP_breg7 RSP+48
128-
# CHECK-NEXT: Variable: id = {{.*}}, name = "bar_local", type = "int", valid ranges = <block>, location = [0x000000014000101c, 0x0000000140001039) -> DW_OP_breg7 RSP+52
127+
# CHECK-NEXT: Variable: id = {{.*}}, name = "func_local", type = "volatile int", valid ranges = <block>, location = [0x000000014000102a, 0x0000000140001039) -> DW_OP_breg7 RSP+48
128+
# CHECK-NEXT: Variable: id = {{.*}}, name = "bar_local", type = "volatile int", valid ranges = <block>, location = [0x000000014000101c, 0x0000000140001039) -> DW_OP_breg7 RSP+52
129129
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = <empty>, decl =
130-
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
130+
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001039) -> DW_OP_breg7 RSP+44
131131
# CHECK-NEXT: Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = <block>, location = [0x0000000140001000, 0x000000014000102d) -> DW_OP_reg26 XMM9
132132
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
133-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
133+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
134134

135135
# CHECK-LABEL: (lldb) image lookup -a 0x140001039 -v
136136
# CHECK: Summary: {{.*}}`main + 57 at a.cpp:3
@@ -139,7 +139,7 @@
139139
# CHECK: LineEntry: [0x0000000140001039-0x000000014000103d): /tmp/a.cpp:3
140140
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
141141
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
142-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
142+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
143143

144144
# CHECK-LABEL: (lldb) image lookup -a 0x140001044 -v
145145
# CHECK: Summary: {{.*}}`main + 68 [inlined] Namespace1::foo + 5 at a.h:8
@@ -150,10 +150,10 @@
150150
# CHECK: LineEntry: [0x0000000140001044-0x0000000140001046): /tmp/a.h:8
151151
# CHECK-NEXT: Symbol: id = {{.*}}, range = [0x0000000140001000-0x0000000140001046), name="main"
152152
# CHECK-NEXT: Variable: id = {{.*}}, name = "x", type = "int", valid ranges = <block>, location = <empty>, decl =
153-
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "int", valid ranges = <block>, location = [0x0000000140001044, 0x0000000140001046) -> DW_OP_breg7 RSP+44
153+
# CHECK-NEXT: Variable: id = {{.*}}, name = "foo_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001044, 0x0000000140001046) -> DW_OP_breg7 RSP+44
154154
# CHECK-NEXT: Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = <block>, location = [0x0000000140001044, 0x0000000140001045) -> DW_OP_reg26 XMM9
155155
# CHECK-NEXT: Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = <block>, location = [0x0000000140001000, 0x0000000140001045) -> DW_OP_reg3 RBX
156-
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
156+
# CHECK-NEXT: Variable: id = {{.*}}, name = "main_local", type = "volatile int", valid ranges = <block>, location = [0x0000000140001004, 0x0000000140001046) -> DW_OP_breg7 RSP+48
157157

158158
# CHECK-LABEL: (lldb) target modules dump ast
159159
# CHECK-NEXT: Dumping clang ast for 1 modules.

lldb/test/Shell/SymbolFile/PDB/type-quals.test

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@ REQUIRES: target-windows, msvc
22
RUN: mkdir -p %t.dir
33
RUN: %build --compiler=clang-cl --mode=compile --arch=32 --nodefaultlib --output=%t.dir/TypeQualsTest.cpp.obj %S/Inputs/TypeQualsTest.cpp
44
RUN: %build --compiler=msvc --mode=link --arch=32 --nodefaultlib --output=%t.dir/TypeQualsTest.cpp.exe %t.dir/TypeQualsTest.cpp.obj
5-
RUN: lldb-test symbols %t.dir/TypeQualsTest.cpp.exe | FileCheck %s
5+
RUN: env LLDB_USE_NATIVE_PDB_READER=0 lldb-test symbols %t.dir/TypeQualsTest.cpp.exe | FileCheck %s
6+
RUN: env LLDB_USE_NATIVE_PDB_READER=1 lldb-test symbols %t.dir/TypeQualsTest.cpp.exe | FileCheck %s
67

78
CHECK: Module [[MOD:.*]]
8-
CHECK-DAG: SymbolFile pdb ([[MOD]])
9+
CHECK-DAG: SymbolFile {{(native-)?}}pdb ([[MOD]])
910
CHECK-DAG: Type{{.*}} , name = "const int", size = 4, compiler_type = {{.*}} const int
1011
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} const int *
1112
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} const int **const
1213
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} const int *const
1314
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} const int *const *
14-
CHECK-DAG: Type{{.*}} , name = "Func1", {{.*}}, compiler_type = {{.*}} void (const int *, const int *, const int **const, const int *const *)
15+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (const int *, const int *, const int **const, const int *const *)
1516

1617
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} volatile int *
17-
CHECK-DAG: Type{{.*}} , name = "Func2", {{.*}}, compiler_type = {{.*}} void (volatile int *, volatile int *)
18+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (volatile int *, volatile int *)
1819

1920
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int *
2021
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int *&
2122
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int &&
2223
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int &
2324
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} const int &
24-
CHECK-DAG: Type{{.*}} , name = "Func3", {{.*}}, compiler_type = {{.*}} void (int *&, int &, const int &, int &&)
25+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (int *&, int &, const int &, int &&)
2526

2627
// FIXME: __unaligned is not supported.
27-
CHECK-DAG: Type{{.*}} , name = "Func4", {{.*}}, compiler_type = {{.*}} void (int *, int *)
28+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (int *, int *)
2829

2930
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int *__restrict
3031
CHECK-DAG: Type{{.*}} , size = 4, compiler_type = {{.*}} int &__restrict
31-
CHECK-DAG: Type{{.*}} , name = "Func5", {{.*}}, compiler_type = {{.*}} void (int, int *__restrict, int &__restrict)
32+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (int, int *__restrict, int &__restrict)
3233

33-
CHECK-DAG: Type{{.*}} , name = "Func6", {{.*}}, compiler_type = {{.*}} void (const volatile int *__restrict)
34+
CHECK-DAG: Type{{.*}} , name = "{{volatile const|const volatile}} int", size = 4, compiler_type = {{.*}} {{volatile const|const volatile}} int
35+
CHECK-DAG: Type{{.*}} , {{.*}}, compiler_type = {{.*}} void (const volatile int *__restrict)
3436

3537
CHECK-DAG: Type{{.*}} , size = 400, compiler_type = {{.*}} volatile int *[100]
3638
CHECK-DAG: Type{{.*}} , size = 4000, compiler_type = {{.*}} volatile int *[10][100]

0 commit comments

Comments
 (0)