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.

getSymbols

Elf.getSymbols
pub fn getSymbols(
    si: *SelfInfo,
    io: Io,
    symbol_allocator: Allocator,
    text_arena: Allocator,
    address: usize,
    resolve_inline_callers: bool,
    symbols: *std.ArrayList(std.debug.Symbol),
) Error!void

File

Code

pub fn getSymbols(
    si: *SelfInfo,
    io: Io,
    symbol_allocator: Allocator,
    text_arena: Allocator,
    address: usize,
    resolve_inline_callers: bool,
    symbols: *std.ArrayList(std.debug.Symbol),
) Error!void {
    const gpa = std.debug.getDebugInfoAllocator();
    const module = try si.findModule(gpa, io, address, .exclusive);
    defer si.rwlock.unlock(io);

    const vaddr = address - module.load_offset;

    const loaded_elf = try module.getLoadedElf(gpa, io);
    const dwarf_err: ?Error = err: {
        const dwarf = &(loaded_elf.file.dwarf orelse break :err null);
        switch (loaded_elf.dwarf) {
            .not_scanned => if (dwarf.open(gpa, native_endian)) {
                loaded_elf.dwarf = .ok;
            } else |err| switch (err) {
                error.InvalidDebugInfo,
                error.EndOfStream,
                error.Overflow,
                error.ReadFailed,
                error.StreamTooLong,
                => {
                    loaded_elf.dwarf = .invalid;
                    break :err error.InvalidDebugInfo;
                },
                error.MissingDebugInfo => {
                    loaded_elf.dwarf = .missing;
                    break :err error.MissingDebugInfo;
                },
                error.OutOfMemory => |e| return e,
            },
            .invalid => break :err error.InvalidDebugInfo,
            .missing => break :err error.MissingDebugInfo,
            .ok => {},
        }
        return dwarf.getSymbols(
            symbol_allocator,
            text_arena,
            native_endian,
            vaddr,
            resolve_inline_callers,
            symbols,
        ) catch |err| switch (err) {
            error.InvalidDebugInfo,
            error.MissingDebugInfo,
            error.UnsupportedDebugInfo,
            => |e| break :err e,

            error.ReadFailed,
            error.OutOfMemory,
            error.Canceled,
            error.Unexpected,
            => |e| return e,
        };
    };
    // When DWARF is unavailable, fall back to searching the symtab.
    try symbols.append(symbol_allocator, loaded_elf.file.searchSymtab(gpa, vaddr) catch |err| switch (err) {
        error.NoSymtab, error.NoStrtab => return error.MissingDebugInfo,
        error.BadSymtab => return error.InvalidDebugInfo,
        error.OutOfMemory => |e| return e,
    });
    // After searching the symtab, still report the DWARF error.
    if (dwarf_err) |e| return e;
}