diff --git a/lib/compiler/reduce.zig b/lib/compiler/reduce.zig index abdd9f84362292f50dc1c67d04cbc707d2e30888..8d4f270a7946ca32ae04aa996df91a1decc22743 100644 --- a/lib/compiler/reduce.zig +++ b/lib/compiler/reduce.zig @@ -291,7 +291,11 @@ fn termToInteresting(term: std.process.Child.Term) Interestingness { std.debug.print("interestingness check terminated with signal {t}\n", .{sig}); return .boring; }, - else => { + .stopped => |sig| { + std.debug.print("interestingness check stopped with signal {t}\n", .{sig}); + return .boring; + }, + .unknown => { std.debug.print("interestingness check aborted unexpectedly\n", .{}); return .boring; }, diff --git a/lib/compiler/std-docs.zig b/lib/compiler/std-docs.zig index 5660e6e56dbf4c5b60aab76305a22f1de730f64b..e1ef5178a88450ffa6b6dc214eb820ace1b07931 100644 --- a/lib/compiler/std-docs.zig +++ b/lib/compiler/std-docs.zig @@ -423,7 +423,14 @@ fn buildWasmBinary( ); return error.WasmCompilationFailed; }, - .stopped, .unknown => { + .stopped => |sig| { + std.log.err( + "the following command stopped unexpectedly with signal {t}:\n{s}", + .{ sig, try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) }, + ); + return error.WasmCompilationFailed; + }, + .unknown => { std.log.err( "the following command terminated unexpectedly:\n{s}", .{try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)}, diff --git a/lib/std/Build.zig b/lib/std/Build.zig index d415301b0a87c2d4c022a1f16af5be899901fa44..75f82457b2f7bf8c1b66c2d4c1c0e2048c9e7c45 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1899,11 +1899,11 @@ pub fn runAllowFail( } return stdout; }, - .signal => |sig| { + .signal, .stopped => |sig| { out_code.* = @as(u8, @truncate(@intFromEnum(sig))); return error.ProcessTerminated; }, - .stopped, .unknown => |code| { + .unknown => |code| { out_code.* = @as(u8, @truncate(code)); return error.ProcessTerminated; }, diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index 5876614099b38b9608006650b464978a87443b6f..9df1b9d0383db5fa8cdc582d6c7bc6e466132781 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -725,19 +725,12 @@ pub inline fn handleChildProcUnsupported(s: *Step) error{ OutOfMemory, MakeFaile /// Asserts that the caller has already populated `s.result_failed_command`. pub fn handleChildProcessTerm(s: *Step, term: std.process.Child.Term) error{ MakeFailed, OutOfMemory }!void { assert(s.result_failed_command != null); - switch (term) { - .exited => |code| { - if (code != 0) { - return s.fail("process exited with error code {d}", .{code}); - } - }, - .signal => |sig| { - return s.fail("process terminated with signal {t}", .{sig}); - }, - .stopped, .unknown => { - return s.fail("process terminated unexpectedly", .{}); - }, - } + return switch (term) { + .exited => |code| if (code != 0) s.fail("process exited with error code {d}", .{code}), + .signal => |sig| s.fail("process terminated with signal {t}", .{sig}), + .stopped => |sig| s.fail("process stopped with signal {t}", .{sig}), + .unknown => s.fail("process terminated unexpectedly", .{}), + }; } pub fn allocPrintCmd( diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index da20a15e78e03b1a32613513eaddcc81a87a1819..76acbcb4b799e42b1d54f07a1e36ba950317a029 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1173,7 +1173,7 @@ fn formatTerm(term: ?process.Child.Term, w: *std.Io.Writer) std.Io.Writer.Error! if (term) |t| switch (t) { .exited => |code| try w.print("exited with code {d}", .{code}), .signal => |sig| try w.print("terminated with signal {t}", .{sig}), - .stopped => |sig| try w.print("stopped with signal {d}", .{sig}), + .stopped => |sig| try w.print("stopped with signal {t}", .{sig}), .unknown => |code| try w.print("terminated for unknown reason with code {d}", .{code}), } else { try w.writeAll("exited with any code"); @@ -2804,8 +2804,8 @@ fn hashStdIo(hh: *std.Build.Cache.HashHelper, stdio: StdIo) void { .expect_term => |term| { hh.add(@as(std.meta.Tag(process.Child.Term), term)); switch (term) { - inline .exited, .signal => |x| hh.add(x), - .stopped, .unknown => |x| hh.add(x), + inline .exited, .signal, .stopped => |x| hh.add(x), + .unknown => |x| hh.add(x), } }, } diff --git a/lib/std/Build/WebServer.zig b/lib/std/Build/WebServer.zig index 02778dec7a685dde4f39eae3f74b184cdcd00606..ea7e0a6e26a91b33b9c80c67ccdbf3a6fdfc8fc4 100644 --- a/lib/std/Build/WebServer.zig +++ b/lib/std/Build/WebServer.zig @@ -681,7 +681,14 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim ); return error.WasmCompilationFailed; }, - .stopped, .unknown => { + .stopped => |sig| { + log.err( + "the following command stopped unexpectedly with signal {t}:\n{s}", + .{ sig, try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) }, + ); + return error.WasmCompilationFailed; + }, + .unknown => { log.err( "the following command terminated unexpectedly:\n{s}", .{try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)}, diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index c3c2adc4ab06608141746524365e22793095fe7c..2fcd4551104797f08b75d8ababb7833455d01590 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -15281,7 +15281,7 @@ fn childWaitPosix(child: *process.Child) process.Child.WaitError!process.Child.T return switch (code) { .EXITED => .{ .exited = @truncate(status) }, .KILLED, .DUMPED => .{ .signal = @enumFromInt(status) }, - .TRAPPED, .STOPPED => .{ .stopped = status }, + .TRAPPED, .STOPPED => .{ .stopped = @enumFromInt(status) }, _, .CONTINUED => .{ .unknown = status }, }; }, diff --git a/lib/std/Io/Uring.zig b/lib/std/Io/Uring.zig index b28d78db790904793da9c857243bae1b644532de..759a9bac20fa6257b36ea93d220fa5e977f05905 100644 --- a/lib/std/Io/Uring.zig +++ b/lib/std/Io/Uring.zig @@ -4729,7 +4729,7 @@ fn childWait(userdata: ?*anyopaque, child: *process.Child) process.Child.WaitErr return switch (code) { .EXITED => .{ .exited = @truncate(status) }, .KILLED, .DUMPED => .{ .signal = @enumFromInt(status) }, - .TRAPPED, .STOPPED => .{ .stopped = status }, + .TRAPPED, .STOPPED => .{ .stopped = @enumFromInt(status) }, _, .CONTINUED => .{ .unknown = status }, }; }, diff --git a/lib/std/c.zig b/lib/std/c.zig index 90efa67884e844c8ce4514929ac6dd37b911e07a..f0b03917855a2261fad5352220329c6904f922dc 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -3721,14 +3721,14 @@ pub const W = switch (native_os) { pub fn TERMSIG(x: u32) SIG { return @enumFromInt(status(x)); } - pub fn STOPSIG(x: u32) u32 { - return x >> 8; + pub fn STOPSIG(x: u32) SIG { + return @enumFromInt(x >> 8); } pub fn IFEXITED(x: u32) bool { return status(x) == 0; } pub fn IFSTOPPED(x: u32) bool { - return status(x) == stopped and STOPSIG(x) != 0x13; + return status(x) == stopped and @as(u32, @intFromEnum(STOPSIG(x))) != 0x13; } pub fn IFSIGNALED(x: u32) bool { return status(x) != stopped and status(x) != 0; @@ -3754,8 +3754,8 @@ pub const W = switch (native_os) { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; @@ -3782,8 +3782,8 @@ pub const W = switch (native_os) { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; @@ -3816,8 +3816,8 @@ pub const W = switch (native_os) { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; @@ -3850,8 +3850,8 @@ pub const W = switch (native_os) { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; @@ -3879,8 +3879,8 @@ pub const W = switch (native_os) { return @enumFromInt((s >> 8) & 0xff); } - pub fn STOPSIG(s: u32) u32 { - return (s >> 16) & 0xff; + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt((s >> 16) & 0xff); } pub fn IFEXITED(s: u32) bool { @@ -3906,8 +3906,8 @@ pub const W = switch (native_os) { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; @@ -3938,8 +3938,8 @@ pub const W = switch (native_os) { return @intCast((s & 0xff00) >> 8); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn TERMSIG(s: u32) SIG { diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index aa75916f21d1a439e3c608b8536c4cf76bccf022..d8ed5887ff7a8fc96c45cac41506d12e06b82b33 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -212,7 +212,7 @@ pub const W = struct { return @enumFromInt(s & 0x7f); } pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index eb4908f3318a4bc8dff8c3bc11dc1b7ed1bc448b..424f80bb6a3fbe00e0ffc5ca69379ded3d407c5c 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -3883,8 +3883,8 @@ pub const W = struct { pub fn TERMSIG(s: u32) SIG { return @enumFromInt(s & 0x7f); } - pub fn STOPSIG(s: u32) u32 { - return EXITSTATUS(s); + pub fn STOPSIG(s: u32) SIG { + return @enumFromInt(EXITSTATUS(s)); } pub fn IFEXITED(s: u32) bool { return (s & 0x7f) == 0; diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index 0cc60a23e999239401c7531cade47eff2d27e52d..65f6429e59f399fcb34137587d3f73ac9a35c24b 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -94,7 +94,7 @@ pub const ResourceUsageStatistics = struct { pub const Term = union(enum) { exited: u8, signal: std.posix.SIG, - stopped: u32, + stopped: std.posix.SIG, unknown: u32, }; diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 524c5e29afc5407036069264a16c9ea698e8c794..61f78093d6927fee7ee68dc274390b604be1535c 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -1185,11 +1185,25 @@ fn detectAndroidApiLevel(io: Io) !u32 { return error.ApiLevelQueryFailed; }; - const term = try child.wait(io); - if (term != .exited or term.exited != 0) { - std.log.err("getprop terminated abnormally: {}", .{term}); - return error.ApiLevelQueryFailed; + switch (try child.wait(io)) { + .exited => |code| if (code != 0) { + std.log.err("getprop terminated abnormally with exit code: {d}", .{code}); + return error.ApiLevelQueryFailed; + }, + .signal => |sig| { + std.log.err("getprop terminated abnormally with signal: {t}", .{sig}); + return error.ApiLevelQueryFailed; + }, + .stopped => |sig| { + std.log.err("getprop stopped abnormally with signal: {t}", .{sig}); + return error.ApiLevelQueryFailed; + }, + .unknown => { + std.log.err("getprop terminated abnormally", .{}); + return error.ApiLevelQueryFailed; + }, } + return api_level; } diff --git a/src/Compilation.zig b/src/Compilation.zig index fb0e5cc83f02513600cd0fc0fe92032c20fa3337..695dd8918fd7d7ff10f11f9ffff3b33b724aef84 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5870,7 +5870,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr log.err("clang failed with stderr: {s}", .{stderr}); return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig}); }, - else => { + .stopped => |sig| { + log.err("clang failed with stderr: {s}", .{stderr}); + return comp.failCObj(c_object, "clang stopped with signal {t}", .{sig}); + }, + .unknown => { log.err("clang terminated with stderr: {s}", .{stderr}); return comp.failCObj(c_object, "clang terminated unexpectedly", .{}); }, @@ -6297,7 +6301,11 @@ fn spawnZigRc( log.err("zig rc signaled {t} with stderr:\n{s}", .{ sig, stderr }); return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{}); }, - else => { + .stopped => |sig| { + log.err("zig rc stopped {t} with stderr:\n{s}", .{ sig, stderr }); + return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{}); + }, + .unknown => { log.err("zig rc terminated with stderr:\n{s}", .{stderr}); return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{}); }, diff --git a/src/link/Lld.zig b/src/link/Lld.zig index 9a6f4f392be21ebb3cae4a995c68d1a8fcbb6e87..ffb9020e7f64e3f4caa169407730d4365aa7c080 100644 --- a/src/link/Lld.zig +++ b/src/link/Lld.zig @@ -1733,7 +1733,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi }, .stopped => |sig| { if (comp.clang_passthrough_mode) std.process.abort(); - return diags.fail("{s} stopped with signal {d} and stderr:\n{s}", .{ argv[0], sig, stderr }); + return diags.fail("{s} stopped with signal {t} and stderr:\n{s}", .{ argv[0], sig, stderr }); }, .unknown => |code| { if (comp.clang_passthrough_mode) std.process.abort(); diff --git a/src/main.zig b/src/main.zig index e837d204a3d906d4022eb6303f495c695acb877d..0ba118025462ef94db94e5d7bca4ebd148a7aad3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4580,7 +4580,11 @@ fn runOrTest( const cmd = try std.mem.join(arena, " ", argv.items); fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd }); }, - else => { + .stopped => |sig| { + const cmd = try std.mem.join(arena, " ", argv.items); + fatal("the following command stopped with signal {t}:\n{s}", .{ sig, cmd }); + }, + .unknown => { process.exit(1); }, } @@ -5630,7 +5634,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8, const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd }); }, - else => { + .stopped => |sig| { + const cmd = try std.mem.join(arena, " ", child_argv.items); + fatal("the following build command stopped with signal {t}:\n{s}", .{ sig, cmd }); + }, + .unknown => { const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following build command crashed:\n{s}", .{cmd}); }, @@ -5932,7 +5940,11 @@ fn jitCmdInner( const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd }); }, - else => { + .stopped => |sig| { + const cmd = try std.mem.join(arena, " ", child_argv.items); + fatal("the following build command stopped with signal {t}:\n{s}", .{ sig, cmd }); + }, + .unknown => { const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following build command crashed:\n{s}", .{cmd}); }, diff --git a/tools/doctest.zig b/tools/doctest.zig index 0e29b2b983f6f5915fae5f9ae0fc759ba1abcdfa..2b0d7431b7e2bcf541f1ddd8dbe4ef3b17e70fae 100644 --- a/tools/doctest.zig +++ b/tools/doctest.zig @@ -1141,7 +1141,12 @@ fn run( dumpArgs(args); return error.ChildCrashed; }, - else => { + .stopped => |sig| { + std.debug.print("{s}\nThe following command stopped with signal {t}:\n", .{ result.stderr, sig }); + dumpArgs(args); + return error.ChildCrashed; + }, + .unknown => { std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr}); dumpArgs(args); return error.ChildCrashed; diff --git a/tools/incr-check.zig b/tools/incr-check.zig index 453139609c4a663e7681cc5846b44050cbbd6789..97ed993c2bed3747c8da1d9c65a13e02bd20d4e9 100644 --- a/tools/incr-check.zig +++ b/tools/incr-check.zig @@ -568,7 +568,10 @@ const Eval = struct { .signal => |sig| { eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig }); }, - .stopped, .unknown => { + .stopped => |sig| { + eval.fatal("generated executable '{s}' stopped with signal {t}", .{ binary_path, sig }); + }, + .unknown => { eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path}); }, } @@ -627,19 +630,17 @@ const Eval = struct { }) catch |err| { eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err }); }; + + if (result.term == .exited and result.term.exited == 0) return; + + if (result.stderr.len != 0) { + std.log.err("zig cc stderr:\n{s}", .{result.stderr}); + } switch (result.term) { - .exited => |code| if (code != 0) { - if (result.stderr.len != 0) { - std.log.err("zig cc stderr:\n{s}", .{result.stderr}); - } - eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }); - }, - .signal, .stopped, .unknown => { - if (result.stderr.len != 0) { - std.log.err("zig cc stderr:\n{s}", .{result.stderr}); - } - eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path}); - }, + .exited => |code| eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }), + .signal => |sig| eval.fatal("zig cc for '{s}' terminated unexpectedly with signal {t}", .{ c_path, sig }), + .stopped => |sig| eval.fatal("zig cc for '{s}' stopped unexpectedly with signal {t}", .{ c_path, sig }), + .unknown => eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path}), } } @@ -918,7 +919,8 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void { switch (term) { .exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}), .signal => |sig| eval.fatal("compiler terminated with signal {t}", .{sig}), - .stopped, .unknown => eval.fatal("compiler terminated unexpectedly", .{}), + .stopped => |sig| eval.fatal("compiler stopped unexpectedly with signal {t}", .{sig}), + .unknown => eval.fatal("compiler terminated unexpectedly", .{}), } } diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index b2661ac181f1a2f3405ffc19a8da1e48d811647b..49b8e72f58372ee2a5c63ec2e0132d9fbdfd1fdb 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -688,9 +688,17 @@ pub fn main(init: std.process.Init) !void { const json_text = switch (child_result.term) { .exited => |code| if (code == 0) child_result.stdout else { - fatal("llvm-tblgen exited with code {d}", .{code}); + fatal("llvm-tblgen exited with code {d}\n", .{code}); + }, + .signal => |sig| { + fatal("llvm-tblgen terminated with signal {t}\n", .{sig}); + }, + .stopped => |sig| { + fatal("llvm-tblgen stopped with signal {d}\n", .{sig}); + }, + .unknown => { + fatal("llvm-tblgen crashed\n", .{}); }, - else => fatal("llvm-tblgen crashed", .{}), }; const parsed = try json.parseFromSlice(json.Value, arena, json_text, .{}); diff --git a/tools/update_cpu_features.zig b/tools/update_cpu_features.zig index 636f45fa86f98513e45f6c212f389f56ec442281..8a8e15558b19db009ea978730813452aeb621889 100644 --- a/tools/update_cpu_features.zig +++ b/tools/update_cpu_features.zig @@ -2012,7 +2012,15 @@ fn processOneTarget(io: Io, job: Job) void { std.debug.print("llvm-tblgen exited with code {d}\n", .{code}); std.process.exit(1); }, - else => { + .signal => |sig| { + std.debug.print("llvm-tblgen terminated with signal {t}\n", .{sig}); + std.process.exit(1); + }, + .stopped => |sig| { + std.debug.print("llvm-tblgen stopped with signal {t}\n", .{sig}); + std.process.exit(1); + }, + .unknown => { std.debug.print("llvm-tblgen crashed\n", .{}); std.process.exit(1); },