| 1 | pub const std_options: std.Options = .{ |
| 2 | .allow_stack_tracing = false, |
| 3 | }; |
| 4 | |
| 5 | pub fn main() !void { |
| 6 | var st_buf: [8]usize = undefined; |
| 7 | var buf: [1024]u8 = undefined; |
| 8 | var stdout = std.Io.File.stdout().writer(std.Options.debug_io, &buf); |
| 9 | |
| 10 | const captured_st = try foo(&stdout.interface, &st_buf); |
| 11 | try std.debug.writeStackTrace(&captured_st, .{ .writer = &stdout.interface, .mode = .no_color }); |
| 12 | try stdout.interface.print("stack trace index: {d}\n", .{captured_st.return_addresses.len}); |
| 13 | |
| 14 | try stdout.interface.flush(); |
| 15 | } |
| 16 | fn foo(w: *std.Io.Writer, st_buf: []usize) !std.debug.StackTrace { |
| 17 | try std.debug.writeCurrentStackTrace(.{}, .{ .writer = w, .mode = .no_color }); |
| 18 | return std.debug.captureCurrentStackTrace(.{}, st_buf); |
| 19 | } |
| 20 | |
| 21 | const 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 | // |