2017-10-01 06:58:41 +08:00
|
|
|
// This file is the default panic handler if the root source file does not
|
|
|
|
// have a `pub fn panic`.
|
|
|
|
// If this file wants to import other files *by name*, support for that would
|
|
|
|
// have to be added in the compiler.
|
|
|
|
|
|
|
|
const builtin = @import("builtin");
|
2018-01-12 15:12:11 +08:00
|
|
|
const std = @import("std");
|
2017-10-01 06:58:41 +08:00
|
|
|
|
2018-05-31 22:56:59 +08:00
|
|
|
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
|
2019-06-16 00:28:21 +08:00
|
|
|
@setCold(true);
|
|
|
|
switch (builtin.os) {
|
|
|
|
.freestanding => {
|
2019-07-03 07:44:49 +08:00
|
|
|
while (true) {
|
|
|
|
@breakpoint();
|
|
|
|
}
|
2019-06-16 00:28:21 +08:00
|
|
|
},
|
|
|
|
.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);
|
|
|
|
},
|
|
|
|
}
|
2017-10-01 06:58:41 +08:00
|
|
|
}
|