authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-29 20:37:01+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-29 23:43:52+01:00
logba8d3f69ca65738f27deea43e795f5e787a061f2
tree6c5ead2e52338ff5b5d803298a6015a5cd31cc87
parent4330c405963ad7db2bfdb639c556e04793d386a1
signaturelock-open Commit is signed but in an unrecognized format.

std.pdb: obey naming conventions

These names aren't matching any formal specification; they're mostly just ripped from LLVM code. Therefore, we should definitely follow Zig naming conventions here.

3 files changed, 389 insertions(+), 387 deletions(-)

lib/std/debug/Pdb.zig+61-61
......@@ -63,18 +63,18 @@ pub fn deinit(self: *Pdb) void {
6363}
6464
6565pub fn parseDbiStream(self: *Pdb) !void {
66 var stream = self.getStream(pdb.StreamType.Dbi) orelse
66 var stream = self.getStream(pdb.StreamType.dbi) orelse
6767 return error.InvalidDebugInfo;
6868 const reader = stream.reader();
6969
7070 const header = try reader.readStruct(std.pdb.DbiStreamHeader);
71 if (header.VersionHeader != 19990903) // V70, only value observed by LLVM team
71 if (header.version_header != 19990903) // V70, only value observed by LLVM team
7272 return error.UnknownPDBVersion;
7373 // if (header.Age != age)
7474 // return error.UnmatchingPDB;
7575
76 const mod_info_size = header.ModInfoSize;
77 const section_contrib_size = header.SectionContributionSize;
76 const mod_info_size = header.mod_info_size;
77 const section_contrib_size = header.section_contribution_size;
7878
7979 var modules = std.ArrayList(Module).init(self.allocator);
8080 errdefer modules.deinit();
......@@ -143,7 +143,7 @@ pub fn parseDbiStream(self: *Pdb) !void {
143143}
144144
145145pub fn parseInfoStream(self: *Pdb) !void {
146 var stream = self.getStream(pdb.StreamType.Pdb) orelse
146 var stream = self.getStream(pdb.StreamType.pdb) orelse
147147 return error.InvalidDebugInfo;
148148 const reader = stream.reader();
149149
......@@ -168,23 +168,23 @@ pub fn parseInfoStream(self: *Pdb) !void {
168168 try reader.readNoEof(name_bytes);
169169
170170 const HashTableHeader = extern struct {
171 Size: u32,
172 Capacity: u32,
171 size: u32,
172 capacity: u32,
173173
174174 fn maxLoad(cap: u32) u32 {
175175 return cap * 2 / 3 + 1;
176176 }
177177 };
178178 const hash_tbl_hdr = try reader.readStruct(HashTableHeader);
179 if (hash_tbl_hdr.Capacity == 0)
179 if (hash_tbl_hdr.capacity == 0)
180180 return error.InvalidDebugInfo;
181181
182 if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))
182 if (hash_tbl_hdr.size > HashTableHeader.maxLoad(hash_tbl_hdr.capacity))
183183 return error.InvalidDebugInfo;
184184
185185 const present = try readSparseBitVector(&reader, self.allocator);
186186 defer self.allocator.free(present);
187 if (present.len != hash_tbl_hdr.Size)
187 if (present.len != hash_tbl_hdr.size)
188188 return error.InvalidDebugInfo;
189189 const deleted = try readSparseBitVector(&reader, self.allocator);
190190 defer self.allocator.free(deleted);
......@@ -212,19 +212,19 @@ pub fn getSymbolName(self: *Pdb, module: *Module, address: u64) ?[]const u8 {
212212
213213 var symbol_i: usize = 0;
214214 while (symbol_i != module.symbols.len) {
215 const prefix = @as(*align(1) pdb.RecordPrefix, @ptrCast(&module.symbols[symbol_i]));
216 if (prefix.RecordLen < 2)
215 const prefix: *align(1) pdb.RecordPrefix = @ptrCast(&module.symbols[symbol_i]);
216 if (prefix.record_len < 2)
217217 return null;
218 switch (prefix.RecordKind) {
219 .S_LPROC32, .S_GPROC32 => {
220 const proc_sym = @as(*align(1) pdb.ProcSym, @ptrCast(&module.symbols[symbol_i + @sizeOf(pdb.RecordPrefix)]));
221 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
222 return std.mem.sliceTo(@as([*:0]u8, @ptrCast(&proc_sym.Name[0])), 0);
218 switch (prefix.record_kind) {
219 .lproc32, .gproc32 => {
220 const proc_sym: *align(1) pdb.ProcSym = @ptrCast(&module.symbols[symbol_i + @sizeOf(pdb.RecordPrefix)]);
221 if (address >= proc_sym.code_offset and address < proc_sym.code_offset + proc_sym.code_size) {
222 return std.mem.sliceTo(@as([*:0]u8, @ptrCast(&proc_sym.name[0])), 0);
223223 }
224224 },
225225 else => {},
226226 }
227 symbol_i += prefix.RecordLen + @sizeOf(u16);
227 symbol_i += prefix.record_len + @sizeOf(u16);
228228 }
229229
230230 return null;
......@@ -238,44 +238,44 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
238238 var skip_len: usize = undefined;
239239 const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
240240 while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {
241 const subsect_hdr = @as(*align(1) pdb.DebugSubsectionHeader, @ptrCast(&subsect_info[sect_offset]));
242 skip_len = subsect_hdr.Length;
241 const subsect_hdr: *align(1) pdb.DebugSubsectionHeader = @ptrCast(&subsect_info[sect_offset]);
242 skip_len = subsect_hdr.length;
243243 sect_offset += @sizeOf(pdb.DebugSubsectionHeader);
244244
245 switch (subsect_hdr.Kind) {
246 .Lines => {
245 switch (subsect_hdr.kind) {
246 .lines => {
247247 var line_index = sect_offset;
248248
249 const line_hdr = @as(*align(1) pdb.LineFragmentHeader, @ptrCast(&subsect_info[line_index]));
250 if (line_hdr.RelocSegment == 0)
249 const line_hdr: *align(1) pdb.LineFragmentHeader = @ptrCast(&subsect_info[line_index]);
250 if (line_hdr.reloc_segment == 0)
251251 return error.MissingDebugInfo;
252252 line_index += @sizeOf(pdb.LineFragmentHeader);
253 const frag_vaddr_start = line_hdr.RelocOffset;
254 const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize;
253 const frag_vaddr_start = line_hdr.reloc_offset;
254 const frag_vaddr_end = frag_vaddr_start + line_hdr.code_size;
255255
256256 if (address >= frag_vaddr_start and address < frag_vaddr_end) {
257257 // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records)
258258 // from now on. We will iterate through them, and eventually find a SourceLocation that we're interested in,
259259 // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection.
260 const subsection_end_index = sect_offset + subsect_hdr.Length;
260 const subsection_end_index = sect_offset + subsect_hdr.length;
261261
262262 while (line_index < subsection_end_index) {
263 const block_hdr = @as(*align(1) pdb.LineBlockFragmentHeader, @ptrCast(&subsect_info[line_index]));
263 const block_hdr: *align(1) pdb.LineBlockFragmentHeader = @ptrCast(&subsect_info[line_index]);
264264 line_index += @sizeOf(pdb.LineBlockFragmentHeader);
265265 const start_line_index = line_index;
266266
267 const has_column = line_hdr.Flags.LF_HaveColumns;
267 const has_column = line_hdr.flags.have_columns;
268268
269269 // All line entries are stored inside their line block by ascending start address.
270270 // Heuristic: we want to find the last line entry
271271 // that has a vaddr_start <= address.
272272 // This is done with a simple linear search.
273273 var line_i: u32 = 0;
274 while (line_i < block_hdr.NumLines) : (line_i += 1) {
275 const line_num_entry = @as(*align(1) pdb.LineNumberEntry, @ptrCast(&subsect_info[line_index]));
274 while (line_i < block_hdr.num_lines) : (line_i += 1) {
275 const line_num_entry: *align(1) pdb.LineNumberEntry = @ptrCast(&subsect_info[line_index]);
276276 line_index += @sizeOf(pdb.LineNumberEntry);
277277
278 const vaddr_start = frag_vaddr_start + line_num_entry.Offset;
278 const vaddr_start = frag_vaddr_start + line_num_entry.offset;
279279 if (address < vaddr_start) {
280280 break;
281281 }
......@@ -283,19 +283,19 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
283283
284284 // line_i == 0 would mean that no matching pdb.LineNumberEntry was found.
285285 if (line_i > 0) {
286 const subsect_index = checksum_offset + block_hdr.NameIndex;
287 const chksum_hdr = @as(*align(1) pdb.FileChecksumEntryHeader, @ptrCast(&module.subsect_info[subsect_index]));
288 const strtab_offset = @sizeOf(pdb.StringTableHeader) + chksum_hdr.FileNameOffset;
286 const subsect_index = checksum_offset + block_hdr.name_index;
287 const chksum_hdr: *align(1) pdb.FileChecksumEntryHeader = @ptrCast(&module.subsect_info[subsect_index]);
288 const strtab_offset = @sizeOf(pdb.StringTableHeader) + chksum_hdr.file_name_offset;
289289 try self.string_table.?.seekTo(strtab_offset);
290290 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
291291
292292 const line_entry_idx = line_i - 1;
293293
294294 const column = if (has_column) blk: {
295 const start_col_index = start_line_index + @sizeOf(pdb.LineNumberEntry) * block_hdr.NumLines;
295 const start_col_index = start_line_index + @sizeOf(pdb.LineNumberEntry) * block_hdr.num_lines;
296296 const col_index = start_col_index + @sizeOf(pdb.ColumnNumberEntry) * line_entry_idx;
297 const col_num_entry = @as(*align(1) pdb.ColumnNumberEntry, @ptrCast(&subsect_info[col_index]));
298 break :blk col_num_entry.StartColumn;
297 const col_num_entry: *align(1) pdb.ColumnNumberEntry = @ptrCast(&subsect_info[col_index]);
298 break :blk col_num_entry.start_column;
299299 } else 0;
300300
301301 const found_line_index = start_line_index + line_entry_idx * @sizeOf(pdb.LineNumberEntry);
......@@ -303,7 +303,7 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
303303
304304 return .{
305305 .file_name = source_file_name,
306 .line = line_num_entry.Flags.Start,
306 .line = line_num_entry.flags.start,
307307 .column = column,
308308 };
309309 }
......@@ -334,12 +334,12 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
334334 return mod;
335335
336336 // At most one can be non-zero.
337 if (mod.mod_info.C11ByteSize != 0 and mod.mod_info.C13ByteSize != 0)
337 if (mod.mod_info.c11_byte_size != 0 and mod.mod_info.c13_byte_size != 0)
338338 return error.InvalidDebugInfo;
339 if (mod.mod_info.C13ByteSize == 0)
339 if (mod.mod_info.c13_byte_size == 0)
340340 return error.InvalidDebugInfo;
341341
342 const stream = self.getStreamById(mod.mod_info.ModuleSymStream) orelse
342 const stream = self.getStreamById(mod.mod_info.module_sym_stream) orelse
343343 return error.MissingDebugInfo;
344344 const reader = stream.reader();
345345
......@@ -347,23 +347,23 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
347347 if (signature != 4)
348348 return error.InvalidDebugInfo;
349349
350 mod.symbols = try self.allocator.alloc(u8, mod.mod_info.SymByteSize - 4);
350 mod.symbols = try self.allocator.alloc(u8, mod.mod_info.sym_byte_size - 4);
351351 errdefer self.allocator.free(mod.symbols);
352352 try reader.readNoEof(mod.symbols);
353353
354 mod.subsect_info = try self.allocator.alloc(u8, mod.mod_info.C13ByteSize);
354 mod.subsect_info = try self.allocator.alloc(u8, mod.mod_info.c13_byte_size);
355355 errdefer self.allocator.free(mod.subsect_info);
356356 try reader.readNoEof(mod.subsect_info);
357357
358358 var sect_offset: usize = 0;
359359 var skip_len: usize = undefined;
360360 while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {
361 const subsect_hdr = @as(*align(1) pdb.DebugSubsectionHeader, @ptrCast(&mod.subsect_info[sect_offset]));
362 skip_len = subsect_hdr.Length;
361 const subsect_hdr: *align(1) pdb.DebugSubsectionHeader = @ptrCast(&mod.subsect_info[sect_offset]);
362 skip_len = subsect_hdr.length;
363363 sect_offset += @sizeOf(pdb.DebugSubsectionHeader);
364364
365 switch (subsect_hdr.Kind) {
366 .FileChecksums => {
365 switch (subsect_hdr.kind) {
366 .file_checksums => {
367367 mod.checksum_offset = sect_offset;
368368 break;
369369 },
......@@ -400,30 +400,30 @@ const Msf = struct {
400400 const superblock = try in.readStruct(pdb.SuperBlock);
401401
402402 // Sanity checks
403 if (!std.mem.eql(u8, &superblock.FileMagic, pdb.SuperBlock.file_magic))
403 if (!std.mem.eql(u8, &superblock.file_magic, pdb.SuperBlock.expect_magic))
404404 return error.InvalidDebugInfo;
405 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)
405 if (superblock.free_block_map_block != 1 and superblock.free_block_map_block != 2)
406406 return error.InvalidDebugInfo;
407407 const file_len = try file.getEndPos();
408 if (superblock.NumBlocks * superblock.BlockSize != file_len)
408 if (superblock.num_blocks * superblock.block_size != file_len)
409409 return error.InvalidDebugInfo;
410 switch (superblock.BlockSize) {
410 switch (superblock.block_size) {
411411 // llvm only supports 4096 but we can handle any of these values
412412 512, 1024, 2048, 4096 => {},
413413 else => return error.InvalidDebugInfo,
414414 }
415415
416 const dir_block_count = blockCountFromSize(superblock.NumDirectoryBytes, superblock.BlockSize);
417 if (dir_block_count > superblock.BlockSize / @sizeOf(u32))
416 const dir_block_count = blockCountFromSize(superblock.num_directory_bytes, superblock.block_size);
417 if (dir_block_count > superblock.block_size / @sizeOf(u32))
418418 return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment.
419419
420 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);
420 try file.seekTo(superblock.block_size * superblock.block_map_addr);
421421 const dir_blocks = try allocator.alloc(u32, dir_block_count);
422422 for (dir_blocks) |*b| {
423423 b.* = try in.readInt(u32, .little);
424424 }
425425 var directory = MsfStream.init(
426 superblock.BlockSize,
426 superblock.block_size,
427427 file,
428428 dir_blocks,
429429 );
......@@ -439,7 +439,7 @@ const Msf = struct {
439439 const Nil = 0xFFFFFFFF;
440440 for (stream_sizes) |*s| {
441441 const size = try directory.reader().readInt(u32, .little);
442 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
442 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.block_size);
443443 }
444444
445445 const streams = try allocator.alloc(MsfStream, stream_count);
......@@ -454,15 +454,15 @@ const Msf = struct {
454454 var j: u32 = 0;
455455 while (j < size) : (j += 1) {
456456 const block_id = try directory.reader().readInt(u32, .little);
457 const n = (block_id % superblock.BlockSize);
457 const n = (block_id % superblock.block_size);
458458 // 0 is for pdb.SuperBlock, 1 and 2 for FPMs.
459 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len)
459 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.block_size > file_len)
460460 return error.InvalidBlockIndex;
461461 blocks[j] = block_id;
462462 }
463463
464464 stream.* = MsfStream.init(
465 superblock.BlockSize,
465 superblock.block_size,
466466 file,
467467 blocks,
468468 );
......@@ -470,7 +470,7 @@ const Msf = struct {
470470 }
471471
472472 const end = directory.pos;
473 if (end - begin != superblock.NumDirectoryBytes)
473 if (end - begin != superblock.num_directory_bytes)
474474 return error.InvalidStreamDirectory;
475475
476476 return Msf{
lib/std/debug/SelfInfo.zig+5-5
......@@ -732,14 +732,14 @@ pub const Module = switch (native_os) {
732732 fn getSymbolFromPdb(self: *@This(), relocated_address: usize) !?std.debug.Symbol {
733733 var coff_section: *align(1) const coff.SectionHeader = undefined;
734734 const mod_index = for (self.pdb.?.sect_contribs) |sect_contrib| {
735 if (sect_contrib.Section > self.coff_section_headers.len) continue;
735 if (sect_contrib.section > self.coff_section_headers.len) continue;
736736 // Remember that SectionContribEntry.Section is 1-based.
737 coff_section = &self.coff_section_headers[sect_contrib.Section - 1];
737 coff_section = &self.coff_section_headers[sect_contrib.section - 1];
738738
739 const vaddr_start = coff_section.virtual_address + sect_contrib.Offset;
740 const vaddr_end = vaddr_start + sect_contrib.Size;
739 const vaddr_start = coff_section.virtual_address + sect_contrib.offset;
740 const vaddr_end = vaddr_start + sect_contrib.size;
741741 if (relocated_address >= vaddr_start and relocated_address < vaddr_end) {
742 break sect_contrib.ModuleIndex;
742 break sect_contrib.module_index;
743743 }
744744 } else {
745745 // we have no information to add to the address
lib/std/pdb.zig+323-321
......@@ -20,297 +20,297 @@ const ArrayList = std.ArrayList;
2020
2121/// https://llvm.org/docs/PDB/DbiStream.html#stream-header
2222pub const DbiStreamHeader = extern struct {
23 VersionSignature: i32,
24 VersionHeader: u32,
25 Age: u32,
26 GlobalStreamIndex: u16,
27 BuildNumber: u16,
28 PublicStreamIndex: u16,
29 PdbDllVersion: u16,
30 SymRecordStream: u16,
31 PdbDllRbld: u16,
32 ModInfoSize: u32,
33 SectionContributionSize: u32,
34 SectionMapSize: u32,
35 SourceInfoSize: i32,
36 TypeServerSize: i32,
37 MFCTypeServerIndex: u32,
38 OptionalDbgHeaderSize: i32,
39 ECSubstreamSize: i32,
40 Flags: u16,
41 Machine: u16,
42 Padding: u32,
23 version_signature: i32,
24 version_header: u32,
25 age: u32,
26 global_stream_index: u16,
27 build_number: u16,
28 public_stream_index: u16,
29 pdb_dll_version: u16,
30 sym_record_stream: u16,
31 pdb_dll_rbld: u16,
32 mod_info_size: u32,
33 section_contribution_size: u32,
34 section_map_size: u32,
35 source_info_size: i32,
36 type_server_size: i32,
37 mfc_type_server_index: u32,
38 optional_dbg_header_size: i32,
39 ec_substream_size: i32,
40 flags: u16,
41 machine: u16,
42 padding: u32,
4343};
4444
4545pub const SectionContribEntry = extern struct {
4646 /// COFF Section index, 1-based
47 Section: u16,
48 Padding1: [2]u8,
49 Offset: u32,
50 Size: u32,
51 Characteristics: u32,
52 ModuleIndex: u16,
53 Padding2: [2]u8,
54 DataCrc: u32,
55 RelocCrc: u32,
47 section: u16,
48 padding1: [2]u8,
49 offset: u32,
50 size: u32,
51 characteristics: u32,
52 module_index: u16,
53 padding2: [2]u8,
54 data_crc: u32,
55 reloc_crc: u32,
5656};
5757
5858pub const ModInfo = extern struct {
59 Unused1: u32,
60 SectionContr: SectionContribEntry,
61 Flags: u16,
62 ModuleSymStream: u16,
63 SymByteSize: u32,
64 C11ByteSize: u32,
65 C13ByteSize: u32,
66 SourceFileCount: u16,
67 Padding: [2]u8,
68 Unused2: u32,
69 SourceFileNameIndex: u32,
70 PdbFilePathNameIndex: u32,
59 unused1: u32,
60 section_contr: SectionContribEntry,
61 flags: u16,
62 module_sym_stream: u16,
63 sym_byte_size: u32,
64 c11_byte_size: u32,
65 c13_byte_size: u32,
66 source_file_count: u16,
67 padding: [2]u8,
68 unused2: u32,
69 source_file_name_index: u32,
70 pdb_file_path_name_index: u32,
7171 // These fields are variable length
72 //ModuleName: char[],
73 //ObjFileName: char[],
72 //module_name: char[],
73 //obj_file_name: char[],
7474};
7575
7676pub const SectionMapHeader = extern struct {
7777 /// Number of segment descriptors
78 Count: u16,
78 count: u16,
7979
8080 /// Number of logical segment descriptors
81 LogCount: u16,
81 log_count: u16,
8282};
8383
8484pub const SectionMapEntry = extern struct {
8585 /// See the SectionMapEntryFlags enum below.
86 Flags: u16,
86 flags: u16,
8787
8888 /// Logical overlay number
89 Ovl: u16,
89 ovl: u16,
9090
9191 /// Group index into descriptor array.
92 Group: u16,
93 Frame: u16,
92 group: u16,
93 frame: u16,
9494
9595 /// Byte index of segment / group name in string table, or 0xFFFF.
96 SectionName: u16,
96 section_name: u16,
9797
9898 /// Byte index of class in string table, or 0xFFFF.
99 ClassName: u16,
99 class_name: u16,
100100
101101 /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group.
102 Offset: u32,
102 offset: u32,
103103
104104 /// Byte count of the segment or group.
105 SectionLength: u32,
105 section_length: u32,
106106};
107107
108108pub const StreamType = enum(u16) {
109 Pdb = 1,
110 Tpi = 2,
111 Dbi = 3,
112 Ipi = 4,
109 pdb = 1,
110 tpi = 2,
111 dbi = 3,
112 ipi = 4,
113113};
114114
115115/// Duplicate copy of SymbolRecordKind, but using the official CV names. Useful
116116/// for reference purposes and when dealing with unknown record types.
117117pub const SymbolKind = enum(u16) {
118 S_COMPILE = 1,
119 S_REGISTER_16t = 2,
120 S_CONSTANT_16t = 3,
121 S_UDT_16t = 4,
122 S_SSEARCH = 5,
123 S_SKIP = 7,
124 S_CVRESERVE = 8,
125 S_OBJNAME_ST = 9,
126 S_ENDARG = 10,
127 S_COBOLUDT_16t = 11,
128 S_MANYREG_16t = 12,
129 S_RETURN = 13,
130 S_ENTRYTHIS = 14,
131 S_BPREL16 = 256,
132 S_LDATA16 = 257,
133 S_GDATA16 = 258,
134 S_PUB16 = 259,
135 S_LPROC16 = 260,
136 S_GPROC16 = 261,
137 S_THUNK16 = 262,
138 S_BLOCK16 = 263,
139 S_WITH16 = 264,
140 S_LABEL16 = 265,
141 S_CEXMODEL16 = 266,
142 S_VFTABLE16 = 267,
143 S_REGREL16 = 268,
144 S_BPREL32_16t = 512,
145 S_LDATA32_16t = 513,
146 S_GDATA32_16t = 514,
147 S_PUB32_16t = 515,
148 S_LPROC32_16t = 516,
149 S_GPROC32_16t = 517,
150 S_THUNK32_ST = 518,
151 S_BLOCK32_ST = 519,
152 S_WITH32_ST = 520,
153 S_LABEL32_ST = 521,
154 S_CEXMODEL32 = 522,
155 S_VFTABLE32_16t = 523,
156 S_REGREL32_16t = 524,
157 S_LTHREAD32_16t = 525,
158 S_GTHREAD32_16t = 526,
159 S_SLINK32 = 527,
160 S_LPROCMIPS_16t = 768,
161 S_GPROCMIPS_16t = 769,
162 S_PROCREF_ST = 1024,
163 S_DATAREF_ST = 1025,
164 S_ALIGN = 1026,
165 S_LPROCREF_ST = 1027,
166 S_OEM = 1028,
167 S_TI16_MAX = 4096,
168 S_REGISTER_ST = 4097,
169 S_CONSTANT_ST = 4098,
170 S_UDT_ST = 4099,
171 S_COBOLUDT_ST = 4100,
172 S_MANYREG_ST = 4101,
173 S_BPREL32_ST = 4102,
174 S_LDATA32_ST = 4103,
175 S_GDATA32_ST = 4104,
176 S_PUB32_ST = 4105,
177 S_LPROC32_ST = 4106,
178 S_GPROC32_ST = 4107,
179 S_VFTABLE32 = 4108,
180 S_REGREL32_ST = 4109,
181 S_LTHREAD32_ST = 4110,
182 S_GTHREAD32_ST = 4111,
183 S_LPROCMIPS_ST = 4112,
184 S_GPROCMIPS_ST = 4113,
185 S_COMPILE2_ST = 4115,
186 S_MANYREG2_ST = 4116,
187 S_LPROCIA64_ST = 4117,
188 S_GPROCIA64_ST = 4118,
189 S_LOCALSLOT_ST = 4119,
190 S_PARAMSLOT_ST = 4120,
191 S_ANNOTATION = 4121,
192 S_GMANPROC_ST = 4122,
193 S_LMANPROC_ST = 4123,
194 S_RESERVED1 = 4124,
195 S_RESERVED2 = 4125,
196 S_RESERVED3 = 4126,
197 S_RESERVED4 = 4127,
198 S_LMANDATA_ST = 4128,
199 S_GMANDATA_ST = 4129,
200 S_MANFRAMEREL_ST = 4130,
201 S_MANREGISTER_ST = 4131,
202 S_MANSLOT_ST = 4132,
203 S_MANMANYREG_ST = 4133,
204 S_MANREGREL_ST = 4134,
205 S_MANMANYREG2_ST = 4135,
206 S_MANTYPREF = 4136,
207 S_UNAMESPACE_ST = 4137,
208 S_ST_MAX = 4352,
209 S_WITH32 = 4356,
210 S_MANYREG = 4362,
211 S_LPROCMIPS = 4372,
212 S_GPROCMIPS = 4373,
213 S_MANYREG2 = 4375,
214 S_LPROCIA64 = 4376,
215 S_GPROCIA64 = 4377,
216 S_LOCALSLOT = 4378,
217 S_PARAMSLOT = 4379,
218 S_MANFRAMEREL = 4382,
219 S_MANREGISTER = 4383,
220 S_MANSLOT = 4384,
221 S_MANMANYREG = 4385,
222 S_MANREGREL = 4386,
223 S_MANMANYREG2 = 4387,
224 S_UNAMESPACE = 4388,
225 S_DATAREF = 4390,
226 S_ANNOTATIONREF = 4392,
227 S_TOKENREF = 4393,
228 S_GMANPROC = 4394,
229 S_LMANPROC = 4395,
230 S_ATTR_FRAMEREL = 4398,
231 S_ATTR_REGISTER = 4399,
232 S_ATTR_REGREL = 4400,
233 S_ATTR_MANYREG = 4401,
234 S_SEPCODE = 4402,
235 S_LOCAL_2005 = 4403,
236 S_DEFRANGE_2005 = 4404,
237 S_DEFRANGE2_2005 = 4405,
238 S_DISCARDED = 4411,
239 S_LPROCMIPS_ID = 4424,
240 S_GPROCMIPS_ID = 4425,
241 S_LPROCIA64_ID = 4426,
242 S_GPROCIA64_ID = 4427,
243 S_DEFRANGE_HLSL = 4432,
244 S_GDATA_HLSL = 4433,
245 S_LDATA_HLSL = 4434,
246 S_LOCAL_DPC_GROUPSHARED = 4436,
247 S_DEFRANGE_DPC_PTR_TAG = 4439,
248 S_DPC_SYM_TAG_MAP = 4440,
249 S_ARMSWITCHTABLE = 4441,
250 S_POGODATA = 4444,
251 S_INLINESITE2 = 4445,
252 S_MOD_TYPEREF = 4447,
253 S_REF_MINIPDB = 4448,
254 S_PDBMAP = 4449,
255 S_GDATA_HLSL32 = 4450,
256 S_LDATA_HLSL32 = 4451,
257 S_GDATA_HLSL32_EX = 4452,
258 S_LDATA_HLSL32_EX = 4453,
259 S_FASTLINK = 4455,
260 S_INLINEES = 4456,
261 S_END = 6,
262 S_INLINESITE_END = 4430,
263 S_PROC_ID_END = 4431,
264 S_THUNK32 = 4354,
265 S_TRAMPOLINE = 4396,
266 S_SECTION = 4406,
267 S_COFFGROUP = 4407,
268 S_EXPORT = 4408,
269 S_LPROC32 = 4367,
270 S_GPROC32 = 4368,
271 S_LPROC32_ID = 4422,
272 S_GPROC32_ID = 4423,
273 S_LPROC32_DPC = 4437,
274 S_LPROC32_DPC_ID = 4438,
275 S_REGISTER = 4358,
276 S_PUB32 = 4366,
277 S_PROCREF = 4389,
278 S_LPROCREF = 4391,
279 S_ENVBLOCK = 4413,
280 S_INLINESITE = 4429,
281 S_LOCAL = 4414,
282 S_DEFRANGE = 4415,
283 S_DEFRANGE_SUBFIELD = 4416,
284 S_DEFRANGE_REGISTER = 4417,
285 S_DEFRANGE_FRAMEPOINTER_REL = 4418,
286 S_DEFRANGE_SUBFIELD_REGISTER = 4419,
287 S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE = 4420,
288 S_DEFRANGE_REGISTER_REL = 4421,
289 S_BLOCK32 = 4355,
290 S_LABEL32 = 4357,
291 S_OBJNAME = 4353,
292 S_COMPILE2 = 4374,
293 S_COMPILE3 = 4412,
294 S_FRAMEPROC = 4114,
295 S_CALLSITEINFO = 4409,
296 S_FILESTATIC = 4435,
297 S_HEAPALLOCSITE = 4446,
298 S_FRAMECOOKIE = 4410,
299 S_CALLEES = 4442,
300 S_CALLERS = 4443,
301 S_UDT = 4360,
302 S_COBOLUDT = 4361,
303 S_BUILDINFO = 4428,
304 S_BPREL32 = 4363,
305 S_REGREL32 = 4369,
306 S_CONSTANT = 4359,
307 S_MANCONSTANT = 4397,
308 S_LDATA32 = 4364,
309 S_GDATA32 = 4365,
310 S_LMANDATA = 4380,
311 S_GMANDATA = 4381,
312 S_LTHREAD32 = 4370,
313 S_GTHREAD32 = 4371,
118 compile = 1,
119 register_16t = 2,
120 constant_16t = 3,
121 udt_16t = 4,
122 ssearch = 5,
123 skip = 7,
124 cvreserve = 8,
125 objname_st = 9,
126 endarg = 10,
127 coboludt_16t = 11,
128 manyreg_16t = 12,
129 @"return" = 13,
130 entrythis = 14,
131 bprel16 = 256,
132 ldata16 = 257,
133 gdata16 = 258,
134 pub16 = 259,
135 lproc16 = 260,
136 gproc16 = 261,
137 thunk16 = 262,
138 block16 = 263,
139 with16 = 264,
140 label16 = 265,
141 cexmodel16 = 266,
142 vftable16 = 267,
143 regrel16 = 268,
144 bprel32_16t = 512,
145 ldata32_16t = 513,
146 gdata32_16t = 514,
147 pub32_16t = 515,
148 lproc32_16t = 516,
149 gproc32_16t = 517,
150 thunk32_st = 518,
151 block32_st = 519,
152 with32_st = 520,
153 label32_st = 521,
154 cexmodel32 = 522,
155 vftable32_16t = 523,
156 regrel32_16t = 524,
157 lthread32_16t = 525,
158 gthread32_16t = 526,
159 slink32 = 527,
160 lprocmips_16t = 768,
161 gprocmips_16t = 769,
162 procref_st = 1024,
163 dataref_st = 1025,
164 @"align" = 1026,
165 lprocref_st = 1027,
166 oem = 1028,
167 ti16_max = 4096,
168 register_st = 4097,
169 constant_st = 4098,
170 udt_st = 4099,
171 coboludt_st = 4100,
172 manyreg_st = 4101,
173 bprel32_st = 4102,
174 ldata32_st = 4103,
175 gdata32_st = 4104,
176 pub32_st = 4105,
177 lproc32_st = 4106,
178 gproc32_st = 4107,
179 vftable32 = 4108,
180 regrel32_st = 4109,
181 lthread32_st = 4110,
182 gthread32_st = 4111,
183 lprocmips_st = 4112,
184 gprocmips_st = 4113,
185 compile2_st = 4115,
186 manyreg2_st = 4116,
187 lprocia64_st = 4117,
188 gprocia64_st = 4118,
189 localslot_st = 4119,
190 paramslot_st = 4120,
191 annotation = 4121,
192 gmanproc_st = 4122,
193 lmanproc_st = 4123,
194 reserved1 = 4124,
195 reserved2 = 4125,
196 reserved3 = 4126,
197 reserved4 = 4127,
198 lmandata_st = 4128,
199 gmandata_st = 4129,
200 manframerel_st = 4130,
201 manregister_st = 4131,
202 manslot_st = 4132,
203 manmanyreg_st = 4133,
204 manregrel_st = 4134,
205 manmanyreg2_st = 4135,
206 mantypref = 4136,
207 unamespace_st = 4137,
208 st_max = 4352,
209 with32 = 4356,
210 manyreg = 4362,
211 lprocmips = 4372,
212 gprocmips = 4373,
213 manyreg2 = 4375,
214 lprocia64 = 4376,
215 gprocia64 = 4377,
216 localslot = 4378,
217 paramslot = 4379,
218 manframerel = 4382,
219 manregister = 4383,
220 manslot = 4384,
221 manmanyreg = 4385,
222 manregrel = 4386,
223 manmanyreg2 = 4387,
224 unamespace = 4388,
225 dataref = 4390,
226 annotationref = 4392,
227 tokenref = 4393,
228 gmanproc = 4394,
229 lmanproc = 4395,
230 attr_framerel = 4398,
231 attr_register = 4399,
232 attr_regrel = 4400,
233 attr_manyreg = 4401,
234 sepcode = 4402,
235 local_2005 = 4403,
236 defrange_2005 = 4404,
237 defrange2_2005 = 4405,
238 discarded = 4411,
239 lprocmips_id = 4424,
240 gprocmips_id = 4425,
241 lprocia64_id = 4426,
242 gprocia64_id = 4427,
243 defrange_hlsl = 4432,
244 gdata_hlsl = 4433,
245 ldata_hlsl = 4434,
246 local_dpc_groupshared = 4436,
247 defrange_dpc_ptr_tag = 4439,
248 dpc_sym_tag_map = 4440,
249 armswitchtable = 4441,
250 pogodata = 4444,
251 inlinesite2 = 4445,
252 mod_typeref = 4447,
253 ref_minipdb = 4448,
254 pdbmap = 4449,
255 gdata_hlsl32 = 4450,
256 ldata_hlsl32 = 4451,
257 gdata_hlsl32_ex = 4452,
258 ldata_hlsl32_ex = 4453,
259 fastlink = 4455,
260 inlinees = 4456,
261 end = 6,
262 inlinesite_end = 4430,
263 proc_id_end = 4431,
264 thunk32 = 4354,
265 trampoline = 4396,
266 section = 4406,
267 coffgroup = 4407,
268 @"export" = 4408,
269 lproc32 = 4367,
270 gproc32 = 4368,
271 lproc32_id = 4422,
272 gproc32_id = 4423,
273 lproc32_dpc = 4437,
274 lproc32_dpc_id = 4438,
275 register = 4358,
276 pub32 = 4366,
277 procref = 4389,
278 lprocref = 4391,
279 envblock = 4413,
280 inlinesite = 4429,
281 local = 4414,
282 defrange = 4415,
283 defrange_subfield = 4416,
284 defrange_register = 4417,
285 defrange_framepointer_rel = 4418,
286 defrange_subfield_register = 4419,
287 defrange_framepointer_rel_full_scope = 4420,
288 defrange_register_rel = 4421,
289 block32 = 4355,
290 label32 = 4357,
291 objname = 4353,
292 compile2 = 4374,
293 compile3 = 4412,
294 frameproc = 4114,
295 callsiteinfo = 4409,
296 filestatic = 4435,
297 heapallocsite = 4446,
298 framecookie = 4410,
299 callees = 4442,
300 callers = 4443,
301 udt = 4360,
302 coboludt = 4361,
303 buildinfo = 4428,
304 bprel32 = 4363,
305 regrel32 = 4369,
306 constant = 4359,
307 manconstant = 4397,
308 ldata32 = 4364,
309 gdata32 = 4365,
310 lmandata = 4380,
311 gmandata = 4381,
312 lthread32 = 4370,
313 gthread32 = 4371,
314314};
315315
316316pub const TypeIndex = u32;
......@@ -320,28 +320,28 @@ pub const TypeIndex = u32;
320320// we should define RecordPrefix as part of the ProcSym structure.
321321// This might be important when we start generating PDB in self-hosted with our own PE linker.
322322pub const ProcSym = extern struct {
323 Parent: u32,
324 End: u32,
325 Next: u32,
326 CodeSize: u32,
327 DbgStart: u32,
328 DbgEnd: u32,
329 FunctionType: TypeIndex,
330 CodeOffset: u32,
331 Segment: u16,
332 Flags: ProcSymFlags,
333 Name: [1]u8, // null-terminated
323 parent: u32,
324 end: u32,
325 next: u32,
326 code_size: u32,
327 dbg_start: u32,
328 dbg_end: u32,
329 function_type: TypeIndex,
330 code_offset: u32,
331 segment: u16,
332 flags: ProcSymFlags,
333 name: [1]u8, // null-terminated
334334};
335335
336336pub const ProcSymFlags = packed struct {
337 HasFP: bool,
338 HasIRET: bool,
339 HasFRET: bool,
340 IsNoReturn: bool,
341 IsUnreachable: bool,
342 HasCustomCallingConv: bool,
343 IsNoInline: bool,
344 HasOptimizedDebugInfo: bool,
337 has_fp: bool,
338 has_iret: bool,
339 has_fret: bool,
340 is_no_return: bool,
341 is_unreachable: bool,
342 has_custom_calling_conv: bool,
343 is_no_inline: bool,
344 has_optimized_debug_info: bool,
345345};
346346
347347pub const SectionContrSubstreamVersion = enum(u32) {
......@@ -351,11 +351,11 @@ pub const SectionContrSubstreamVersion = enum(u32) {
351351};
352352
353353pub const RecordPrefix = extern struct {
354 /// Record length, starting from &RecordKind.
355 RecordLen: u16,
354 /// Record length, starting from &record_kind.
355 record_len: u16,
356356
357357 /// Record kind enum (SymRecordKind or TypeRecordKind)
358 RecordKind: SymbolKind,
358 record_kind: SymbolKind,
359359};
360360
361361/// The following variable length array appears immediately after the header.
......@@ -364,19 +364,19 @@ pub const RecordPrefix = extern struct {
364364/// Each `LineBlockFragmentHeader` as specified below.
365365pub const LineFragmentHeader = extern struct {
366366 /// Code offset of line contribution.
367 RelocOffset: u32,
367 reloc_offset: u32,
368368
369369 /// Code segment of line contribution.
370 RelocSegment: u16,
371 Flags: LineFlags,
370 reloc_segment: u16,
371 flags: LineFlags,
372372
373373 /// Code size of this line contribution.
374 CodeSize: u32,
374 code_size: u32,
375375};
376376
377377pub const LineFlags = packed struct {
378378 /// CV_LINES_HAVE_COLUMNS
379 LF_HaveColumns: bool,
379 have_columns: bool,
380380 unused: u15,
381381};
382382
......@@ -389,107 +389,109 @@ pub const LineBlockFragmentHeader = extern struct {
389389 /// checksums buffer. The checksum entry then
390390 /// contains another offset into the string
391391 /// table of the actual name.
392 NameIndex: u32,
393 NumLines: u32,
392 name_index: u32,
393 num_lines: u32,
394394
395395 /// code size of block, in bytes
396 BlockSize: u32,
396 block_size: u32,
397397};
398398
399399pub const LineNumberEntry = extern struct {
400400 /// Offset to start of code bytes for line number
401 Offset: u32,
402 Flags: packed struct(u32) {
401 offset: u32,
402 flags: Flags,
403
404 pub const Flags = packed struct(u32) {
403405 /// Start line number
404 Start: u24,
406 start: u24,
405407 /// Delta of lines to the end of the expression. Still unclear.
406408 // TODO figure out the point of this field.
407 End: u7,
408 IsStatement: bool,
409 },
409 end: u7,
410 is_statement: bool,
411 };
410412};
411413
412414pub const ColumnNumberEntry = extern struct {
413 StartColumn: u16,
414 EndColumn: u16,
415 start_column: u16,
416 end_column: u16,
415417};
416418
417419/// Checksum bytes follow.
418420pub const FileChecksumEntryHeader = extern struct {
419421 /// Byte offset of filename in global string table.
420 FileNameOffset: u32,
422 file_name_offset: u32,
421423 /// Number of bytes of checksum.
422 ChecksumSize: u8,
424 checksum_size: u8,
423425 /// FileChecksumKind
424 ChecksumKind: u8,
426 checksum_kind: u8,
425427};
426428
427429pub const DebugSubsectionKind = enum(u32) {
428 None = 0,
429 Symbols = 0xf1,
430 Lines = 0xf2,
431 StringTable = 0xf3,
432 FileChecksums = 0xf4,
433 FrameData = 0xf5,
434 InlineeLines = 0xf6,
435 CrossScopeImports = 0xf7,
436 CrossScopeExports = 0xf8,
430 none = 0,
431 symbols = 0xf1,
432 lines = 0xf2,
433 string_table = 0xf3,
434 file_checksums = 0xf4,
435 frame_data = 0xf5,
436 inlinee_lines = 0xf6,
437 cross_scope_imports = 0xf7,
438 cross_scope_exports = 0xf8,
437439
438440 // These appear to relate to .Net assembly info.
439 ILLines = 0xf9,
440 FuncMDTokenMap = 0xfa,
441 TypeMDTokenMap = 0xfb,
442 MergedAssemblyInput = 0xfc,
441 il_lines = 0xf9,
442 func_md_token_map = 0xfa,
443 type_md_token_map = 0xfb,
444 merged_assembly_input = 0xfc,
443445
444 CoffSymbolRVA = 0xfd,
446 coff_symbol_rva = 0xfd,
445447};
446448
447449pub const DebugSubsectionHeader = extern struct {
448450 /// codeview::DebugSubsectionKind enum
449 Kind: DebugSubsectionKind,
451 kind: DebugSubsectionKind,
450452
451453 /// number of bytes occupied by this record.
452 Length: u32,
454 length: u32,
453455};
454456
455457pub const StringTableHeader = extern struct {
456458 /// PDBStringTableSignature
457 Signature: u32,
459 signature: u32,
458460 /// 1 or 2
459 HashVersion: u32,
461 hash_version: u32,
460462 /// Number of bytes of names buffer.
461 ByteSize: u32,
463 byte_size: u32,
462464};
463465
464466// https://llvm.org/docs/PDB/MsfFile.html#the-superblock
465467pub const SuperBlock = extern struct {
466468 /// The LLVM docs list a space between C / C++ but empirically this is not the case.
467 pub const file_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";
469 pub const expect_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";
468470
469 FileMagic: [file_magic.len]u8,
471 file_magic: [expect_magic.len]u8,
470472
471473 /// The block size of the internal file system. Valid values are 512, 1024,
472474 /// 2048, and 4096 bytes. Certain aspects of the MSF file layout vary depending
473475 /// on the block sizes. For the purposes of LLVM, we handle only block sizes of
474476 /// 4KiB, and all further discussion assumes a block size of 4KiB.
475 BlockSize: u32,
477 block_size: u32,
476478
477479 /// The index of a block within the file, at which begins a bitfield representing
478480 /// the set of all blocks within the file which are “free” (i.e. the data within
479481 /// that block is not used). See The Free Block Map for more information. Important:
480482 /// FreeBlockMapBlock can only be 1 or 2!
481 FreeBlockMapBlock: u32,
483 free_block_map_block: u32,
482484
483485 /// The total number of blocks in the file. NumBlocks * BlockSize should equal the
484486 /// size of the file on disk.
485 NumBlocks: u32,
487 num_blocks: u32,
486488
487489 /// The size of the stream directory, in bytes. The stream directory contains
488490 /// information about each stream’s size and the set of blocks that it occupies.
489491 /// It will be described in more detail later.
490 NumDirectoryBytes: u32,
492 num_directory_bytes: u32,
491493
492 Unknown: u32,
494 unknown: u32,
493495 /// The index of a block within the MSF file. At this block is an array of
494496 /// ulittle32_t’s listing the blocks that the stream directory resides on.
495497 /// For large MSF files, the stream directory (which describes the block
......@@ -505,5 +507,5 @@ pub const SuperBlock = extern struct {
505507 // This would mean the Stream Directory is bigger than BlockSize / sizeof(u32)
506508 // blocks. We're not even close to this with a 1GB pdb file, and LLVM didn't
507509 // implement it so we're kind of safe making this assumption for now.
508 BlockMapAddr: u32,
510 block_map_addr: u32,
509511};