master
1pub const std_options: std.Options = .{
2 .allow_stack_tracing = false,
3};
4
5pub fn main() !void {
6 var st_buf: [8]usize = undefined;
7 var buf: [1024]u8 = undefined;
8 var stdout = std.fs.File.stdout().writer(&buf);
9
10 const captured_st = try foo(&stdout.interface, &st_buf);
11 try std.debug.writeStackTrace(&captured_st, &stdout.interface, .no_color);
12 try stdout.interface.print("stack trace index: {d}\n", .{captured_st.index});
13
14 try stdout.interface.flush();
15}
16fn foo(w: *std.Io.Writer, st_buf: []usize) !std.builtin.StackTrace {
17 try std.debug.writeCurrentStackTrace(.{}, w, .no_color);
18 return std.debug.captureCurrentStackTrace(.{}, st_buf);
19}
20
21const std = @import("std");
22
23// run
24//
25// Cannot print stack trace: stack tracing is disabled
26// Cannot print stack trace: stack tracing is disabled
27// stack trace index: 0
28//