Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › debug › MachOFile › loadDsymFile Private Function loadDsymFile Doc Source Private Function std.debug.MachOFile.loadDsymFile
fn loadDsymFile (
gpa : Allocator ,
io : Io ,
path : []const u8 ,
arch : std .Target .Cpu .Arch ,
expected_uuid : Uuid ,
) Error !DsymFile Params Errors InvalidMachO InvalidDwarf MissingDebugInfo UnsupportedDebugInfo ReadFailed OutOfMemory File debug/MachOFile.zig: 411
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452 fn loadDsymFile (
gpa : Allocator ,
io : Io ,
path : []const u8 ,
arch : std .Target .Cpu .Arch ,
expected_uuid : Uuid ,
) Error !DsymFile {
const all_mapped_memory = try mapDebugInfoFile (io , path );
errdefer posix .munmap (all_mapped_memory );
const mapped_macho = try selectMachOSlice (all_mapped_memory , arch );
var r : Io .Reader = .fixed (mapped_macho );
const hdr = r .takeStruct (macho .mach_header_64 , .little ) catch |err | switch (err ) {
error .ReadFailed => unreachable ,
error .EndOfStream => return error .InvalidMachO ,
};
if (hdr .magic != macho .MH_MAGIC_64 ) return error .InvalidMachO ;
if (hdr .filetype != macho .MH_DSYM ) return error .MissingDebugInfo ;
var uuid : ?Uuid = null ;
var dwarf_sections : ?[]align (1 ) const macho .section_64 = null ;
var it : macho .LoadCommandIterator = try .init (&hdr , mapped_macho [@sizeOf (macho .mach_header_64 )..]);
while (try it .next ()) |lc | switch (lc .hdr .cmd ) {
.SEGMENT_64 => if (lc .cast (macho .segment_command_64 )) |seg_cmd | {
if (!mem .eql (u8 , "__DWARF" , seg_cmd .segName ())) continue ;
dwarf_sections = lc .getSections ();
},
.UUID => if (lc .cast (macho .uuid_command )) |uuid_cmd | {
uuid = uuid_cmd .uuid ;
},
else => {},
};
const actual_uuid = uuid orelse return error .MissingDebugInfo ;
if (!mem .eql (u8 , &actual_uuid , &expected_uuid )) return error .MissingDebugInfo ;
return .{
.mapped_memory = all_mapped_memory ,
.dwarf = try loadDwarfFromSections (gpa , mapped_macho , dwarf_sections orelse return error .MissingDebugInfo ),
};
}