| ... | ... | @@ -14,7 +14,7 @@ const ArrayList = std.ArrayList; |
| 14 | 14 | // documentation and/or contributors. |
| 15 | 15 | |
| 16 | 16 | // https://llvm.org/docs/PDB/DbiStream.html#stream-header |
| 17 | | pub const DbiStreamHeader = packed struct { |
| 17 | pub const DbiStreamHeader = extern struct { |
| 18 | 18 | VersionSignature: i32, |
| 19 | 19 | VersionHeader: u32, |
| 20 | 20 | Age: u32, |
| ... | ... | @@ -37,7 +37,7 @@ pub const DbiStreamHeader = packed struct { |
| 37 | 37 | Padding: u32, |
| 38 | 38 | }; |
| 39 | 39 | |
| 40 | | pub const SectionContribEntry = packed struct { |
| 40 | pub const SectionContribEntry = extern struct { |
| 41 | 41 | /// COFF Section index, 1-based |
| 42 | 42 | Section: u16, |
| 43 | 43 | Padding1: [2]u8, |
| ... | ... | @@ -50,7 +50,7 @@ pub const SectionContribEntry = packed struct { |
| 50 | 50 | RelocCrc: u32, |
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | | pub const ModInfo = packed struct { |
| 53 | pub const ModInfo = extern struct { |
| 54 | 54 | Unused1: u32, |
| 55 | 55 | SectionContr: SectionContribEntry, |
| 56 | 56 | Flags: u16, |
| ... | ... | @@ -68,7 +68,7 @@ pub const ModInfo = packed struct { |
| 68 | 68 | //ObjFileName: char[], |
| 69 | 69 | }; |
| 70 | 70 | |
| 71 | | pub const SectionMapHeader = packed struct { |
| 71 | pub const SectionMapHeader = extern struct { |
| 72 | 72 | /// Number of segment descriptors |
| 73 | 73 | Count: u16, |
| 74 | 74 | |
| ... | ... | @@ -76,7 +76,7 @@ pub const SectionMapHeader = packed struct { |
| 76 | 76 | LogCount: u16, |
| 77 | 77 | }; |
| 78 | 78 | |
| 79 | | pub const SectionMapEntry = packed struct { |
| 79 | pub const SectionMapEntry = extern struct { |
| 80 | 80 | /// See the SectionMapEntryFlags enum below. |
| 81 | 81 | Flags: u16, |
| 82 | 82 | |
| ... | ... | @@ -310,7 +310,7 @@ pub const SymbolKind = enum(u16) { |
| 310 | 310 | |
| 311 | 311 | pub const TypeIndex = u32; |
| 312 | 312 | |
| 313 | | pub const ProcSym = packed struct { |
| 313 | pub const ProcSym = extern struct { |
| 314 | 314 | Parent: u32, |
| 315 | 315 | End: u32, |
| 316 | 316 | Next: u32, |
| ... | ... | @@ -342,7 +342,7 @@ pub const SectionContrSubstreamVersion = enum(u32) { |
| 342 | 342 | _, |
| 343 | 343 | }; |
| 344 | 344 | |
| 345 | | pub const RecordPrefix = packed struct { |
| 345 | pub const RecordPrefix = extern struct { |
| 346 | 346 | /// Record length, starting from &RecordKind. |
| 347 | 347 | RecordLen: u16, |
| 348 | 348 | |
| ... | ... | @@ -354,7 +354,7 @@ pub const RecordPrefix = packed struct { |
| 354 | 354 | /// The structure definition follows. |
| 355 | 355 | /// LineBlockFragmentHeader Blocks[] |
| 356 | 356 | /// Each `LineBlockFragmentHeader` as specified below. |
| 357 | | pub const LineFragmentHeader = packed struct { |
| 357 | pub const LineFragmentHeader = extern struct { |
| 358 | 358 | /// Code offset of line contribution. |
| 359 | 359 | RelocOffset: u32, |
| 360 | 360 | |
| ... | ... | @@ -376,7 +376,7 @@ pub const LineFlags = packed struct { |
| 376 | 376 | /// header. The structure definitions follow. |
| 377 | 377 | /// LineNumberEntry Lines[NumLines]; |
| 378 | 378 | /// ColumnNumberEntry Columns[NumLines]; |
| 379 | | pub const LineBlockFragmentHeader = packed struct { |
| 379 | pub const LineBlockFragmentHeader = extern struct { |
| 380 | 380 | /// Offset of FileChecksum entry in File |
| 381 | 381 | /// checksums buffer. The checksum entry then |
| 382 | 382 | /// contains another offset into the string |
| ... | ... | @@ -388,7 +388,7 @@ pub const LineBlockFragmentHeader = packed struct { |
| 388 | 388 | BlockSize: u32, |
| 389 | 389 | }; |
| 390 | 390 | |
| 391 | | pub const LineNumberEntry = packed struct { |
| 391 | pub const LineNumberEntry = extern struct { |
| 392 | 392 | /// Offset to start of code bytes for line number |
| 393 | 393 | Offset: u32, |
| 394 | 394 | Flags: u32, |
| ... | ... | @@ -404,13 +404,13 @@ pub const LineNumberEntry = packed struct { |
| 404 | 404 | }; |
| 405 | 405 | }; |
| 406 | 406 | |
| 407 | | pub const ColumnNumberEntry = packed struct { |
| 407 | pub const ColumnNumberEntry = extern struct { |
| 408 | 408 | StartColumn: u16, |
| 409 | 409 | EndColumn: u16, |
| 410 | 410 | }; |
| 411 | 411 | |
| 412 | 412 | /// Checksum bytes follow. |
| 413 | | pub const FileChecksumEntryHeader = packed struct { |
| 413 | pub const FileChecksumEntryHeader = extern struct { |
| 414 | 414 | /// Byte offset of filename in global string table. |
| 415 | 415 | FileNameOffset: u32, |
| 416 | 416 | |
| ... | ... | @@ -441,7 +441,7 @@ pub const DebugSubsectionKind = enum(u32) { |
| 441 | 441 | CoffSymbolRVA = 0xfd, |
| 442 | 442 | }; |
| 443 | 443 | |
| 444 | | pub const DebugSubsectionHeader = packed struct { |
| 444 | pub const DebugSubsectionHeader = extern struct { |
| 445 | 445 | /// codeview::DebugSubsectionKind enum |
| 446 | 446 | Kind: DebugSubsectionKind, |
| 447 | 447 | |
| ... | ... | @@ -449,7 +449,7 @@ pub const DebugSubsectionHeader = packed struct { |
| 449 | 449 | Length: u32, |
| 450 | 450 | }; |
| 451 | 451 | |
| 452 | | pub const PDBStringTableHeader = packed struct { |
| 452 | pub const PDBStringTableHeader = extern struct { |
| 453 | 453 | /// PDBStringTableSignature |
| 454 | 454 | Signature: u32, |
| 455 | 455 | |
| ... | ... | @@ -686,12 +686,12 @@ pub const Pdb = struct { |
| 686 | 686 | |
| 687 | 687 | var symbol_i: usize = 0; |
| 688 | 688 | while (symbol_i != module.symbols.len) { |
| 689 | | const prefix = @ptrCast(*RecordPrefix, &module.symbols[symbol_i]); |
| 689 | const prefix = @ptrCast(*align(1) RecordPrefix, &module.symbols[symbol_i]); |
| 690 | 690 | if (prefix.RecordLen < 2) |
| 691 | 691 | return null; |
| 692 | 692 | switch (prefix.RecordKind) { |
| 693 | 693 | .S_LPROC32, .S_GPROC32 => { |
| 694 | | const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]); |
| 694 | const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]); |
| 695 | 695 | if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) { |
| 696 | 696 | return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0); |
| 697 | 697 | } |
| ... | ... | @@ -712,7 +712,7 @@ pub const Pdb = struct { |
| 712 | 712 | var skip_len: usize = undefined; |
| 713 | 713 | const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo; |
| 714 | 714 | while (sect_offset != subsect_info.len) : (sect_offset += skip_len) { |
| 715 | | const subsect_hdr = @ptrCast(*DebugSubsectionHeader, &subsect_info[sect_offset]); |
| 715 | const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &subsect_info[sect_offset]); |
| 716 | 716 | skip_len = subsect_hdr.Length; |
| 717 | 717 | sect_offset += @sizeOf(DebugSubsectionHeader); |
| 718 | 718 | |
| ... | ... | @@ -720,7 +720,7 @@ pub const Pdb = struct { |
| 720 | 720 | .Lines => { |
| 721 | 721 | var line_index = sect_offset; |
| 722 | 722 | |
| 723 | | const line_hdr = @ptrCast(*LineFragmentHeader, &subsect_info[line_index]); |
| 723 | const line_hdr = @ptrCast(*align(1) LineFragmentHeader, &subsect_info[line_index]); |
| 724 | 724 | if (line_hdr.RelocSegment == 0) |
| 725 | 725 | return error.MissingDebugInfo; |
| 726 | 726 | line_index += @sizeOf(LineFragmentHeader); |
| ... | ... | @@ -734,7 +734,7 @@ pub const Pdb = struct { |
| 734 | 734 | const subsection_end_index = sect_offset + subsect_hdr.Length; |
| 735 | 735 | |
| 736 | 736 | while (line_index < subsection_end_index) { |
| 737 | | const block_hdr = @ptrCast(*LineBlockFragmentHeader, &subsect_info[line_index]); |
| 737 | const block_hdr = @ptrCast(*align(1) LineBlockFragmentHeader, &subsect_info[line_index]); |
| 738 | 738 | line_index += @sizeOf(LineBlockFragmentHeader); |
| 739 | 739 | const start_line_index = line_index; |
| 740 | 740 | |
| ... | ... | @@ -746,7 +746,7 @@ pub const Pdb = struct { |
| 746 | 746 | // This is done with a simple linear search. |
| 747 | 747 | var line_i: u32 = 0; |
| 748 | 748 | while (line_i < block_hdr.NumLines) : (line_i += 1) { |
| 749 | | const line_num_entry = @ptrCast(*LineNumberEntry, &subsect_info[line_index]); |
| 749 | const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[line_index]); |
| 750 | 750 | line_index += @sizeOf(LineNumberEntry); |
| 751 | 751 | |
| 752 | 752 | const vaddr_start = frag_vaddr_start + line_num_entry.Offset; |
| ... | ... | @@ -758,7 +758,7 @@ pub const Pdb = struct { |
| 758 | 758 | // line_i == 0 would mean that no matching LineNumberEntry was found. |
| 759 | 759 | if (line_i > 0) { |
| 760 | 760 | const subsect_index = checksum_offset + block_hdr.NameIndex; |
| 761 | | const chksum_hdr = @ptrCast(*FileChecksumEntryHeader, &module.subsect_info[subsect_index]); |
| 761 | const chksum_hdr = @ptrCast(*align(1) FileChecksumEntryHeader, &module.subsect_info[subsect_index]); |
| 762 | 762 | const strtab_offset = @sizeOf(PDBStringTableHeader) + chksum_hdr.FileNameOffset; |
| 763 | 763 | try self.string_table.?.seekTo(strtab_offset); |
| 764 | 764 | const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024); |
| ... | ... | @@ -768,12 +768,12 @@ pub const Pdb = struct { |
| 768 | 768 | const column = if (has_column) blk: { |
| 769 | 769 | const start_col_index = start_line_index + @sizeOf(LineNumberEntry) * block_hdr.NumLines; |
| 770 | 770 | const col_index = start_col_index + @sizeOf(ColumnNumberEntry) * line_entry_idx; |
| 771 | | const col_num_entry = @ptrCast(*ColumnNumberEntry, &subsect_info[col_index]); |
| 771 | const col_num_entry = @ptrCast(*align(1) ColumnNumberEntry, &subsect_info[col_index]); |
| 772 | 772 | break :blk col_num_entry.StartColumn; |
| 773 | 773 | } else 0; |
| 774 | 774 | |
| 775 | 775 | const found_line_index = start_line_index + line_entry_idx * @sizeOf(LineNumberEntry); |
| 776 | | const line_num_entry = @ptrCast(*LineNumberEntry, &subsect_info[found_line_index]); |
| 776 | const line_num_entry = @ptrCast(*align(1) LineNumberEntry, &subsect_info[found_line_index]); |
| 777 | 777 | const flags = @ptrCast(*LineNumberEntry.Flags, &line_num_entry.Flags); |
| 778 | 778 | |
| 779 | 779 | return debug.LineInfo{ |
| ... | ... | @@ -833,7 +833,7 @@ pub const Pdb = struct { |
| 833 | 833 | var sect_offset: usize = 0; |
| 834 | 834 | var skip_len: usize = undefined; |
| 835 | 835 | while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) { |
| 836 | | const subsect_hdr = @ptrCast(*DebugSubsectionHeader, &mod.subsect_info[sect_offset]); |
| 836 | const subsect_hdr = @ptrCast(*align(1) DebugSubsectionHeader, &mod.subsect_info[sect_offset]); |
| 837 | 837 | skip_len = subsect_hdr.Length; |
| 838 | 838 | sect_offset += @sizeOf(DebugSubsectionHeader); |
| 839 | 839 | |
| ... | ... | @@ -969,7 +969,7 @@ fn blockCountFromSize(size: u32, block_size: u32) u32 { |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | // https://llvm.org/docs/PDB/MsfFile.html#the-superblock |
| 972 | | const SuperBlock = packed struct { |
| 972 | const SuperBlock = extern struct { |
| 973 | 973 | /// The LLVM docs list a space between C / C++ but empirically this is not the case. |
| 974 | 974 | const file_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00"; |
| 975 | 975 | |