diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-12-22 14:37:41 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:12 -0800 |
| commit | 3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9 (patch) | |
| tree | 5ae7765b93dfde9f5638b83ba2436fbbdd0da24d /lib/std/debug.zig | |
| parent | 86e9e32cf0d5a028d6ebb32f8d0f3d0a23e717b6 (diff) | |
| download | zig-3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9.tar.gz zig-3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9.zip | |
std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0
also fix some places that needed recancel(), thanks mlugg!
See #30562
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 5129a70b02..25a0bc120d 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -261,10 +261,6 @@ pub const sys_can_stack_trace = switch (builtin.cpu.arch) { else => true, }; -/// This is used for debug information and debug printing. It is intentionally -/// separate from the application's `Io` instance. -const static_single_threaded_io = Io.Threaded.global_single_threaded.ioBasic(); - /// Allows the caller to freely write to stderr until `unlockStderr` is called. /// /// During the lock, any `std.Progress` information is cleared from the terminal. @@ -284,15 +280,15 @@ const static_single_threaded_io = Io.Threaded.global_single_threaded.ioBasic(); /// Alternatively, use the higher-level `Io.lockStderr` to integrate with the /// application's chosen `Io` implementation. pub fn lockStderr(buffer: []u8) Io.LockedStderr { - return static_single_threaded_io.lockStderr(buffer, null) catch |err| switch (err) { - // Impossible to cancel because no calls to cancel using - // `static_single_threaded_io` exist. - error.Canceled => unreachable, + const io = std.options.debug_io; + return io.lockStderr(buffer, null) catch |err| switch (err) { + error.Canceled => io.recancel(), }; } pub fn unlockStderr() void { - static_single_threaded_io.unlockStderr(); + const io = std.options.debug_io; + io.unlockStderr(); } /// Writes to stderr, ignoring errors. @@ -627,7 +623,7 @@ pub noinline fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: defer it.deinit(); if (!it.stratOk(options.allow_unsafe_unwind)) return empty_trace; - const io = static_single_threaded_io; + const io = std.options.debug_io; var total_frames: usize = 0; var index: usize = 0; @@ -689,7 +685,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, t: Io.Termin var total_frames: usize = 0; var wait_for = options.first_address; var printed_any_frame = false; - const io = static_single_threaded_io; + const io = std.options.debug_io; while (true) switch (it.next(io)) { .switch_to_fp => |unwind_error| { switch (StackIterator.fp_usability) { @@ -797,7 +793,7 @@ pub fn writeStackTrace(st: *const StackTrace, t: Io.Terminal) Writer.Error!void return; }, }; - const io = static_single_threaded_io; + const io = std.options.debug_io; const captured_frames = @min(n_frames, st.instruction_addresses.len); for (st.instruction_addresses[0..captured_frames]) |ret_addr| { // `ret_addr` is the return address, which is *after* the function call. |
