Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9133ca5

Browse files
author
Zachary Turner
committed
Resubmit "Support embedding natvis files in PDBs."
The issue causing this to fail in certain configurations should be fixed. It was due to the fact that DIA apparently expects there to be a null string at ID 1 in the string table. I'm not sure why this is important but it seems to make a difference, so set it. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@328002 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 34412fc commit 9133ca5

12 files changed

+347
-5
lines changed

COFF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct Configuration {
9999
bool DebugGHashes = false;
100100
bool ShowTiming = false;
101101
unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
102+
std::vector<std::string> NatvisFiles;
102103
llvm::SmallString<128> PDBPath;
103104
std::vector<llvm::StringRef> Argv;
104105

COFF/Driver.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -933,9 +933,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
933933

934934
// Handle /pdb
935935
bool ShouldCreatePDB = Args.hasArg(OPT_debug, OPT_debug_ghash);
936-
if (ShouldCreatePDB)
936+
if (ShouldCreatePDB) {
937937
if (auto *Arg = Args.getLastArg(OPT_pdb))
938938
Config->PDBPath = Arg->getValue();
939+
if (Args.hasArg(OPT_natvis))
940+
Config->NatvisFiles = Args.getAllArgValues(OPT_natvis);
941+
}
939942

940943
// Handle /noentry
941944
if (Args.hasArg(OPT_noentry)) {

COFF/Options.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def nodefaultlib : P<"nodefaultlib", "Remove a default library">;
4545
def opt : P<"opt", "Control optimizations">;
4646
def order : P<"order", "Put functions in order">;
4747
def out : P<"out", "Path to file to write output">;
48+
def natvis : P<"natvis", "Path to natvis file to embed in the PDB">;
4849
def pdb : P<"pdb", "PDB file path">;
4950
def section : P<"section", "Specify section attributes">;
5051
def stack : P<"stack", "Size of the stack">;
@@ -162,7 +163,6 @@ def delay : QF<"delay">;
162163
def errorreport : QF<"errorreport">;
163164
def idlout : QF<"idlout">;
164165
def maxilksize : QF<"maxilksize">;
165-
def natvis : QF<"natvis">;
166166
def pdbaltpath : QF<"pdbaltpath">;
167167
def tlbid : QF<"tlbid">;
168168
def tlbout : QF<"tlbout">;

COFF/PDB.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,18 @@ class PDBLinker {
8585
public:
8686
PDBLinker(SymbolTable *Symtab)
8787
: Alloc(), Symtab(Symtab), Builder(Alloc), TypeTable(Alloc),
88-
IDTable(Alloc), GlobalTypeTable(Alloc), GlobalIDTable(Alloc) {}
88+
IDTable(Alloc), GlobalTypeTable(Alloc), GlobalIDTable(Alloc) {
89+
// It's not clear why this is needed, but injected sources (e.g. natvis files)
90+
// can file to be located if this is not present.
91+
PDBStrTab.insert("");
92+
}
8993

9094
/// Emit the basic PDB structure: initial streams, headers, etc.
9195
void initialize(const llvm::codeview::DebugInfo &BuildId);
9296

97+
/// Add natvis files specified on the command line.
98+
void addNatvisFiles();
99+
93100
/// Link CodeView from each object file in the symbol table into the PDB.
94101
void addObjectsToPDB();
95102

@@ -961,6 +968,18 @@ void PDBLinker::addObjectsToPDB() {
961968
}
962969
}
963970

971+
void PDBLinker::addNatvisFiles() {
972+
for (StringRef File : Config->NatvisFiles) {
973+
ErrorOr<std::unique_ptr<MemoryBuffer>> DataOrErr =
974+
MemoryBuffer::getFile(File);
975+
if (!DataOrErr) {
976+
warn("Cannot open input file: " + File);
977+
continue;
978+
}
979+
Builder.addInjectedSource(File, std::move(*DataOrErr));
980+
}
981+
}
982+
964983
static void addCommonLinkerModuleSymbols(StringRef Path,
965984
pdb::DbiModuleDescriptorBuilder &Mod,
966985
BumpPtrAllocator &Allocator) {
@@ -1038,9 +1057,11 @@ void coff::createPDB(SymbolTable *Symtab,
10381057
const llvm::codeview::DebugInfo &BuildId) {
10391058
ScopedTimer T1(TotalPdbLinkTimer);
10401059
PDBLinker PDB(Symtab);
1060+
10411061
PDB.initialize(BuildId);
10421062
PDB.addObjectsToPDB();
10431063
PDB.addSections(OutputSections, SectionTable);
1064+
PDB.addNatvisFiles();
10441065

10451066
ScopedTimer T2(DiskCommitTimer);
10461067
PDB.commit();

test/COFF/Inputs/generic.yaml

+282
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
--- !COFF
2+
header:
3+
Machine: IMAGE_FILE_MACHINE_AMD64
4+
Characteristics: [ ]
5+
sections:
6+
- Name: .text
7+
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
8+
Alignment: 16
9+
SectionData: 4883EC1831C0C7442414000000004889542408894C24044883C418C3
10+
- Name: .data
11+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
12+
Alignment: 4
13+
SectionData: ''
14+
- Name: .bss
15+
Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
16+
Alignment: 4
17+
SectionData: ''
18+
- Name: .xdata
19+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
20+
Alignment: 4
21+
SectionData: '0104010004220000'
22+
- Name: .drectve
23+
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
24+
Alignment: 1
25+
SectionData: 202F44454641554C544C49423A6C6962636D742E6C6962202F44454641554C544C49423A6F6C646E616D65732E6C6962
26+
- Name: '.debug$S'
27+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
28+
Alignment: 4
29+
SectionData: 04000000F10000002F0000002D003C1101000000D0000700000000000000581B000000000000636C616E672076657273696F6E20372E302E30200000F1000000760000002A0047110000000000000000000000001C000000000000000000000003100000000000000000006D61696E000D003E117400000001006172676300120045114F0100000400000017000000000005000D003E110010000001006172677600120045114F01000008000000170000000000050002004F110000F20000002800000000000000000000001C00000000000000020000001C00000000000000020000001700000003000000F40000001800000001000000100139E9A066A1995A99DD01F5A392F26D7C0000F30000003000000000443A5C7372635C6C6C766D6275696C645C636C5C52656C656173655C7836345C67656E657269632E63707000000000
30+
Subsections:
31+
- !Symbols
32+
Records:
33+
- Kind: S_COMPILE3
34+
Compile3Sym:
35+
Flags: [ ]
36+
Machine: X64
37+
FrontendMajor: 7
38+
FrontendMinor: 0
39+
FrontendBuild: 0
40+
FrontendQFE: 0
41+
BackendMajor: 7000
42+
BackendMinor: 0
43+
BackendBuild: 0
44+
BackendQFE: 0
45+
Version: 'clang version 7.0.0 '
46+
- !Symbols
47+
Records:
48+
- Kind: S_GPROC32_ID
49+
ProcSym:
50+
CodeSize: 28
51+
DbgStart: 0
52+
DbgEnd: 0
53+
FunctionType: 4099
54+
Flags: [ ]
55+
DisplayName: main
56+
- Kind: S_LOCAL
57+
LocalSym:
58+
Type: 116
59+
Flags: [ IsParameter ]
60+
VarName: argc
61+
- Kind: S_DEFRANGE_REGISTER_REL
62+
DefRangeRegisterRelSym:
63+
Register: 335
64+
Flags: 0
65+
BasePointerOffset: 4
66+
Range:
67+
OffsetStart: 23
68+
ISectStart: 0
69+
Range: 5
70+
Gaps:
71+
- Kind: S_LOCAL
72+
LocalSym:
73+
Type: 4096
74+
Flags: [ IsParameter ]
75+
VarName: argv
76+
- Kind: S_DEFRANGE_REGISTER_REL
77+
DefRangeRegisterRelSym:
78+
Register: 335
79+
Flags: 0
80+
BasePointerOffset: 8
81+
Range:
82+
OffsetStart: 23
83+
ISectStart: 0
84+
Range: 5
85+
Gaps:
86+
- Kind: S_PROC_ID_END
87+
ScopeEndSym:
88+
- !Lines
89+
CodeSize: 28
90+
Flags: [ ]
91+
RelocOffset: 0
92+
RelocSegment: 0
93+
Blocks:
94+
- FileName: 'D:\src\llvmbuild\cl\Release\x64\generic.cpp'
95+
Lines:
96+
- Offset: 0
97+
LineStart: 2
98+
IsStatement: false
99+
EndDelta: 0
100+
- Offset: 23
101+
LineStart: 3
102+
IsStatement: false
103+
EndDelta: 0
104+
Columns:
105+
- !FileChecksums
106+
Checksums:
107+
- FileName: 'D:\src\llvmbuild\cl\Release\x64\generic.cpp'
108+
Kind: MD5
109+
Checksum: 39E9A066A1995A99DD01F5A392F26D7C
110+
- !StringTable
111+
Strings:
112+
- 'D:\src\llvmbuild\cl\Release\x64\generic.cpp'
113+
- ''
114+
- ''
115+
- ''
116+
Relocations:
117+
- VirtualAddress: 100
118+
SymbolName: main
119+
Type: IMAGE_REL_AMD64_SECREL
120+
- VirtualAddress: 104
121+
SymbolName: main
122+
Type: IMAGE_REL_AMD64_SECTION
123+
- VirtualAddress: 139
124+
SymbolName: .text
125+
Type: IMAGE_REL_AMD64_SECREL
126+
- VirtualAddress: 143
127+
SymbolName: .text
128+
Type: IMAGE_REL_AMD64_SECTION
129+
- VirtualAddress: 174
130+
SymbolName: .text
131+
Type: IMAGE_REL_AMD64_SECREL
132+
- VirtualAddress: 178
133+
SymbolName: .text
134+
Type: IMAGE_REL_AMD64_SECTION
135+
- VirtualAddress: 196
136+
SymbolName: main
137+
Type: IMAGE_REL_AMD64_SECREL
138+
- VirtualAddress: 200
139+
SymbolName: main
140+
Type: IMAGE_REL_AMD64_SECTION
141+
- Name: '.debug$T'
142+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
143+
Alignment: 4
144+
SectionData: 040000000A000210700600000C0001000E0001120200000074000000001000000E0008107400000000000200011000001200011600000000021000006D61696E00F3F2F1
145+
Types:
146+
- Kind: LF_POINTER
147+
Pointer:
148+
ReferentType: 1648
149+
Attrs: 65548
150+
- Kind: LF_ARGLIST
151+
ArgList:
152+
ArgIndices: [ 116, 4096 ]
153+
- Kind: LF_PROCEDURE
154+
Procedure:
155+
ReturnType: 116
156+
CallConv: NearC
157+
Options: [ None ]
158+
ParameterCount: 2
159+
ArgumentList: 4097
160+
- Kind: LF_FUNC_ID
161+
FuncId:
162+
ParentScope: 0
163+
FunctionType: 4098
164+
Name: main
165+
- Name: .pdata
166+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
167+
Alignment: 4
168+
SectionData: 000000001C00000000000000
169+
Relocations:
170+
- VirtualAddress: 0
171+
SymbolName: main
172+
Type: IMAGE_REL_AMD64_ADDR32NB
173+
- VirtualAddress: 4
174+
SymbolName: main
175+
Type: IMAGE_REL_AMD64_ADDR32NB
176+
- VirtualAddress: 8
177+
SymbolName: .xdata
178+
Type: IMAGE_REL_AMD64_ADDR32NB
179+
symbols:
180+
- Name: .text
181+
Value: 0
182+
SectionNumber: 1
183+
SimpleType: IMAGE_SYM_TYPE_NULL
184+
ComplexType: IMAGE_SYM_DTYPE_NULL
185+
StorageClass: IMAGE_SYM_CLASS_STATIC
186+
SectionDefinition:
187+
Length: 28
188+
NumberOfRelocations: 0
189+
NumberOfLinenumbers: 0
190+
CheckSum: 594448369
191+
Number: 1
192+
- Name: .data
193+
Value: 0
194+
SectionNumber: 2
195+
SimpleType: IMAGE_SYM_TYPE_NULL
196+
ComplexType: IMAGE_SYM_DTYPE_NULL
197+
StorageClass: IMAGE_SYM_CLASS_STATIC
198+
SectionDefinition:
199+
Length: 0
200+
NumberOfRelocations: 0
201+
NumberOfLinenumbers: 0
202+
CheckSum: 0
203+
Number: 2
204+
- Name: .bss
205+
Value: 0
206+
SectionNumber: 3
207+
SimpleType: IMAGE_SYM_TYPE_NULL
208+
ComplexType: IMAGE_SYM_DTYPE_NULL
209+
StorageClass: IMAGE_SYM_CLASS_STATIC
210+
SectionDefinition:
211+
Length: 0
212+
NumberOfRelocations: 0
213+
NumberOfLinenumbers: 0
214+
CheckSum: 0
215+
Number: 3
216+
- Name: .xdata
217+
Value: 0
218+
SectionNumber: 4
219+
SimpleType: IMAGE_SYM_TYPE_NULL
220+
ComplexType: IMAGE_SYM_DTYPE_NULL
221+
StorageClass: IMAGE_SYM_CLASS_STATIC
222+
SectionDefinition:
223+
Length: 8
224+
NumberOfRelocations: 0
225+
NumberOfLinenumbers: 0
226+
CheckSum: 1192424177
227+
Number: 4
228+
- Name: .drectve
229+
Value: 0
230+
SectionNumber: 5
231+
SimpleType: IMAGE_SYM_TYPE_NULL
232+
ComplexType: IMAGE_SYM_DTYPE_NULL
233+
StorageClass: IMAGE_SYM_CLASS_STATIC
234+
SectionDefinition:
235+
Length: 48
236+
NumberOfRelocations: 0
237+
NumberOfLinenumbers: 0
238+
CheckSum: 149686238
239+
Number: 5
240+
- Name: '.debug$S'
241+
Value: 0
242+
SectionNumber: 6
243+
SimpleType: IMAGE_SYM_TYPE_NULL
244+
ComplexType: IMAGE_SYM_DTYPE_NULL
245+
StorageClass: IMAGE_SYM_CLASS_STATIC
246+
SectionDefinition:
247+
Length: 324
248+
NumberOfRelocations: 8
249+
NumberOfLinenumbers: 0
250+
CheckSum: 4196717433
251+
Number: 6
252+
- Name: '.debug$T'
253+
Value: 0
254+
SectionNumber: 7
255+
SimpleType: IMAGE_SYM_TYPE_NULL
256+
ComplexType: IMAGE_SYM_DTYPE_NULL
257+
StorageClass: IMAGE_SYM_CLASS_STATIC
258+
SectionDefinition:
259+
Length: 68
260+
NumberOfRelocations: 0
261+
NumberOfLinenumbers: 0
262+
CheckSum: 485351071
263+
Number: 7
264+
- Name: .pdata
265+
Value: 0
266+
SectionNumber: 8
267+
SimpleType: IMAGE_SYM_TYPE_NULL
268+
ComplexType: IMAGE_SYM_DTYPE_NULL
269+
StorageClass: IMAGE_SYM_CLASS_STATIC
270+
SectionDefinition:
271+
Length: 12
272+
NumberOfRelocations: 3
273+
NumberOfLinenumbers: 0
274+
CheckSum: 722740324
275+
Number: 8
276+
- Name: main
277+
Value: 0
278+
SectionNumber: 1
279+
SimpleType: IMAGE_SYM_TYPE_NULL
280+
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
281+
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
282+
...

test/COFF/Inputs/natvis-1.natvis

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1st Natvis Test

test/COFF/Inputs/natvis-2.natvis

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Second Natvis Test

test/COFF/Inputs/natvis-3.natvis

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Third Natvis Test

test/COFF/pdb-file-static.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
# CHECK: ============================================================
4444
# CHECK-LABEL: Mod 0000 | `{{.*}}a.obj`:
4545
# CHECK: 232 | S_FILESTATIC [size = 16] `x`
46-
# CHECK-NEXT: type = 0x0074 (int), file name = 1 (D:\src\llvmbuild\cl\Debug\x64\a.obj), flags = enreg global | enreg static
46+
# CHECK-NEXT: type = 0x0074 (int), file name = 2 (D:\src\llvmbuild\cl\Debug\x64\a.obj), flags = enreg global | enreg static
4747
# CHECK: Mod 0001 | `{{.*}}b.obj`:
4848
# CHECK: 232 | S_FILESTATIC [size = 16] `y`
49-
# CHECK-NEXT: type = 0x0074 (int), file name = 73 (D:\src\llvmbuild\cl\Debug\x64\b.obj), flags = enreg global | enreg static
49+
# CHECK-NEXT: type = 0x0074 (int), file name = 74 (D:\src\llvmbuild\cl\Debug\x64\b.obj), flags = enreg global | enreg static
5050
# CHECK-LABEL: Mod 0002 | `* Linker *`:
5151

0 commit comments

Comments
 (0)