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 › loadDwarfFromSections Private Function loadDwarfFromSections Doc Source Private Function std.debug.MachOFile.loadDwarfFromSections
fn loadDwarfFromSections (
gpa : Allocator ,
mapped_macho : []const u8 ,
section_headers : []align (1 ) const macho .section_64 ,
) !Dwarf Params gpa : Allocator mapped_macho : []const u8 section_headers : []align (1 ) const macho .section_64 File debug/MachOFile.zig: 568
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619 fn loadDwarfFromSections (
gpa : Allocator ,
mapped_macho : []const u8 ,
section_headers : []align (1 ) const macho .section_64 ,
) !Dwarf {
var sections : Dwarf .SectionArray = @splat (null );
for (section_headers ) |sect_raw | {
var sect = sect_raw ;
if (builtin .cpu .arch .endian () != .little ) std .mem .byteSwapAllFields (macho .section_64 , § );
if (!std .mem .eql (u8 , "__DWARF" , sect .segName ())) continue ;
const section_index : usize = inline for (@typeInfo (Dwarf .Section .Id ).@"enum" .field_names , 0 ..) |field_name , i | {
const section_name_long = "__" ++ field_name ;
// Some dwarf section names don't fit in the `sectname` buffer, so they are truncated.
const section_name_trunc = section_name_long [0 ..@min (section_name_long .len , sect .sectname .len )];
if (mem .eql (u8 , section_name_trunc , sect .sectName ())) break i ;
} else continue ;
if (mapped_macho .len < sect .offset + sect .size ) return error .InvalidMachO ;
const section_bytes = mapped_macho [sect .offset ..][0 ..sect .size ];
sections [section_index ] = .{
.data = section_bytes ,
.owned = false ,
};
}
if (sections [@backingInt (Dwarf .Section .Id .debug_info )] == null or
sections [@backingInt (Dwarf .Section .Id .debug_abbrev )] == null or
sections [@backingInt (Dwarf .Section .Id .debug_str )] == null or
sections [@backingInt (Dwarf .Section .Id .debug_line )] == null )
{
return error .MissingDebugInfo ;
}
var dwarf : Dwarf = .{ .sections = sections };
errdefer dwarf .deinit (gpa );
dwarf .open (gpa , .little ) catch |err | switch (err ) {
error .InvalidDebugInfo ,
error .EndOfStream ,
error .Overflow ,
error .StreamTooLong ,
=> return error .InvalidDwarf ,
error .MissingDebugInfo ,
error .ReadFailed ,
error .OutOfMemory ,
=> |e | return e ,
};
return dwarf ;
}