diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2022-01-17 17:46:48 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-18 15:10:49 -0500 |
| commit | 305a7def136580e7a05652a95c1d2ff338541607 (patch) | |
| tree | 56018e77d507252d36a393d6fbe81abd55751a48 /lib/std/debug.zig | |
| parent | f423b5949b8722d4b290f57c3d06d015e39217b0 (diff) | |
| download | zig-305a7def136580e7a05652a95c1d2ff338541607.tar.gz zig-305a7def136580e7a05652a95c1d2ff338541607.zip | |
Implement segfault handler for macOS x86_64
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 6c09b71451..517176c900 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1574,6 +1574,7 @@ fn getDebugInfoAllocator() mem.Allocator { /// Whether or not the current target can print useful debug information when a segfault occurs. pub const have_segfault_handling_support = switch (native_os) { .linux, .netbsd, .solaris => true, + .macos => native_arch == .x86_64, .windows => true, .freebsd, .openbsd => @hasDecl(os.system, "ucontext_t"), else => false, @@ -1601,7 +1602,7 @@ pub fn attachSegfaultHandler() void { return; } var act = os.Sigaction{ - .handler = .{ .sigaction = handleSegfaultLinux }, + .handler = .{ .sigaction = handleSegfaultPosix }, .mask = os.empty_sigset, .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND), }; @@ -1629,7 +1630,7 @@ fn resetSegfaultHandler() void { os.sigaction(os.SIG.BUS, &act, null); } -fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn { +fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn { // Reset to the default handler so that if a segfault happens in this handler it will crash // the process. Also when this handler returns, the original instruction will be repeated // and the resulting segfault will crash the process rather than continually dump stack traces. @@ -1637,7 +1638,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any const addr = switch (native_os) { .linux => @ptrToInt(info.fields.sigfault.addr), - .freebsd => @ptrToInt(info.addr), + .freebsd, .macos => @ptrToInt(info.addr), .netbsd => @ptrToInt(info.info.reason.fault.addr), .openbsd => @ptrToInt(info.data.fault.addr), .solaris => @ptrToInt(info.reason.fault.addr), @@ -1668,12 +1669,14 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]), .freebsd => @intCast(usize, ctx.mcontext.rip), .openbsd => @intCast(usize, ctx.sc_rip), + .macos => @intCast(usize, ctx.mcontext.ss.rip), else => unreachable, }; const bp = switch (native_os) { .linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]), .openbsd => @intCast(usize, ctx.sc_rbp), .freebsd => @intCast(usize, ctx.mcontext.rbp), + .macos => @intCast(usize, ctx.mcontext.ss.rbp), else => unreachable, }; dumpStackTraceFromBase(bp, ip); |
