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 › writeTrace Private Function writeTrace Doc Source Private Function std.debug.writeTrace
fn writeTrace (
addresses : []const usize ,
skipped : SkippedAddresses ,
t : Io .Terminal ,
resolve_inline_callers : bool ,
) Writer .Error !void Params addresses : []const usize skipped : SkippedAddresses t : Io .Terminal resolve_inline_callers : bool File debug.zig: 864
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912 fn writeTrace (
addresses : []const usize ,
skipped : SkippedAddresses ,
t : Io .Terminal ,
resolve_inline_callers : bool ,
) Writer .Error !void {
var text_arena : std .heap .ArenaAllocator = .init (getDebugInfoAllocator ());
defer text_arena .deinit ();
const writer = t .writer ;
if (!std .options .allow_stack_tracing ) {
t .setColor (.dim ) catch {};
try writer .print ("Cannot print stack trace: stack tracing is disabled\n" , .{});
t .setColor (.reset ) catch {};
return ;
}
if (addresses .len == 0 ) return writer .writeAll ("(empty stack trace)\n" );
const di = getSelfDebugInfo () catch |err | switch (err ) {
error .UnsupportedTarget => {
t .setColor (.dim ) catch {};
try writer .print ("Cannot print stack trace: debug info unavailable for target\n\n" , .{});
t .setColor (.reset ) catch {};
return ;
},
};
const io = std .Options .debug_io ;
for (addresses ) |addr | {
// `addr` is the return address, which is *after* the function call.
// Subtract 1 to get an address *in* the function call for a better source location.
try printSourceAtAddress (io , &text_arena , di , t , .{
.address = addr -| StackIterator .ra_call_offset ,
.resolve_inline_callers = resolve_inline_callers ,
});
}
switch (skipped ) {
.none => {},
.unknown => {
t .setColor (.bold ) catch {};
try writer .writeAll ("(additional stack frames may have been skipped...)\n" );
t .setColor (.reset ) catch {};
},
else => |n | {
t .setColor (.bold ) catch {};
try writer .print ("({d} additional stack frames skipped due to buffer size limitations...)\n" , .{n });
t .setColor (.reset ) catch {};
},
}
}