feat: more improvements to panic handling
Follow on panics no longer confuse the panic output and the just in time debugger now works properly on the local tty.
This commit is contained in:
parent
14dce0a10b
commit
e9735d9425
5 changed files with 42 additions and 12 deletions
|
@ -135,15 +135,46 @@ pub fn install_crash_handler() void {
|
|||
std.posix.sigaction(std.posix.SIG.ILL, &act, null);
|
||||
}
|
||||
|
||||
pub var jit_debugger_enabled: bool = false;
|
||||
|
||||
fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {
|
||||
const debug = @import("std/debug.zig");
|
||||
debug.lockStdErr();
|
||||
|
||||
if (panic_in_progress())
|
||||
std.posix.abort();
|
||||
|
||||
in_panic.store(true, .release);
|
||||
const cleanup = panic_cleanup;
|
||||
panic_cleanup = null;
|
||||
|
||||
if (cleanup) |self| {
|
||||
self.vx.deinit(self.allocator, self.tty.anyWriter());
|
||||
self.tty.deinit();
|
||||
}
|
||||
@import("std/debug.zig").handleSegfaultPosix(sig, info, ctx_ptr);
|
||||
if (jit_debugger_enabled) {
|
||||
handleSegfaultPosixNoAbort(sig, info, ctx_ptr);
|
||||
@import("thespian").sighdl_debugger(sig, @ptrCast(@constCast(info)), ctx_ptr);
|
||||
std.posix.abort();
|
||||
} else {
|
||||
debug.handleSegfaultPosix(sig, info, ctx_ptr);
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn handleSegfaultPosixNoAbort(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void {
|
||||
const debug = @import("std/debug.zig");
|
||||
debug.resetSegfaultHandler();
|
||||
const addr = switch (builtin.os.tag) {
|
||||
.linux => @intFromPtr(info.fields.sigfault.addr),
|
||||
.freebsd, .macos => @intFromPtr(info.addr),
|
||||
.netbsd => @intFromPtr(info.info.reason.fault.addr),
|
||||
.openbsd => @intFromPtr(info.data.fault.addr),
|
||||
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),
|
||||
else => unreachable,
|
||||
};
|
||||
const code = if (builtin.os.tag == .netbsd) info.info.code else info.code;
|
||||
debug.dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
|
||||
}
|
||||
|
||||
pub fn run(self: *Self) Error!void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue