authorgravatar for lukas@lalinsky.comLukas Lalinsky <lukas@lalinsky.com> 2026-06-07 12:21:13+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-11 06:05:18+02:00
log041ae87b987fbb1a1c8b286e09123965073ccc0a
treea134d09b0ff98881b9350b8773237f15b3a5a6bf
parent60e4f56b69e5a760cda7fda87332670ab4405c1f

Avoid `error.Canceled` swallowing in `std.debug.*


1 files changed, 15 insertions(+), 0 deletions(-)

lib/std/debug.zig+15
......@@ -308,6 +308,9 @@ pub fn unlockStderr() void {
308308/// Alternatively, use the higher-level `std.log` or `Io.lockStderr` to
309309/// integrate with the application's chosen `Io` implementation.
310310pub fn print(comptime fmt: []const u8, args: anytype) void {
311 const io = std.Options.debug_io;
312 const prev = io.swapCancelProtection(.blocked);
313 defer _ = io.swapCancelProtection(prev);
311314 var buffer: [64]u8 = undefined;
312315 const stderr = lockStderr(&buffer);
313316 defer unlockStderr();
......@@ -326,6 +329,9 @@ pub inline fn getSelfDebugInfo() !*SelfInfo {
326329/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
327330/// Obtains the stderr mutex while dumping.
328331pub fn dumpHex(bytes: []const u8) void {
332 const io = std.Options.debug_io;
333 const prev = io.swapCancelProtection(.blocked);
334 defer _ = io.swapCancelProtection(prev);
329335 const stderr = lockStderr(&.{}).terminal();
330336 defer unlockStderr();
331337 dumpHexFallible(stderr, bytes) catch {};
......@@ -789,6 +795,9 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, t: Io.Termin
789795}
790796/// A thin wrapper around `writeCurrentStackTrace` which writes to stderr and ignores write errors.
791797pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void {
798 const io = std.Options.debug_io;
799 const prev = io.swapCancelProtection(.blocked);
800 defer _ = io.swapCancelProtection(prev);
792801 const stderr = lockStderr(&.{}).terminal();
793802 defer unlockStderr();
794803 writeCurrentStackTrace(.{
......@@ -879,6 +888,9 @@ fn writeTrace(
879888}
880889/// A thin wrapper around `writeStackTrace` which writes to stderr and ignores write errors.
881890pub fn dumpStackTrace(st: *const StackTrace) void {
891 const io = std.Options.debug_io;
892 const prev = io.swapCancelProtection(.blocked);
893 defer _ = io.swapCancelProtection(prev);
882894 const stderr = lockStderr(&.{}).terminal();
883895 defer unlockStderr();
884896 writeStackTrace(st, stderr) catch |err| switch (err) {
......@@ -888,6 +900,9 @@ pub fn dumpStackTrace(st: *const StackTrace) void {
888900
889901/// A thin wrapper around `writeErrorReturnTrace` which writes to stderr and ignores write errors.
890902pub fn dumpErrorReturnTrace(et: *const std.builtin.StackTrace) void {
903 const io = std.Options.debug_io;
904 const prev = io.swapCancelProtection(.blocked);
905 defer _ = io.swapCancelProtection(prev);
891906 const stderr = lockStderr(&.{}).terminal();
892907 defer unlockStderr();
893908 writeErrorReturnTrace(et, stderr) catch |err| switch (err) {