aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-21 14:11:16 -0500
committerGitHub <noreply@github.com>2019-12-21 14:11:16 -0500
commitbc95c63cf227226861d7fbf63fa6c779fed8abf8 (patch)
tree1e004f521047ead2fb52855da7bc4fa819020548 /lib/std/debug.zig
parent51cbd968203f348051b8c2bdc005ca5294a79ceb (diff)
parent290dc5d95b986464a5be91bb3fd0ada2dd0840ae (diff)
downloadzig-bc95c63cf227226861d7fbf63fa6c779fed8abf8.tar.gz
zig-bc95c63cf227226861d7fbf63fa6c779fed8abf8.zip
Merge pull request #3940 from ziglang/sentinel-slicing
fix std.mem.addNullByte and implement sentinel slicing
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 9b24e1acd3..76685666ad 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -219,7 +219,7 @@ pub fn panic(comptime format: []const u8, args: var) noreturn {
}
/// TODO multithreaded awareness
-var panicking: u8 = 0; // TODO make this a bool
+var panicking: u8 = 0;
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
@setCold(true);
@@ -230,21 +230,25 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
resetSegfaultHandler();
}
- if (@atomicRmw(u8, &panicking, builtin.AtomicRmwOp.Xchg, 1, builtin.AtomicOrder.SeqCst) == 1) {
- // 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();
- }
- const stderr = getStderrStream();
- stderr.print(format ++ "\n", args) catch os.abort();
- if (trace) |t| {
- dumpStackTrace(t.*);
+ switch (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst)) {
+ 0 => {
+ const stderr = getStderrStream();
+ stderr.print(format ++ "\n", args) catch os.abort();
+ if (trace) |t| {
+ dumpStackTrace(t.*);
+ }
+ dumpCurrentStackTrace(first_trace_addr);
+ },
+ 1 => {
+ // 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.
+ warn("Panicked during a panic. Aborting.\n", .{});
+ },
+ else => {
+ // Panicked while printing "Panicked during a panic."
+ },
}
- dumpCurrentStackTrace(first_trace_addr);
-
os.abort();
}