debug: implement segfault handler for macOS aarch64

Tested on a M1 MacBook Pro, macOS Monterey 12.2.
This commit is contained in:
John Schmidt
2022-02-07 18:20:33 +01:00
committed by Andrew Kelley
parent 8e10c80c5f
commit fbde43524f
4 changed files with 83 additions and 50 deletions

View File

@@ -1601,9 +1601,13 @@ 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,
.linux,
.macos,
.netbsd,
.solaris,
.windows,
=> true,
.freebsd, .openbsd => @hasDecl(os.system, "ucontext_t"),
else => false,
};
@@ -1717,9 +1721,15 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
},
.aarch64 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = @intCast(usize, ctx.mcontext.pc);
const ip = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.pc),
else => @intCast(usize, ctx.mcontext.pc),
};
// x29 is the ABI-designated frame pointer
const bp = @intCast(usize, ctx.mcontext.regs[29]);
const bp = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.fp),
else => @intCast(usize, ctx.mcontext.regs[29]),
};
dumpStackTraceFromBase(bp, ip);
},
else => {},