aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-15 00:43:48 +0300
committerAndrew Kelley <andrew@ziglang.org>2022-09-20 19:05:00 -0700
commit694fab484805088030fa36efe3e6b6e7ee385852 (patch)
tree451290910b16372dfdad4336efbc0124248582d7 /lib/std
parent8f2e82dbf63aedc64af5c701c4798e9fbd51de72 (diff)
downloadzig-694fab484805088030fa36efe3e6b6e7ee385852.tar.gz
zig-694fab484805088030fa36efe3e6b6e7ee385852.zip
std: add return address parameter to panic fn
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/builtin.zig12
-rw-r--r--lib/std/debug.zig5
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index d65e12988d..aff47ac6ba 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -748,7 +748,7 @@ const testFnProto = switch (builtin.zig_backend) {
/// This function type is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
-pub const PanicFn = fn ([]const u8, ?*StackTrace) noreturn;
+pub const PanicFn = fn ([]const u8, ?*StackTrace, ?usize) noreturn;
/// This function is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
@@ -761,7 +761,7 @@ else
/// This function is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
-pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn {
+pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn {
@setCold(true);
// Until self-hosted catches up with stage1 language features, we have a simpler
@@ -839,7 +839,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
std.os.abort();
},
else => {
- const first_trace_addr = @returnAddress();
+ const first_trace_addr = ret_addr orelse @returnAddress();
std.debug.panicImpl(error_return_trace, first_trace_addr, msg);
},
}
@@ -853,17 +853,17 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void
pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn {
@setCold(true);
- std.debug.panic("sentinel mismatch: expected {any}, found {any}", .{ expected, actual });
+ std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual });
}
pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
@setCold(true);
- std.debug.panicExtra(st, "attempt to unwrap error: {s}", .{@errorName(err)});
+ std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)});
}
pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
@setCold(true);
- std.debug.panic("index out of bounds: index {d}, len {d}", .{ index, len });
+ std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len });
}
pub noinline fn returnError(st: *StackTrace) void {
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index a7f0b202cb..cfe646647b 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -284,13 +284,14 @@ pub fn assert(ok: bool) void {
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
@setCold(true);
- panicExtra(null, format, args);
+ panicExtra(null, null, format, args);
}
/// `panicExtra` is useful when you want to print out an `@errorReturnTrace`
/// and also print out some values.
pub fn panicExtra(
trace: ?*std.builtin.StackTrace,
+ ret_addr: ?usize,
comptime format: []const u8,
args: anytype,
) noreturn {
@@ -308,7 +309,7 @@ pub fn panicExtra(
break :blk &buf;
},
};
- std.builtin.panic(msg, trace);
+ std.builtin.panic(msg, trace, ret_addr);
}
/// Non-zero whenever the program triggered a panic.