feature. See also
. The project being documented here (as the example) is the Zig library itself.
debug.printLineInfo
fn printLineInfo(
io: Io,
t: Io.Terminal,
debug_info: *SelfInfo,
address: usize,
symbol: Symbol,
) Writer.Error!void
File
Code
fn printLineInfo(
io: Io,
t: Io.Terminal,
debug_info: *SelfInfo,
address: usize,
symbol: Symbol,
) Writer.Error!void {
const writer = t.writer;
t.setColor(.bold) catch {};
if (symbol.source_location) |*sl| {
if (sl.column == 0) {
try writer.print("{s}:{d}", .{ sl.file_name, sl.line });
} else {
try writer.print("{s}:{d}:{d}", .{ sl.file_name, sl.line, sl.column });
}
} else {
try writer.writeAll("???:?:?");
}
t.setColor(.reset) catch {};
try writer.writeAll(": ");
t.setColor(.dim) catch {};
try writer.print("0x{x} in {s} ({s})", .{
address,
symbol.name orelse "???",
symbol.compile_unit_name orelse debug_info.getModuleName(io, address) catch "???",
});
t.setColor(.reset) catch {};
try writer.writeAll("\n");
if (symbol.source_location) |sl| {
if (printLineFromFile(io, writer, sl)) {
if (sl.column > 0) {
const space_needed = @as(usize, @intCast(sl.column - 1));
try writer.splatByteAll(' ', space_needed);
t.setColor(.green) catch {};
try writer.writeAll("^");
t.setColor(.reset) catch {};
}
try writer.writeAll("\n");
} else |_| {
// corresponding line number. The user can always open the source file themselves.
}
}
}