Source
pub fn getModule(self: *Pdb, index: usize) !?*Module {
if (index >= self.modules.len)
return null;
const mod = &self.modules[index];
if (mod.populated)
return mod;
// At most one can be non-zero.
if (mod.mod_info.c11_byte_size != 0 and mod.mod_info.c13_byte_size != 0)
return error.InvalidDebugInfo;
if (mod.mod_info.c13_byte_size == 0)
return error.InvalidDebugInfo;
const stream = self.getStreamById(mod.mod_info.module_sym_stream) orelse
return error.MissingDebugInfo;
const reader = stream.reader();
const signature = try reader.readInt(u32, .little);
if (signature != 4)
return error.InvalidDebugInfo;
mod.symbols = try self.allocator.alloc(u8, mod.mod_info.sym_byte_size - 4);
errdefer self.allocator.free(mod.symbols);
try reader.readNoEof(mod.symbols);
mod.subsect_info = try self.allocator.alloc(u8, mod.mod_info.c13_byte_size);
errdefer self.allocator.free(mod.subsect_info);
try reader.readNoEof(mod.subsect_info);
var sect_offset: usize = 0;
var skip_len: usize = undefined;
while (sect_offset != mod.subsect_info.len) : (sect_offset += skip_len) {
const subsect_hdr: *align(1) pdb.DebugSubsectionHeader = @ptrCast(&mod.subsect_info[sect_offset]);
skip_len = subsect_hdr.length;
sect_offset += @sizeOf(pdb.DebugSubsectionHeader);
switch (subsect_hdr.kind) {
.file_checksums => {
mod.checksum_offset = sect_offset;
break;
},
else => {},
}
if (sect_offset > mod.subsect_info.len)
return error.InvalidDebugInfo;
}
mod.populated = true;
return mod;
}