debug: Show a nice error message on SIGBUS

This commit is contained in:
LemonBoy 2020-02-07 16:06:33 +01:00
parent 786700249e
commit be02616c86

View File

@ -2256,6 +2256,7 @@ pub fn attachSegfaultHandler() void {
os.sigaction(os.SIGSEGV, &act, null); os.sigaction(os.SIGSEGV, &act, null);
os.sigaction(os.SIGILL, &act, null); os.sigaction(os.SIGILL, &act, null);
os.sigaction(os.SIGBUS, &act, null);
} }
fn resetSegfaultHandler() void { fn resetSegfaultHandler() void {
@ -2273,6 +2274,7 @@ fn resetSegfaultHandler() void {
}; };
os.sigaction(os.SIGSEGV, &act, null); os.sigaction(os.SIGSEGV, &act, null);
os.sigaction(os.SIGILL, &act, null); os.sigaction(os.SIGILL, &act, null);
os.sigaction(os.SIGBUS, &act, null);
} }
fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn { fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn {
@ -2285,6 +2287,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_vo
switch (sig) { switch (sig) {
os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}), os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}),
os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}), os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}),
os.SIGBUS => std.debug.warn("Bus error at address 0x{x}\n", .{addr}),
else => unreachable, else => unreachable,
} }
switch (builtin.arch) { switch (builtin.arch) {