feature. See also
. The project being documented here (as the example) is the Zig library itself.
debug.printSourceAtAddress
fn printSourceAtAddress(
io: Io,
text_arena: *std.heap.ArenaAllocator,
debug_info: *SelfInfo,
t: Io.Terminal,
options: PrintSourceAddressOptions,
) Writer.Error!void
File
Code
fn printSourceAtAddress(
io: Io,
text_arena: *std.heap.ArenaAllocator,
debug_info: *SelfInfo,
t: Io.Terminal,
options: PrintSourceAddressOptions,
) Writer.Error!void {
defer _ = text_arena.reset(.retain_capacity);
// in the common case where only one element is needed
var buf: [1]Symbol = undefined;
var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&buf), getDebugInfoAllocator());
const symbol_allocator = bfa.allocator();
var symbols = std.ArrayList(Symbol).initCapacity(symbol_allocator, 1) catch unreachable;
defer symbols.deinit(symbol_allocator);
debug_info.getSymbols(
io,
symbol_allocator,
text_arena.allocator(),
options.address,
options.resolve_inline_callers,
&symbols,
) catch |err| {
t.setColor(.dim) catch {};
defer t.setColor(.reset) catch {};
switch (err) {
error.MissingDebugInfo,
error.UnsupportedDebugInfo,
error.InvalidDebugInfo,
=> {},
error.ReadFailed, error.Unexpected, error.Canceled => {
try t.writer.print("Failed to read debug info from filesystem, trace may be incomplete\n\n", .{});
},
error.OutOfMemory => {
t.setColor(.dim) catch {};
try t.writer.print("Ran out of memory loading debug info, trace may be incomplete\n\n", .{});
t.setColor(.reset) catch {};
},
}
};
// initialized with a capacity of 1.
if (symbols.items.len == 0) symbols.appendAssumeCapacity(.unknown);
for (symbols.items) |symbol| {
try printLineInfo(io, t, debug_info, options.address, symbol);
}
}