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 {...@@ -308,6 +308,9 @@ pub fn unlockStderr() void {
308/// Alternatively, use the higher-level `std.log` or `Io.lockStderr` to308/// Alternatively, use the higher-level `std.log` or `Io.lockStderr` to
309/// integrate with the application's chosen `Io` implementation.309/// integrate with the application's chosen `Io` implementation.
310pub fn print(comptime fmt: []const u8, args: anytype) void {310pub 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);
311 var buffer: [64]u8 = undefined;314 var buffer: [64]u8 = undefined;
312 const stderr = lockStderr(&buffer);315 const stderr = lockStderr(&buffer);
313 defer unlockStderr();316 defer unlockStderr();
...@@ -326,6 +329,9 @@ pub inline fn getSelfDebugInfo() !*SelfInfo {...@@ -326,6 +329,9 @@ pub inline fn getSelfDebugInfo() !*SelfInfo {
326/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.329/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
327/// Obtains the stderr mutex while dumping.330/// Obtains the stderr mutex while dumping.
328pub fn dumpHex(bytes: []const u8) void {331pub fn dumpHex(bytes: []const u8) void {
332 const io = std.Options.debug_io;
333 const prev = io.swapCancelProtection(.blocked);
334 defer _ = io.swapCancelProtection(prev);
329 const stderr = lockStderr(&.{}).terminal();335 const stderr = lockStderr(&.{}).terminal();
330 defer unlockStderr();336 defer unlockStderr();
331 dumpHexFallible(stderr, bytes) catch {};337 dumpHexFallible(stderr, bytes) catch {};
...@@ -789,6 +795,9 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, t: Io.Termin...@@ -789,6 +795,9 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, t: Io.Termin
789}795}
790/// A thin wrapper around `writeCurrentStackTrace` which writes to stderr and ignores write errors.796/// A thin wrapper around `writeCurrentStackTrace` which writes to stderr and ignores write errors.
791pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void {797pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void {
798 const io = std.Options.debug_io;
799 const prev = io.swapCancelProtection(.blocked);
800 defer _ = io.swapCancelProtection(prev);
792 const stderr = lockStderr(&.{}).terminal();801 const stderr = lockStderr(&.{}).terminal();
793 defer unlockStderr();802 defer unlockStderr();
794 writeCurrentStackTrace(.{803 writeCurrentStackTrace(.{
...@@ -879,6 +888,9 @@ fn writeTrace(...@@ -879,6 +888,9 @@ fn writeTrace(
879}888}
880/// A thin wrapper around `writeStackTrace` which writes to stderr and ignores write errors.889/// A thin wrapper around `writeStackTrace` which writes to stderr and ignores write errors.
881pub fn dumpStackTrace(st: *const StackTrace) void {890pub fn dumpStackTrace(st: *const StackTrace) void {
891 const io = std.Options.debug_io;
892 const prev = io.swapCancelProtection(.blocked);
893 defer _ = io.swapCancelProtection(prev);
882 const stderr = lockStderr(&.{}).terminal();894 const stderr = lockStderr(&.{}).terminal();
883 defer unlockStderr();895 defer unlockStderr();
884 writeStackTrace(st, stderr) catch |err| switch (err) {896 writeStackTrace(st, stderr) catch |err| switch (err) {
...@@ -888,6 +900,9 @@ pub fn dumpStackTrace(st: *const StackTrace) void {...@@ -888,6 +900,9 @@ pub fn dumpStackTrace(st: *const StackTrace) void {
888900
889/// A thin wrapper around `writeErrorReturnTrace` which writes to stderr and ignores write errors.901/// A thin wrapper around `writeErrorReturnTrace` which writes to stderr and ignores write errors.
890pub fn dumpErrorReturnTrace(et: *const std.builtin.StackTrace) void {902pub 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);
891 const stderr = lockStderr(&.{}).terminal();906 const stderr = lockStderr(&.{}).terminal();
892 defer unlockStderr();907 defer unlockStderr();
893 writeErrorReturnTrace(et, stderr) catch |err| switch (err) {908 writeErrorReturnTrace(et, stderr) catch |err| switch (err) {