diff options
Diffstat (limited to 'std/debug.zig')
| -rw-r--r-- | std/debug.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/std/debug.zig b/std/debug.zig index 435d572ac2..f3278a0e45 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -13,6 +13,27 @@ pub fn assert(ok: bool) { if (!ok) @unreachable() } +var panicking = false; +/// This is the default panic implementation. +pub coldcc fn panic(message: []const u8) -> unreachable { + // TODO + // if (@atomicRmw(AtomicOp.XChg, &panicking, true, AtomicOrder.SeqCst)) { } + if (panicking) { + // Panicked during a panic. + // TODO detect if a different thread caused the panic, because in that case + // we would want to return here instead of calling abort, so that the thread + // which first called panic can finish printing a stack trace. + os.abort(); + } else { + panicking = true; + } + + %%io.stderr.printf("{}\n", message); + %%printStackTrace(); + + os.abort(); +} + pub fn printStackTrace() -> %void { %return writeStackTrace(&io.stderr); %return io.stderr.flush(); |
