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 library itself.
Zig › std/ › debug/ › Dwarf.zig › readDebugAddr
readDebugAddr
Dwarf.readDebugAddr
fn readDebugAddr (di : Dwarf , endian : Endian , compile_unit : *const CompileUnit , index : u64 ) !u64
File
Code
fn readDebugAddr (di : Dwarf , endian : Endian , compile_unit : *const CompileUnit , index : u64 ) !u64 {
const debug_addr = di .section (.debug_addr ) orelse return bad ();
// need to read the header to know the size of each item. Empirically,
// it may disagree with is_64 on the compile unit.
// The header is 8 or 12 bytes depending on is_64.
if (compile_unit .addr_base < 8 ) return bad ();
const version = mem .readInt (u16 , debug_addr [compile_unit .addr_base - 4 ..][0 ..2 ], endian );
if (version != 5 ) return bad ();
const addr_size = debug_addr [compile_unit .addr_base - 2 ];
const seg_size = debug_addr [compile_unit .addr_base - 1 ];
const byte_offset = compile_unit .addr_base + (addr_size + seg_size ) * index ;
if (byte_offset + addr_size > debug_addr .len ) return bad ();
return switch (addr_size ) {
1 => debug_addr [@intCast (byte_offset )],
2 => mem .readInt (u16 , debug_addr [@intCast (byte_offset )..][0 ..2 ], endian ),
4 => mem .readInt (u32 , debug_addr [@intCast (byte_offset )..][0 ..4 ], endian ),
8 => mem .readInt (u64 , debug_addr [@intCast (byte_offset )..][0 ..8 ], endian ),
else => bad (),
};
}