debug: implement segfault handler for macOS aarch64
Tested on a M1 MacBook Pro, macOS Monterey 12.2.
This commit is contained in:
committed by
Andrew Kelley
parent
8e10c80c5f
commit
fbde43524f
@@ -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 => {},
|
||||
|
||||
Reference in New Issue
Block a user