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 › getDwarfForAddress Public Type Function getDwarfForAddress Doc Source Public Type Function std.debug.MachOFile.getDwarfForAddress
pub fn getDwarfForAddress (mf : *MachOFile , gpa : Allocator , io : Io , vaddr : u64 ) !struct File debug/MachOFile.zig: 239
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 pub fn getDwarfForAddress (mf : *MachOFile , gpa : Allocator , io : Io , vaddr : u64 ) !struct { *Dwarf , u64 } {
if (mf .adjacent_dsym ) |*dsym | {
return .{ &dsym .dwarf , vaddr };
}
const symbol = Symbol .find (mf .symbols , vaddr ) orelse return error .MissingDebugInfo ;
if (symbol .ofile == Symbol .unknown_ofile ) return error .MissingDebugInfo ;
// offset of `address` from start of `symbol`
const address_symbol_offset = vaddr - symbol .addr ;
// Take the symbol name from the N_FUN STAB entry, we're going to
// use it if we fail to find the DWARF infos
const stab_symbol = mem .sliceTo (mf .strings [symbol .strx ..], 0 );
const gop = try mf .ofiles .getOrPut (gpa , symbol .ofile );
if (!gop .found_existing ) {
const name = mem .sliceTo (mf .strings [symbol .ofile ..], 0 );
gop .value_ptr .* = loadOFile (gpa , io , name );
}
const of = &(gop .value_ptr .* catch |err | return err );
const symbol_index = of .symbols_by_name .getKeyAdapted (
@as ([]const u8 , stab_symbol ),
@as (OFile .SymbolAdapter , .{ .strtab = of .strtab , .symtab_raw = of .symtab_raw }),
) orelse return error .MissingDebugInfo ;
const symbol_ofile_vaddr = vaddr : {
var sym = of .symtab_raw [symbol_index ];
if (builtin .cpu .arch .endian () != .little ) std .mem .byteSwapAllFields (macho .nlist_64 , &sym );
break :vaddr sym .n_value ;
};
return .{ &of .dwarf , symbol_ofile_vaddr + address_symbol_offset };
}