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