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.

getModuleNameInner

MachO.getModuleNameInner
fn getModuleNameInner(address: usize) ?[]const u8

File

Code

fn getModuleNameInner(address: usize) ?[]const u8 {
    switch (builtin.target.os.tag) {
        .macos => {
            // This function is marked as deprecated; however, it is significantly more performant
            // than `dladdr` (since the latter also does a very slow symbol lookup), so let's just
            // use it for the better performance since it's still available.
            return std.mem.span(std.c.dyld_image_path_containing_address(
                @ptrFromInt(address),
            ) orelse return null);
        },
        else => {
            // On other Darwin systems, the function used above is entirely unavailable, so we have
            // no choice but to use the slow `dladdr`.
            var info: std.c.dl_info = undefined;
            if (std.c.dladdr(@ptrFromInt(address), &info) == 0) {
                return null;
            }
            return std.mem.span(info.fname);
        },
    }
}