From 6bf193af192ffaf3465958a243ec8fc8941cfe4d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 15 Jun 2019 12:28:21 -0400 Subject: better result location semantics with optionals and return locations somewhere along this branch, #1901 has been fixed. --- std/special/panic.zig | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'std/special/panic.zig') diff --git a/std/special/panic.zig b/std/special/panic.zig index 50dc5e0c65..92e0d9164c 100644 --- a/std/special/panic.zig +++ b/std/special/panic.zig @@ -7,8 +7,23 @@ const builtin = @import("builtin"); const std = @import("std"); pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { - const stderr = std.io.getStdErr() catch std.process.abort(); - stderr.write("panic: ") catch std.process.abort(); - stderr.write(msg) catch std.process.abort(); - std.process.abort(); + @setCold(true); + switch (builtin.os) { + .freestanding => { + while (true) {} + }, + .wasi => { + std.debug.warn("{}", msg); + _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); + unreachable; + }, + .uefi => { + // TODO look into using the debug info and logging helpful messages + std.os.abort(); + }, + else => { + const first_trace_addr = @returnAddress(); + std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); + }, + } } -- cgit v1.2.3