A bounded, pure MoonBit reader for Microsoft PDB 7.0 debug information.
let msf = @moonpdb.parse_msf(file_bytes, @moonpdb.MsfLimits::default())
let info = msf.pdb_info(@moonpdb.PdbInfoLimits::default())
let names_stream = info.named_stream_index("/names")
let tpi = msf.tpi(@moonpdb.TpiLimits::default())
let ipi = msf.ipi(@moonpdb.TpiLimits::default())
let int32_type = @moonpdb.simple_type(0x74)
let dbi = msf.dbi(@moonpdb.DbiLimits::default())
let modules = dbi.modules()
let module_debug = msf.module_debug_stream(
dbi, 0, @moonpdb.SymbolLimits::default(),
)
let symbols = module_debug.symbols()
let publics = msf.publics_stream(
dbi, @moonpdb.SymbolLimits::default(),
)
let nearest_public = publics.find_public_nearest(1, 0x1000)
let globals = msf.globals_stream(
dbi, @moonpdb.SymbolLimits::default(),
)
let matches = globals.find_records_by_name("main")
let lines = msf.module_c13_info(
dbi, 0, @moonpdb.SymbolLimits::default(), @moonpdb.C13Limits::default(),
)
let source = lines.find_line(1, 0x1000)
let pe = @moonpdb.parse_pe_image(pe_bytes, @moonpdb.PeLimits::default())
let report = @moonpdb.symbolicate_address(
pe, publics, [lines], 1, 0x1000,
)moon run cmd/main -- summary test-data/llvm/global-name-lookup.pdb
moon run cmd/main -- modules test-data/llvm/global-name-lookup.pdb
moon run cmd/main -- types test-data/llvm/global-name-lookup.pdb 20
moon run cmd/main -- symbols test-data/llvm/global-name-lookup.pdb 20
moon run cmd/main -- publics test-data/llvm/global-name-lookup.pdb 20
moon run cmd/main -- find test-data/llvm/global-name-lookup.pdb main
moon run cmd/main -- address app.exe app.pdb 1 0x1000pub suberror DbiError {
TruncatedDbi(Int)
InvalidDbiHeader(String)
UnsupportedDbiVersion(UInt)
UnsupportedSectionContributionVersion(UInt)
InvalidDbiModule(String)
InvalidSectionContribution(String)
InvalidSectionMap(String)
InvalidFileInfo(String)
DbiStreamUnavailable
DbiLimitExceeded(String)
}pub suberror MsfError {
TooSmall(Int)
BadMagic
UnsupportedBlockSize(Int)
InvalidBlockCount(Int)
InvalidFreeBlockMap(Int)
InvalidBlockIndex(Int)
Truncated(Int)
InvalidDirectory(String)
InvalidStream(Int)
LimitExceeded(String)
InvalidValue(String)
}pub suberror PdbInfoError {
TruncatedInfo(Int)
InvalidInfoValue(String)
InvalidNamedStream(String)
InfoStreamUnavailable
LimitExceededInfo(String)
}pub suberror PeError {
TooSmallPe(Int)
BadDosMagic
BadPeSignature
TruncatedPe(Int)
UnsupportedPeOptionalHeader(UInt16)
InvalidPeSection(String)
PeLimitExceeded(String)
}pub suberror SymbolError {
TruncatedSymbol(Int)
InvalidSymbolRecord(String)
InvalidModuleStream(String)
UnsupportedModuleSignature(UInt)
SymbolStreamUnavailable(UInt16)
ModuleStreamUnavailable(UInt16)
SymbolLimitExceeded(String)
TruncatedPublics(Int)
InvalidPublicsHeader(String)
UnsupportedGsiVersion(UInt)
InvalidGsi(String)
PublicsStreamUnavailable(UInt16)
InvalidPublicSymbol(String)
PublicsLimitExceeded(String)
GlobalsStreamUnavailable(UInt16)
InvalidGlobalIndex(String)
TruncatedC13(Int)
InvalidC13Subsection(String)
InvalidFileChecksum(String)
InvalidLineInfo(String)
MissingC13StringTable
C13LimitExceeded(String)
InvalidPdbStringTable(String)
PdbStringTableUnavailable
}pub suberror TpiError {
TruncatedTpi(Int)
InvalidTpiHeader(String)
InvalidTypeRecord(String)
TypeStreamUnavailable(Int)
TpiLimitExceeded(String)
}pub struct AggregateType {
leaf_kind : UInt16
member_count : UInt16
properties : UInt16
field_list : UInt
derived_from : UInt
vtable_shape : UInt
size : NumericValue
name : String
unique_name : String?
}pub struct AliasType {
underlying_type : UInt
name : String
}pub struct BPRelativeSymbol {
offset : Int
type_index : UInt
name : String
}pub struct BitFieldType {
underlying_type : UInt
bit_size : Int
bit_offset : Int
}pub struct BlockSymbol {
parent : UInt
end : UInt
code_size : UInt
code_offset : UInt
segment : UInt16
name : String
}pub struct C13DebugInfo {
subsections : Array[C13Subsection]
string_table : DebugStringTable?
checksums : Array[FileChecksum]
line_fragments : Array[LineFragment]
}pub struct C13Limits {
max_bytes : Int
max_subsections : Int
max_file_checksums : Int
max_line_fragments : Int
max_line_entries : Int
}pub struct C13Subsection {
kind : UInt
payload : Bytes
}pub struct DataField {
attributes : FieldAttributes
type_index : UInt
offset : NumericValue
name : String
}pub struct DataSymbol {
type_index : UInt
offset : UInt
segment : UInt16
name : String
}pub struct DbiFile {
data : Bytes
header : DbiHeader
modules : Array[DbiModule]
section_contributions : Array[SectionContribution]
section_contribution_version : SectionContributionVersion
section_map : SectionMap
reported_source_file_count : UInt16
type_server_map : Bytes
ec_substream : Bytes
optional_debug_streams : Array[UInt16]
}pub struct DbiHeader {
version_signature : UInt
version : UInt
age : UInt
global_symbol_stream_index : UInt16
build_number : UInt16
public_symbol_stream_index : UInt16
pdb_dll_version : UInt16
symbol_record_stream_index : UInt16
pdb_dll_rebuild : UInt16
modi_substream_bytes : Int
section_contributions_bytes : Int
section_map_bytes : Int
file_info_bytes : Int
type_server_map_bytes : Int
mfc_type_server_index : UInt
optional_debug_header_bytes : Int
ec_substream_bytes : Int
flags : UInt16
machine_type : UInt16
reserved : UInt
}pub struct DbiLimits {
max_stream_bytes : Int
max_modules : Int
max_section_contributions : Int
max_section_map_entries : Int
max_source_files : Int
max_string_bytes : Int
max_debug_streams : Int
}pub struct DbiModule {
record_index : Int
module_name : String
object_name : String
section_contribution : SectionContribution
flags : UInt16
module_stream_index : UInt16
symbol_debug_bytes : UInt
c11_line_bytes : UInt
c13_line_bytes : UInt
declared_source_file_count : UInt16
source_file_name_index : UInt
pdb_file_path_index : UInt
source_files : Array[String]
}pub enum DebugStreamKind {
Fpo
Exception
Fixup
OmapToSrc
OmapFromSrc
SectionHdr
TokenRidMap
Xdata
Pdata
NewFpo
SectionHdrOrig
}pub struct DebugStringTable {
bytes : Bytes
}pub struct EnumType {
member_count : UInt16
properties : UInt16
underlying_type : UInt
field_list : UInt
name : String
unique_name : String?
}pub struct FieldAttributes {
raw : UInt16
}pub enum FieldListMember {
BaseClass(BaseClassField)
VirtualBaseClass(VirtualBaseClassField)
Data(DataField)
StaticData(StaticDataField)
Enumerated(EnumeratedField)
OverloadedMethod(OverloadedMethodField)
NestedType(NestedTypeField)
OneMethod(OneMethodField)
VFunctionTable(VFunctionTableField)
FriendClass(FriendClassField)
UnknownTail(UnknownFieldTail)
}pub struct FileChecksum {
subsection_offset : UInt
file_name_offset : UInt
kind : Int
checksum : Bytes
file_path : String
}pub struct FrameProcedureSymbol {
total_frame_bytes : UInt
padding_frame_bytes : UInt
offset_to_padding : UInt
callee_saved_bytes : UInt
exception_handler_offset : UInt
exception_handler_section : UInt16
flags : UInt
}pub struct FriendClassField {
type_index : UInt
}pub struct FunctionIdType {
parent_scope : UInt
function_type : UInt
name : String
}fn GlobalsStream::find_records_by_name(self : GlobalsStream, name : String) -> Array[SymbolRecord] raise SymbolErrorpub struct GsiHashHeader {
signature : UInt
version : UInt
hash_record_bytes : UInt
declared_bucket_count : UInt
}pub struct GsiHashRecord {
raw_offset : UInt
reference_count : UInt
}pub struct GsiTable {
header : GsiHashHeader
hash_records : Array[GsiHashRecord]
bitmap : Array[UInt]
buckets : Array[UInt]
bucket_map : Array[Int]
}pub struct LabelSymbol {
code_offset : UInt
segment : UInt16
flags : Int
name : String
}pub struct LabelType {
mode : UInt16
}pub struct LineBlock {
file_checksum_offset : UInt
file_path : String
record_size : UInt
lines : Array[LineNumber]
}pub struct LineColumnRange {
start : UInt16
end : UInt16
}pub struct LineNumber {
offset : UInt
line_start : UInt
line_end : UInt
is_statement : Bool
columns : LineColumnRange?
}pub struct MemberFunctionIdType {
class_type : UInt
function_type : UInt
name : String
}pub struct MemberFunctionType {
return_type : UInt
class_type : UInt
this_type : UInt
calling_convention : Int
function_options : Int
parameter_count : UInt16
argument_list : UInt
this_adjustment : Int
}pub struct ModifierType {
modified_type : UInt
modifiers : UInt16
}pub struct ModuleDebugStream {
signature : UInt
symbols : SymbolTable
c11_lines : Bytes
c13_lines : Bytes
global_refs : Array[UInt]
}fn ModuleDebugStream::c13_info(self : ModuleDebugStream, limits : C13Limits) -> C13DebugInfo raise SymbolErrorfn ModuleDebugStream::c13_info_with_fallback(self : ModuleDebugStream, fallback : DebugStringTable?, limits : C13Limits) -> C13DebugInfo raise SymbolErrorfn MsfFile::globals_stream(self : MsfFile, dbi : DbiFile, limits : SymbolLimits) -> GlobalsStream raise SymbolErrorfn MsfFile::module_c13_info(self : MsfFile, dbi : DbiFile, module_index : Int, symbol_limits : SymbolLimits, limits : C13Limits) -> C13DebugInfo raise SymbolErrorfn MsfFile::module_debug_stream(self : MsfFile, dbi : DbiFile, module_index : Int, limits : SymbolLimits) -> ModuleDebugStream raise SymbolErrorfn MsfFile::pdb_string_table(self : MsfFile, info : PdbInfo, name : String, limits : PdbStringTableLimits) -> PdbStringTable raise SymbolErrorfn MsfFile::publics_stream(self : MsfFile, dbi : DbiFile, limits : SymbolLimits) -> PublicsStream raise SymbolErrorfn MsfFile::symbol_record_stream(self : MsfFile, dbi : DbiFile, limits : SymbolLimits) -> SymbolTable raise SymbolErrorpub struct MsfHeader {
block_size : Int
free_block_map_block : Int
num_blocks : Int
num_directory_bytes : Int
block_map_addr : Int
}pub struct MsfLimits {
max_file_bytes : Int
max_directory_bytes : Int
max_streams : Int
max_stream_bytes : Int
}pub struct NamedStream {
name : String
stream_index : Int
}pub struct NestedTypeField {
type_index : UInt
name : String
}pub enum NumericValue {
Signed(Int64)
Unsigned(UInt64)
Opaque(UInt16, Bytes)
}pub struct ObjectNameSymbol {
signature : UInt
name : String
}pub struct OneMethodField {
attributes : FieldAttributes
type_index : UInt
vtable_offset : Int?
name : String
}pub struct OverloadedMethodField {
count : UInt16
method_list : UInt
name : String
}pub struct PdbInfo {
version : UInt
signature : UInt
age : UInt
guid : Bytes
named_streams : Array[NamedStream]
feature_codes : Array[UInt]
}pub struct PdbInfoLimits {
max_string_bytes : Int
max_named_streams : Int
max_hash_capacity : Int
max_features : Int
}pub struct PdbStringTable {
signature : UInt
hash_version : UInt
strings : DebugStringTable
name_ids : Array[UInt]
name_count : UInt
}pub struct PdbStringTableLimits {
max_bytes : Int
max_names : Int
}pub struct PeLimits {
max_file_bytes : Int
max_sections : Int
}pub struct PeSection {
name : String
virtual_size : UInt
virtual_address : UInt
raw_size : UInt
raw_pointer : UInt
characteristics : UInt
}pub struct PointerType {
referent_type : UInt
attributes : UInt
containing_type : UInt?
member_representation : UInt16?
}pub struct ProcedureReferenceSymbol {
name_hash : UInt
symbol_offset : UInt
module_index : UInt16
name : String
}pub struct ProcedureSymbol {
parent : UInt
end : UInt
next : UInt
code_size : UInt
debug_start : UInt
debug_end : UInt
function_type : UInt
code_offset : UInt
segment : UInt16
flags : Int
name : String
}pub struct ProcedureType {
return_type : UInt
calling_convention : Int
function_options : Int
parameter_count : UInt16
argument_list : UInt
}pub struct PublicSectionOffset {
offset : UInt
section : UInt16
}pub struct PublicSymbol {
flags : UInt
offset : UInt
segment : UInt16
name : String
}pub struct PublicsHeader {
symbol_hash : UInt
address_map_bytes : UInt
thunk_count : UInt
thunk_size : UInt
thunk_table_section : UInt16
thunk_table_offset : UInt
section_count : UInt
}pub struct PublicsStream {
header : PublicsHeader
gsi : GsiTable
address_map : Array[UInt]
thunk_map : Array[UInt]
section_offsets : Array[PublicSectionOffset]
public_symbols : Array[ResolvedPublicSymbol]
}fn PublicsStream::find_public_exact(self : PublicsStream, segment : UInt16, offset : UInt) -> ResolvedPublicSymbol?fn PublicsStream::find_public_nearest(self : PublicsStream, segment : UInt16, offset : UInt) -> ResolvedPublicSymbol?pub struct RegRelativeSymbol {
offset : UInt
type_index : UInt
register : UInt16
name : String
}pub struct ResolvedPublicSymbol {
symbol_offset : UInt
flags : UInt
segment : UInt16
offset : UInt
name : String
}pub struct RvaLocation {
segment : UInt16
section_offset : UInt
section_name : String
rva : UInt
image_address : UInt64
}pub struct SectionContribution {
version : SectionContributionVersion
section_index : UInt16
offset : Int
size : Int
characteristics : UInt
module_index : UInt16
data_crc : UInt
relocation_crc : UInt
coff_section_index : UInt?
}pub enum SectionContributionVersion {
None
V60
V2
}pub struct SectionMap {
physical_count : UInt16
logical_count : UInt16
entries : Array[SectionMapEntry]
}pub struct SectionMapEntry {
flags : UInt16
overlay : UInt16
group : UInt16
frame : UInt16
section_name_offset : UInt16
class_name_offset : UInt16
offset : UInt
byte_length : UInt
}pub struct SimpleType {
raw : UInt
base : Int
mode : SimpleTypeMode
kind : SimpleTypeKind
name : String
byte_size : Int
}pub enum SimpleTypeKind {
NoType
Void
SignedInteger
UnsignedInteger
Boolean
Real
Character
WideCharacter
Bit
Unknown
}pub enum SimpleTypeMode {
Direct
NearPointer
FarPointer
HugePointer
Pointer32
FarPointer32
Pointer64
Reserved
}pub struct SourceLocation {
segment : UInt16
code_offset : UInt
file_path : String
line_start : UInt
line_end : UInt
is_statement : Bool
columns : LineColumnRange?
}pub struct StringIdType {
id : UInt
value : String
}pub enum SymbolDetails {
Public(PublicSymbol)
Data(DataSymbol)
Procedure(ProcedureSymbol)
Thunk(ThunkSymbol)
Block(BlockSymbol)
Label(LabelSymbol)
Constant(ConstantSymbol)
Udt(UdtSymbol)
ObjectName(ObjectNameSymbol)
BPRelative(BPRelativeSymbol)
RegRelative(RegRelativeSymbol)
ProcedureReference(ProcedureReferenceSymbol)
FrameProcedure(FrameProcedureSymbol)
ScopeEnd
Unknown(UnknownSymbol)
}pub struct SymbolLimits {
max_stream_bytes : Int
max_records : Int
max_record_bytes : Int
max_global_refs : Int
max_hash_records : Int
max_public_symbols : Int
}pub struct SymbolizedAddress {
segment : UInt16
section_offset : UInt
section_name : String
rva : UInt
image_address : UInt64
public_symbol : ResolvedPublicSymbol?
source : SourceLocation?
}pub struct ThunkSymbol {
parent : UInt
end : UInt
next : UInt
offset : UInt
segment : UInt16
length : UInt16
ordinal : Int
name : String
variant_bytes : Bytes
}pub struct TpiHeader {
version : UInt
header_size : Int
type_index_begin : UInt
type_index_end : UInt
type_record_bytes : Int
hash_stream_index : Int
hash_aux_stream_index : Int
hash_key_size : UInt
hash_bucket_count : UInt
hash_value_offset : Int
hash_value_bytes : Int
index_offset_offset : Int
index_offset_bytes : Int
hash_adjust_offset : Int
hash_adjust_bytes : Int
}pub struct TpiLimits {
max_stream_bytes : Int
max_records : Int
max_record_bytes : Int
max_type_refs : Int
}pub enum TypeDetails {
Modifier(ModifierType)
Pointer(PointerType)
Procedure(ProcedureType)
MemberFunction(MemberFunctionType)
ArgList(ArgListType)
FieldList(FieldListType)
BitField(BitFieldType)
Array(ArrayType)
Aggregate(AggregateType)
Union(UnionType)
Enum(EnumType)
Alias(AliasType)
Label(LabelType)
FunctionId(FunctionIdType)
MemberFunctionId(MemberFunctionIdType)
StringId(StringIdType)
BuildInfo(BuildInfoType)
UdtSourceLine(UdtSourceLineType)
TypeServer2(TypeServer2Type)
Unknown(UnknownType)
}pub struct TypeServer2Type {
guid : Bytes
age : UInt
name : String
}fn TypeTable::field_list_members(self : TypeTable, type_index : UInt) -> Array[FieldListMember] raise TpiErrorpub struct UdtSourceLineType {
udt : UInt
source_file : UInt
line_number : UInt
module_index : UInt?
}pub struct UdtSymbol {
type_index : UInt
name : String
}pub struct UnionType {
member_count : UInt16
properties : UInt16
field_list : UInt
size : NumericValue
name : String
unique_name : String?
}pub struct UnknownFieldTail {
kind : UInt16
payload : Bytes
}pub struct UnknownSymbol {
kind : UInt16
payload : Bytes
}pub struct UnknownType {
kind : UInt16
payload : Bytes
}pub struct VFunctionTableField {
type_index : UInt
}pub struct VirtualBaseClassField {
virtual_inheritance : Bool
attributes : FieldAttributes
base_type : UInt
vbptr_type : UInt
vbptr_offset : NumericValue
vtable_index : NumericValue
}fn hash_string_v1(value : String) -> UIntfn parse_c13_debug_info_with_fallback(data : Bytes, fallback : DebugStringTable?, limits : C13Limits) -> C13DebugInfo raise SymbolErrorfn parse_globals_stream(data : Bytes, symbols : SymbolTable, limits : SymbolLimits) -> GlobalsStream raise SymbolErrorfn parse_module_debug_stream(data : Bytes, symbol_bytes_raw : UInt, c11_bytes_raw : UInt, c13_bytes_raw : UInt, limits : SymbolLimits) -> ModuleDebugStream raise SymbolErrorfn parse_pdb_info(data : Bytes, msf_stream_count : Int, limits : PdbInfoLimits) -> PdbInfo raise PdbInfoErrorfn parse_pdb_string_table(data : Bytes, limits : PdbStringTableLimits) -> PdbStringTable raise SymbolErrorfn parse_publics_stream(data : Bytes, symbols : SymbolTable, limits : SymbolLimits) -> PublicsStream raise SymbolErrorfn symbolicate_address(pe : PeImage, publics : PublicsStream, c13_modules : Array[C13DebugInfo], segment : UInt16, offset : UInt) -> SymbolizedAddress?fn symbolicate_addresses(pe : PeImage, publics : PublicsStream, c13_modules : Array[C13DebugInfo], addresses : Array[(UInt16, UInt)]) -> Array[SymbolizedAddress]Install
Download zipA bounded, pure MoonBit reader for Microsoft PDB 7.0 debug information.