跳转到内容
标准库Zig 0.17.0官方原文
源码std/pdb.zig

第 1 行

程序数据库调试信息格式。

此命名空间仅包含不附带特定策略的类型和数据定义。 有关解析和缓存 PDB 信息的实现,请参见 std.debug.Pdb。

此处大部分内容基于从 LLVM 源码、 文档或贡献者处收集的信息。

std.pdb.ArrayList

别名

第 18 行

别名目标 std.ArrayList

std.pdb.BinaryAnnotationOpcode

容器

第 634 行

字段

invalid = 0
code_offset = 1
change_code_offset_base = 2
change_code_offset = 3
change_code_length = 4
change_file = 5
change_line_offset = 6
change_line_end_delta = 7
change_range_kind = 8
change_column_start = 9
change_column_end_delta = 10
change_code_offset_and_line_offset = 11
change_code_length_and_code_offset = 12
change_column_end = 13

std.pdb.coff

别名

第 13 行

别名目标 std.coff

std.pdb.ColumnNumberEntry

容器

第 411 行

字段

start_column: u16
end_column: u16

std.pdb.DbiStreamHeader

容器

第 21 行

字段

version_signature: i32
version_header: u32
age: u32
global_stream_index: u16
build_number: u16
public_stream_index: u16
pdb_dll_version: u16
sym_record_stream: u16
pdb_dll_rbld: u16
mod_info_size: u32
section_contribution_size: u32
section_map_size: u32
source_info_size: i32
type_server_size: i32
mfc_type_server_index: u32
optional_dbg_header_size: i32
ec_substream_size: i32
flags: u16
machine: u16
padding: u32

std.pdb.debug

别名

第 16 行

别名目标 std.debug

std.pdb.DebugSubsectionHeader

容器

第 446 行

字段

kind: DebugSubsectionKind

codeview::DebugSubsectionKind 枚举

length: u32

此记录占用的字节数。

std.pdb.DebugSubsectionKind

容器

第 426 行

字段

none = 0
symbols = 0xf1
lines = 0xf2
string_table = 0xf3
file_checksums = 0xf4
frame_data = 0xf5
inlinee_lines = 0xf6
cross_scope_imports = 0xf7
cross_scope_exports = 0xf8
il_lines = 0xf9
func_md_token_map = 0xfa
type_md_token_map = 0xfb
merged_assembly_input = 0xfc
coff_symbol_rva = 0xfd

std.pdb.File

别名

第 15 行

别名目标 std.Io.File

std.pdb.FileChecksumEntryHeader

容器

第 417 行

校验和字节紧随其后。

字段

file_name_offset: u32

全局字符串表中文件名的字节偏移量。

checksum_size: u8

校验和的字节数。

checksum_kind: u8

FileChecksumKind

std.pdb.fs

别名

第 14 行

别名目标 std.fs

std.pdb.InlineeSourceLine

容器

第 621 行

字段

inlinee: u32
file_id: u32
source_line_num: u32

std.pdb.InlineeSourceLineEx

容器

第 627 行

字段

inlinee: u32
file_id: u32
source_line_num: u32
count_of_extra_files: u32

std.pdb.InlineeSourceLineSignature

容器

第 619 行

字段

normal = 0
ex = 1
_

std.pdb.InlineSiteSym

容器

第 602 行

字段

record_len: u16
record_kind: SymbolKind
parent: u32
end: u32
inlinee: u32

std.pdb.InlineSiteSym2

容器

第 610 行

字段

record_len: u16
record_kind: SymbolKind
parent: u32
end: u32
inlinee: u32
invocations: u32

std.pdb.IpiStreamHeader

容器

第 519 行

字段

version: IpiStreamVersion
header_size: u32
type_index_begin: u32
type_index_end: u32
type_record_bytes: u32
hash_stream_index: u16
hash_aux_stream_index: u16
hash_key_size: u32
num_hash_buckets: u32
hash_value_buffer_offset: i32
hash_value_buffer_length: u32
index_offset_buffer_offset: i32
index_offset_buffer_length: u32
hash_adj_buffer_offset: i32
hash_adj_buffer_length: u32

std.pdb.IpiStreamVersion

容器

第 510 行

字段

v40 = 19950410
v41 = 19951122
v50 = 19961031
v70 = 19990903
v80 = 20040203
_

std.pdb.LfFuncId

容器

第 586 行

字段

len: u16
kind: LfRecordKind
scope_id: u32
type: u32
name: [1]u8

std.pdb.LfMFuncId

容器

第 594 行

字段

len: u16
kind: LfRecordKind
parent_type: u32
type: u32
name: [1]u8

std.pdb.LfRecordKind

容器

第 542 行

字段

pointer = 0x1002
modifier = 0x1001
procedure = 0x1008
mfunction = 0x1009
label = 0x000e
arglist = 0x1201
fieldlist = 0x1203
array = 0x1503
class = 0x1504
structure = 0x1505
interface = 0x1519
@"union" = 0x1506
@"enum" = 0x1507
typeserver2 = 0x1515
vftable = 0x151d
vtshape = 0x000a
bitfield = 0x1205
func_id = 0x1601
mfunc_id = 0x1602
buildinfo = 0x1603
substr_list = 0x1604
string_id = 0x1605
udt_src_line = 0x1606
udt_mod_src_line = 0x1607
methodlist = 0x1206
precomp = 0x1509
endprecomp = 0x0014
bclass = 0x1400
binterface = 0x151a
vbclass = 0x1401
ivbclass = 0x1402
vfunctab = 0x1409
stmember = 0x150e
method = 0x150f
member = 0x150d
nesttype = 0x1510
onemethod = 0x1511
enumerate = 0x1502
index = 0x1404
pad0 = 0xf0
_

std.pdb.LfRecordPrefix

容器

第 537 行

字段

len: u16
kind: LfRecordKind

std.pdb.LineBlockFragmentHeader

容器

第 384 行

以下两个变长数组紧随头部之后出现。 结构定义如下。 LineNumberEntry Lines[NumLines]; ColumnNumberEntry Columns[NumLines];

字段

name_index: u32

FileChecksum 条目在文件校验和缓冲区中的偏移。 该校验和条目又包含另一个偏移, 指向字符串表中的 实际文件名。

num_lines: u32
block_size: u32

块的代码大小,单位为字节

std.pdb.LineFlags

容器

第 374 行

字段

have_columns: bool

CV_LINES_HAVE_COLUMNS

unused: u15

std.pdb.LineFragmentHeader

容器

第 362 行

以下变长数组紧随头部之后出现。 结构定义如下。 LineBlockFragmentHeader Blocks[] 各 LineBlockFragmentHeader 的定义见下文。

字段

reloc_offset: u32

行贡献的代码偏移量。

reloc_segment: u16

行信息贡献项的代码段。

flags: LineFlags
code_size: u32

此行信息贡献项的代码大小。

std.pdb.LineNumberEntry

容器

第 396 行

字段

offset: u32

该行号对应代码字节起始位置的偏移量

flags: Flags

std.pdb.LineNumberEntry.Flags

容器

第 401 行

字段

start: u24

起始行号

end: u7

到表达式末尾的行数差。含义仍不明确。

is_statement: bool

std.pdb.math

别名

第 11 行

别名目标 std.math

std.pdb.mem

别名

第 12 行

别名目标 std.mem

std.pdb.ModInfo

容器

第 57 行

字段

unused1: u32
section_contr: SectionContribEntry
flags: u16
module_sym_stream: u16
sym_byte_size: u32
c11_byte_size: u32
c13_byte_size: u32
source_file_count: u16
padding: [2]u8
unused2: u32
source_file_name_index: u32
pdb_file_path_name_index: u32

std.pdb.ProcSym

容器

第 317 行

字段

record_len: u16
record_kind: SymbolKind
parent: u32
end: u32
next: u32
code_size: u32
dbg_start: u32
dbg_end: u32
function_type: TypeIndex
code_offset: u32
segment: u16
flags: ProcSymFlags
name: [1]u8

std.pdb.ProcSymFlags

容器

第 333 行

字段

has_fp: bool
has_iret: bool
has_fret: bool
is_no_return: bool
is_unreachable: bool
has_custom_calling_conv: bool
is_no_inline: bool
has_optimized_debug_info: bool

std.pdb.RecordPrefix

容器

第 350 行

字段

record_len: u16

记录长度,从 &record_kind 开始。

record_kind: SymbolKind

记录种类枚举(SymRecordKind 或 TypeRecordKind)

std.pdb.SectionContribEntry

容器

第 44 行

字段

section: u16

COFF 节索引,从 1 开始

padding1: [2]u8
offset: u32
size: u32
characteristics: u32
module_index: u16
padding2: [2]u8
data_crc: u32
reloc_crc: u32

std.pdb.SectionContrSubstreamVersion

容器

第 344 行

字段

Ver60 = 0xeffe0000 + 19970605
V2 = 0xeffe0000 + 20140516
_

std.pdb.SectionMapEntry

容器

第 83 行

字段

flags: u16

参见下方的 SectionMapEntryFlags 枚举。

ovl: u16

逻辑覆盖编号

group: u16

描述符数组中的组索引。

frame: u16
section_name: u16

段/组名称在字符串表中的字节索引,或 0xFFFF。

class_name: u16

class 在字符串表中的字节索引,或 0xFFFF。

offset: u32

逻辑段在物理段内的字节偏移。若 flags 中设置了 group,则为组的偏移。

section_length: u32

段或组的字节数。

std.pdb.SectionMapHeader

容器

第 75 行

字段

count: u16

段描述符的数量

log_count: u16

逻辑段描述符数量

std.pdb.std

别名

第 10 行

别名目标 std

std.pdb.StreamType

容器

第 107 行

字段

pdb = 1
tpi = 2
dbi = 3
ipi = 4

std.pdb.StringTableHeader

容器

第 454 行

字段

signature: u32

PDBStringTableSignature

hash_version: u32

1 或 2

byte_size: u32

名称缓冲区中的字节数。

std.pdb.SuperBlock

容器

第 464 行

字段

file_magic: [expect_magic.len]u8
block_size: u32

内部文件系统的块大小。有效值为 512、1024、 2048 和 4096 字节。MSF 文件布局的某些方面会随 块大小变化。就 LLVM 而言,只处理 4KiB 块;后续说明均假定块大小为 4KiB。

free_block_map_block: u32

文件内某个块的索引,该块开始处是一个位域, 表示文件内所有“空闲”块的集合,即块内数据 未被使用。更多信息参见空闲块映射。注意: FreeBlockMapBlock 只能为 1 或 2!

num_blocks: u32

文件中的块总数。NumBlocks * BlockSize 应等于 磁盘上的文件大小。

num_directory_bytes: u32

流目录的大小,以字节为单位。流目录包含 每个流的大小及其占用的块集合等信息。 后文将进一步详细说明。

unknown: u32
block_map_addr: u32

MSF 文件中某块的索引。该块保存一个 ulittle32_t 数组,列出流目录所在的块。 对于大型 MSF 文件,描述各流块布局的 流目录可能无法完整放入一个块。 因此引入这一额外间接层:此块 保存流目录占用的块列表, 据此可将流目录本身拼接起来。 数组中的 ulittle32_t 数量为 ceil(NumDirectoryBytes / BlockSize)。

std.pdb.SuperBlock.expect_magic

常量

第 466 行

LLVM 文档中 C / C++ 之间有空格,但实际观察并非如此。

std.pdb.SymbolKind

容器

第 116 行

SymbolRecordKind 的另一份定义,但采用官方 CV 名称。可用于 参考,以及处理未知记录类型。

字段

compile = 1
register_16t = 2
constant_16t = 3
udt_16t = 4
ssearch = 5
skip = 7
cvreserve = 8
objname_st = 9
endarg = 10
coboludt_16t = 11
manyreg_16t = 12
@"return" = 13
entrythis = 14
bprel16 = 256
ldata16 = 257
gdata16 = 258
pub16 = 259
lproc16 = 260
gproc16 = 261
thunk16 = 262
block16 = 263
with16 = 264
label16 = 265
cexmodel16 = 266
vftable16 = 267
regrel16 = 268
bprel32_16t = 512
ldata32_16t = 513
gdata32_16t = 514
pub32_16t = 515
lproc32_16t = 516
gproc32_16t = 517
thunk32_st = 518
block32_st = 519
with32_st = 520
label32_st = 521
cexmodel32 = 522
vftable32_16t = 523
regrel32_16t = 524
lthread32_16t = 525
gthread32_16t = 526
slink32 = 527
lprocmips_16t = 768
gprocmips_16t = 769
procref_st = 1024
dataref_st = 1025
@"align" = 1026
lprocref_st = 1027
oem = 1028
ti16_max = 4096
register_st = 4097
constant_st = 4098
udt_st = 4099
coboludt_st = 4100
manyreg_st = 4101
bprel32_st = 4102
ldata32_st = 4103
gdata32_st = 4104
pub32_st = 4105
lproc32_st = 4106
gproc32_st = 4107
vftable32 = 4108
regrel32_st = 4109
lthread32_st = 4110
gthread32_st = 4111
lprocmips_st = 4112
gprocmips_st = 4113
compile2_st = 4115
manyreg2_st = 4116
lprocia64_st = 4117
gprocia64_st = 4118
localslot_st = 4119
paramslot_st = 4120
annotation = 4121
gmanproc_st = 4122
lmanproc_st = 4123
reserved1 = 4124
reserved2 = 4125
reserved3 = 4126
reserved4 = 4127
lmandata_st = 4128
gmandata_st = 4129
manframerel_st = 4130
manregister_st = 4131
manslot_st = 4132
manmanyreg_st = 4133
manregrel_st = 4134
manmanyreg2_st = 4135
mantypref = 4136
unamespace_st = 4137
st_max = 4352
with32 = 4356
manyreg = 4362
lprocmips = 4372
gprocmips = 4373
manyreg2 = 4375
lprocia64 = 4376
gprocia64 = 4377
localslot = 4378
paramslot = 4379
manframerel = 4382
manregister = 4383
manslot = 4384
manmanyreg = 4385
manregrel = 4386
manmanyreg2 = 4387
unamespace = 4388
dataref = 4390
annotationref = 4392
tokenref = 4393
gmanproc = 4394
lmanproc = 4395
attr_framerel = 4398
attr_register = 4399
attr_regrel = 4400
attr_manyreg = 4401
sepcode = 4402
local_2005 = 4403
defrange_2005 = 4404
defrange2_2005 = 4405
discarded = 4411
lprocmips_id = 4424
gprocmips_id = 4425
lprocia64_id = 4426
gprocia64_id = 4427
defrange_hlsl = 4432
gdata_hlsl = 4433
ldata_hlsl = 4434
local_dpc_groupshared = 4436
defrange_dpc_ptr_tag = 4439
dpc_sym_tag_map = 4440
armswitchtable = 4441
pogodata = 4444
inlinesite2 = 4445
mod_typeref = 4447
ref_minipdb = 4448
pdbmap = 4449
gdata_hlsl32 = 4450
ldata_hlsl32 = 4451
gdata_hlsl32_ex = 4452
ldata_hlsl32_ex = 4453
fastlink = 4455
inlinees = 4456
end = 6
inlinesite_end = 4430
proc_id_end = 4431
thunk32 = 4354
trampoline = 4396
section = 4406
coffgroup = 4407
@"export" = 4408
lproc32 = 4367
gproc32 = 4368
lproc32_id = 4422
gproc32_id = 4423
lproc32_dpc = 4437
lproc32_dpc_id = 4438
register = 4358
pub32 = 4366
procref = 4389
lprocref = 4391
envblock = 4413
inlinesite = 4429
local = 4414
defrange = 4415
defrange_subfield = 4416
defrange_register = 4417
defrange_framepointer_rel = 4418
defrange_subfield_register = 4419
defrange_framepointer_rel_full_scope = 4420
defrange_register_rel = 4421
block32 = 4355
label32 = 4357
objname = 4353
compile2 = 4374
compile3 = 4412
frameproc = 4114
callsiteinfo = 4409
filestatic = 4435
heapallocsite = 4446
framecookie = 4410
callees = 4442
callers = 4443
udt = 4360
coboludt = 4361
buildinfo = 4428
bprel32 = 4363
regrel32 = 4369
constant = 4359
manconstant = 4397
ldata32 = 4364
gdata32 = 4365
lmandata = 4380
gmandata = 4381
lthread32 = 4370
gthread32 = 4371

std.pdb.TypeIndex

类型

第 315 行

源码

std/pdb.zig

//! 程序数据库调试信息格式。
//!
//! 此命名空间仅包含不附带特定策略的类型和数据定义。
//! 有关解析和缓存 PDB 信息的实现,请参见
//! `std.debug.Pdb`。
//!
//! 此处大部分内容基于从 LLVM 源码、
//! 文档或贡献者处收集的信息。

const std = @import("std.zig");
const math = std.math;
const mem = std.mem;
const coff = std.coff;
const fs = std.fs;
const File = std.Io.File;
const debug = std.debug;

const ArrayList = std.ArrayList;

/// https://llvm.org/docs/PDB/DbiStream.html#stream-header
pub const DbiStreamHeader = extern struct {
    version_signature: i32,
    version_header: u32,
    age: u32,
    global_stream_index: u16,
    build_number: u16,
    public_stream_index: u16,
    pdb_dll_version: u16,
    sym_record_stream: u16,
    pdb_dll_rbld: u16,
    mod_info_size: u32,
    section_contribution_size: u32,
    section_map_size: u32,
    source_info_size: i32,
    type_server_size: i32,
    mfc_type_server_index: u32,
    optional_dbg_header_size: i32,
    ec_substream_size: i32,
    flags: u16,
    machine: u16,
    padding: u32,
};

pub const SectionContribEntry = extern struct {
    /// COFF 节索引,从 1 开始
    section: u16,
    padding1: [2]u8,
    offset: u32,
    size: u32,
    characteristics: u32,
    module_index: u16,
    padding2: [2]u8,
    data_crc: u32,
    reloc_crc: u32,
};

pub const ModInfo = extern struct {
    unused1: u32,
    section_contr: SectionContribEntry,
    flags: u16,
    module_sym_stream: u16,
    sym_byte_size: u32,
    c11_byte_size: u32,
    c13_byte_size: u32,
    source_file_count: u16,
    padding: [2]u8,
    unused2: u32,
    source_file_name_index: u32,
    pdb_file_path_name_index: u32,
    // 这些字段的长度可变:
    // module_name: char[],
    // obj_file_name: char[],
};

pub const SectionMapHeader = extern struct {
    /// 段描述符的数量
    count: u16,

    /// 逻辑段描述符数量
    log_count: u16,
};

pub const SectionMapEntry = extern struct {
    /// 参见下方的 SectionMapEntryFlags 枚举。
    flags: u16,

    /// 逻辑覆盖编号
    ovl: u16,

    /// 描述符数组中的组索引。
    group: u16,
    frame: u16,

    /// 段/组名称在字符串表中的字节索引,或 0xFFFF。
    section_name: u16,

    /// class 在字符串表中的字节索引,或 0xFFFF。
    class_name: u16,

    /// 逻辑段在物理段内的字节偏移。若 flags 中设置了 group,则为组的偏移。
    offset: u32,

    /// 段或组的字节数。
    section_length: u32,
};

pub const StreamType = enum(u16) {
    pdb = 1,
    tpi = 2,
    dbi = 3,
    ipi = 4,
};

/// SymbolRecordKind 的另一份定义,但采用官方 CV 名称。可用于
/// 参考,以及处理未知记录类型。
pub const SymbolKind = enum(u16) {
    compile = 1,
    register_16t = 2,
    constant_16t = 3,
    udt_16t = 4,
    ssearch = 5,
    skip = 7,
    cvreserve = 8,
    objname_st = 9,
    endarg = 10,
    coboludt_16t = 11,
    manyreg_16t = 12,
    @"return" = 13,
    entrythis = 14,
    bprel16 = 256,
    ldata16 = 257,
    gdata16 = 258,
    pub16 = 259,
    lproc16 = 260,
    gproc16 = 261,
    thunk16 = 262,
    block16 = 263,
    with16 = 264,
    label16 = 265,
    cexmodel16 = 266,
    vftable16 = 267,
    regrel16 = 268,
    bprel32_16t = 512,
    ldata32_16t = 513,
    gdata32_16t = 514,
    pub32_16t = 515,
    lproc32_16t = 516,
    gproc32_16t = 517,
    thunk32_st = 518,
    block32_st = 519,
    with32_st = 520,
    label32_st = 521,
    cexmodel32 = 522,
    vftable32_16t = 523,
    regrel32_16t = 524,
    lthread32_16t = 525,
    gthread32_16t = 526,
    slink32 = 527,
    lprocmips_16t = 768,
    gprocmips_16t = 769,
    procref_st = 1024,
    dataref_st = 1025,
    @"align" = 1026,
    lprocref_st = 1027,
    oem = 1028,
    ti16_max = 4096,
    register_st = 4097,
    constant_st = 4098,
    udt_st = 4099,
    coboludt_st = 4100,
    manyreg_st = 4101,
    bprel32_st = 4102,
    ldata32_st = 4103,
    gdata32_st = 4104,
    pub32_st = 4105,
    lproc32_st = 4106,
    gproc32_st = 4107,
    vftable32 = 4108,
    regrel32_st = 4109,
    lthread32_st = 4110,
    gthread32_st = 4111,
    lprocmips_st = 4112,
    gprocmips_st = 4113,
    compile2_st = 4115,
    manyreg2_st = 4116,
    lprocia64_st = 4117,
    gprocia64_st = 4118,
    localslot_st = 4119,
    paramslot_st = 4120,
    annotation = 4121,
    gmanproc_st = 4122,
    lmanproc_st = 4123,
    reserved1 = 4124,
    reserved2 = 4125,
    reserved3 = 4126,
    reserved4 = 4127,
    lmandata_st = 4128,
    gmandata_st = 4129,
    manframerel_st = 4130,
    manregister_st = 4131,
    manslot_st = 4132,
    manmanyreg_st = 4133,
    manregrel_st = 4134,
    manmanyreg2_st = 4135,
    mantypref = 4136,
    unamespace_st = 4137,
    st_max = 4352,
    with32 = 4356,
    manyreg = 4362,
    lprocmips = 4372,
    gprocmips = 4373,
    manyreg2 = 4375,
    lprocia64 = 4376,
    gprocia64 = 4377,
    localslot = 4378,
    paramslot = 4379,
    manframerel = 4382,
    manregister = 4383,
    manslot = 4384,
    manmanyreg = 4385,
    manregrel = 4386,
    manmanyreg2 = 4387,
    unamespace = 4388,
    dataref = 4390,
    annotationref = 4392,
    tokenref = 4393,
    gmanproc = 4394,
    lmanproc = 4395,
    attr_framerel = 4398,
    attr_register = 4399,
    attr_regrel = 4400,
    attr_manyreg = 4401,
    sepcode = 4402,
    local_2005 = 4403,
    defrange_2005 = 4404,
    defrange2_2005 = 4405,
    discarded = 4411,
    lprocmips_id = 4424,
    gprocmips_id = 4425,
    lprocia64_id = 4426,
    gprocia64_id = 4427,
    defrange_hlsl = 4432,
    gdata_hlsl = 4433,
    ldata_hlsl = 4434,
    local_dpc_groupshared = 4436,
    defrange_dpc_ptr_tag = 4439,
    dpc_sym_tag_map = 4440,
    armswitchtable = 4441,
    pogodata = 4444,
    inlinesite2 = 4445,
    mod_typeref = 4447,
    ref_minipdb = 4448,
    pdbmap = 4449,
    gdata_hlsl32 = 4450,
    ldata_hlsl32 = 4451,
    gdata_hlsl32_ex = 4452,
    ldata_hlsl32_ex = 4453,
    fastlink = 4455,
    inlinees = 4456,
    end = 6,
    inlinesite_end = 4430,
    proc_id_end = 4431,
    thunk32 = 4354,
    trampoline = 4396,
    section = 4406,
    coffgroup = 4407,
    @"export" = 4408,
    lproc32 = 4367,
    gproc32 = 4368,
    lproc32_id = 4422,
    gproc32_id = 4423,
    lproc32_dpc = 4437,
    lproc32_dpc_id = 4438,
    register = 4358,
    pub32 = 4366,
    procref = 4389,
    lprocref = 4391,
    envblock = 4413,
    inlinesite = 4429,
    local = 4414,
    defrange = 4415,
    defrange_subfield = 4416,
    defrange_register = 4417,
    defrange_framepointer_rel = 4418,
    defrange_subfield_register = 4419,
    defrange_framepointer_rel_full_scope = 4420,
    defrange_register_rel = 4421,
    block32 = 4355,
    label32 = 4357,
    objname = 4353,
    compile2 = 4374,
    compile3 = 4412,
    frameproc = 4114,
    callsiteinfo = 4409,
    filestatic = 4435,
    heapallocsite = 4446,
    framecookie = 4410,
    callees = 4442,
    callers = 4443,
    udt = 4360,
    coboludt = 4361,
    buildinfo = 4428,
    bprel32 = 4363,
    regrel32 = 4369,
    constant = 4359,
    manconstant = 4397,
    ldata32 = 4364,
    gdata32 = 4365,
    lmandata = 4380,
    gmandata = 4381,
    lthread32 = 4370,
    gthread32 = 4371,
};

pub const TypeIndex = u32;

pub const ProcSym = extern struct {
    record_len: u16,
    record_kind: SymbolKind,
    parent: u32,
    end: u32,
    next: u32,
    code_size: u32,
    dbg_start: u32,
    dbg_end: u32,
    function_type: TypeIndex,
    code_offset: u32,
    segment: u16,
    flags: ProcSymFlags,
    name: [1]u8, // 以空字符终止
};

pub const ProcSymFlags = packed struct(u8) {
    has_fp: bool,
    has_iret: bool,
    has_fret: bool,
    is_no_return: bool,
    is_unreachable: bool,
    has_custom_calling_conv: bool,
    is_no_inline: bool,
    has_optimized_debug_info: bool,
};

pub const SectionContrSubstreamVersion = enum(u32) {
    Ver60 = 0xeffe0000 + 19970605,
    V2 = 0xeffe0000 + 20140516,
    _,
};

pub const RecordPrefix = extern struct {
    /// 记录长度,从 &record_kind 开始。
    record_len: u16,

    /// 记录种类枚举(SymRecordKind 或 TypeRecordKind)
    record_kind: SymbolKind,
};

/// 以下变长数组紧随头部之后出现。
/// 结构定义如下。
/// LineBlockFragmentHeader Blocks[]
/// 各 `LineBlockFragmentHeader` 的定义见下文。
pub const LineFragmentHeader = extern struct {
    /// 行贡献的代码偏移量。
    reloc_offset: u32,

    /// 行信息贡献项的代码段。
    reloc_segment: u16,
    flags: LineFlags,

    /// 此行信息贡献项的代码大小。
    code_size: u32,
};

pub const LineFlags = packed struct(u16) {
    /// CV_LINES_HAVE_COLUMNS
    have_columns: bool,
    unused: u15,
};

/// 以下两个变长数组紧随头部之后出现。
/// 结构定义如下。
/// LineNumberEntry   Lines[NumLines];
/// ColumnNumberEntry Columns[NumLines];
pub const LineBlockFragmentHeader = extern struct {
    /// FileChecksum 条目在文件校验和缓冲区中的偏移。
    /// 该校验和条目又包含另一个偏移,
    /// 指向字符串表中的
    /// 实际文件名。
    name_index: u32,
    num_lines: u32,

    /// 块的代码大小,单位为字节
    block_size: u32,
};

pub const LineNumberEntry = extern struct {
    /// 该行号对应代码字节起始位置的偏移量
    offset: u32,
    flags: Flags,

    pub const Flags = packed struct(u32) {
        /// 起始行号
        start: u24,
        /// 到表达式末尾的行数差。含义仍不明确。
        // TODO 弄清此字段的用途。
        end: u7,
        is_statement: bool,
    };
};

pub const ColumnNumberEntry = extern struct {
    start_column: u16,
    end_column: u16,
};

/// 校验和字节紧随其后。
pub const FileChecksumEntryHeader = extern struct {
    /// 全局字符串表中文件名的字节偏移量。
    file_name_offset: u32,
    /// 校验和的字节数。
    checksum_size: u8,
    /// FileChecksumKind
    checksum_kind: u8,
};

pub const DebugSubsectionKind = enum(u32) {
    none = 0,
    symbols = 0xf1,
    lines = 0xf2,
    string_table = 0xf3,
    file_checksums = 0xf4,
    frame_data = 0xf5,
    inlinee_lines = 0xf6,
    cross_scope_imports = 0xf7,
    cross_scope_exports = 0xf8,

    // 这些似乎与 .Net 程序集信息有关。
    il_lines = 0xf9,
    func_md_token_map = 0xfa,
    type_md_token_map = 0xfb,
    merged_assembly_input = 0xfc,

    coff_symbol_rva = 0xfd,
};

pub const DebugSubsectionHeader = extern struct {
    /// codeview::DebugSubsectionKind 枚举
    kind: DebugSubsectionKind,

    /// 此记录占用的字节数。
    length: u32,
};

pub const StringTableHeader = extern struct {
    /// PDBStringTableSignature
    signature: u32,
    /// 1 或 2
    hash_version: u32,
    /// 名称缓冲区中的字节数。
    byte_size: u32,
};

// https://llvm.org/docs/PDB/MsfFile.html#the-superblock
pub const SuperBlock = extern struct {
    /// LLVM 文档中 C / C++ 之间有空格,但实际观察并非如此。
    pub const expect_magic = "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00";

    file_magic: [expect_magic.len]u8,

    /// 内部文件系统的块大小。有效值为 512、1024、
    /// 2048 和 4096 字节。MSF 文件布局的某些方面会随
    /// 块大小变化。就 LLVM 而言,只处理
    /// 4KiB 块;后续说明均假定块大小为 4KiB。
    block_size: u32,

    /// 文件内某个块的索引,该块开始处是一个位域,
    /// 表示文件内所有“空闲”块的集合,即块内数据
    /// 未被使用。更多信息参见空闲块映射。注意:
    /// FreeBlockMapBlock 只能为 1 或 2!
    free_block_map_block: u32,

    /// 文件中的块总数。NumBlocks * BlockSize 应等于
    /// 磁盘上的文件大小。
    num_blocks: u32,

    /// 流目录的大小,以字节为单位。流目录包含
    /// 每个流的大小及其占用的块集合等信息。
    /// 后文将进一步详细说明。
    num_directory_bytes: u32,

    unknown: u32,
    /// MSF 文件中某块的索引。该块保存一个
    /// ulittle32_t 数组,列出流目录所在的块。
    /// 对于大型 MSF 文件,描述各流块布局的
    /// 流目录可能无法完整放入一个块。
    /// 因此引入这一额外间接层:此块
    /// 保存流目录占用的块列表,
    /// 据此可将流目录本身拼接起来。
    /// 数组中的 ulittle32_t 数量为
    /// ceil(NumDirectoryBytes / BlockSize)。
    // 注意:microsoft-pdb 代码实际上暗示这是变长数组。若流目录所占用块的索引无法放入一页,后面应当还有其他 u32。
    // 这意味着流目录大于 BlockSize / sizeof(u32) 个块。即使 1GB 的 PDB 文件也远未达到此规模,且 LLVM 也没有实现此情况,因此目前采用这一假设尚属安全。
    //
    //
    //
    //
    block_map_addr: u32,
};

pub const IpiStreamVersion = enum(u32) {
    v40 = 19950410,
    v41 = 19951122,
    v50 = 19961031,
    v70 = 19990903,
    v80 = 20040203,
    _,
};

pub const IpiStreamHeader = extern struct {
    version: IpiStreamVersion,
    header_size: u32,
    type_index_begin: u32,
    type_index_end: u32,
    type_record_bytes: u32,
    hash_stream_index: u16,
    hash_aux_stream_index: u16,
    hash_key_size: u32,
    num_hash_buckets: u32,
    hash_value_buffer_offset: i32,
    hash_value_buffer_length: u32,
    index_offset_buffer_offset: i32,
    index_offset_buffer_length: u32,
    hash_adj_buffer_offset: i32,
    hash_adj_buffer_length: u32,
};

pub const LfRecordPrefix = extern struct {
    len: u16,
    kind: LfRecordKind,
};

pub const LfRecordKind = enum(u16) {
    pointer = 0x1002,
    modifier = 0x1001,
    procedure = 0x1008,
    mfunction = 0x1009,
    label = 0x000e,
    arglist = 0x1201,
    fieldlist = 0x1203,
    array = 0x1503,
    class = 0x1504,
    structure = 0x1505,
    interface = 0x1519,
    @"union" = 0x1506,
    @"enum" = 0x1507,
    typeserver2 = 0x1515,
    vftable = 0x151d,
    vtshape = 0x000a,
    bitfield = 0x1205,
    func_id = 0x1601,
    mfunc_id = 0x1602,
    buildinfo = 0x1603,
    substr_list = 0x1604,
    string_id = 0x1605,
    udt_src_line = 0x1606,
    udt_mod_src_line = 0x1607,
    methodlist = 0x1206,
    precomp = 0x1509,
    endprecomp = 0x0014,
    bclass = 0x1400,
    binterface = 0x151a,
    vbclass = 0x1401,
    ivbclass = 0x1402,
    vfunctab = 0x1409,
    stmember = 0x150e,
    method = 0x150f,
    member = 0x150d,
    nesttype = 0x1510,
    onemethod = 0x1511,
    enumerate = 0x1502,
    index = 0x1404,
    pad0 = 0xf0,
    _,
};

pub const LfFuncId = extern struct {
    len: u16,
    kind: LfRecordKind,
    scope_id: u32,
    type: u32,
    name: [1]u8, // 以空字符终止
};

pub const LfMFuncId = extern struct {
    len: u16,
    kind: LfRecordKind,
    parent_type: u32,
    type: u32,
    name: [1]u8, // 以空字符终止
};

pub const InlineSiteSym = extern struct {
    record_len: u16,
    record_kind: SymbolKind,
    parent: u32,
    end: u32,
    inlinee: u32,
};

pub const InlineSiteSym2 = extern struct {
    record_len: u16,
    record_kind: SymbolKind,
    parent: u32,
    end: u32,
    inlinee: u32,
    invocations: u32,
};

pub const InlineeSourceLineSignature = enum(u32) { normal = 0, ex = 1, _ };

pub const InlineeSourceLine = extern struct {
    inlinee: u32,
    file_id: u32,
    source_line_num: u32,
};

pub const InlineeSourceLineEx = extern struct {
    inlinee: u32,
    file_id: u32,
    source_line_num: u32,
    count_of_extra_files: u32,
};

pub const BinaryAnnotationOpcode = enum(u8) {
    invalid = 0,
    code_offset = 1,
    change_code_offset_base = 2,
    change_code_offset = 3,
    change_code_length = 4,
    change_file = 5,
    change_line_offset = 6,
    change_line_end_delta = 7,
    change_range_kind = 8,
    change_column_start = 9,
    change_column_end_delta = 10,
    change_code_offset_and_line_offset = 11,
    change_code_length_and_code_offset = 12,
    change_column_end = 13,
};