diff options
| author | Alex Cameron <ascottcameron@gmail.com> | 2020-12-19 10:21:55 +0000 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2020-12-23 11:02:05 +0200 |
| commit | 60020fd545e508453ee599c9b792ddb6e164b115 (patch) | |
| tree | b947e98852242e6addfb027d9c8d7e5f2ee2f776 /lib/std/debug.zig | |
| parent | d9fe7ea81592e0978166a2fcfb5edb01ee7d48ef (diff) | |
| download | zig-60020fd545e508453ee599c9b792ddb6e164b115.tar.gz zig-60020fd545e508453ee599c9b792ddb6e164b115.zip | |
Enable segfault handling on FreeBSD.
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index be5635ee8f..e93143c598 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1696,6 +1696,7 @@ fn getDebugInfoAllocator() *mem.Allocator { pub const have_segfault_handling_support = switch (builtin.os.tag) { .linux, .netbsd => true, .windows => true, + .freebsd => @hasDecl(os, "ucontext_t"), else => false, }; pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) @@ -1757,6 +1758,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v const addr = switch (builtin.os.tag) { .linux => @ptrToInt(info.fields.sigfault.addr), + .freebsd => @ptrToInt(info.addr), .netbsd => @ptrToInt(info.info.reason.fault.addr), else => unreachable, }; @@ -1781,8 +1783,16 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v }, .x86_64 => { const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); - const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]); - const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]); + const ip = switch (builtin.os.tag) { + .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]), + .freebsd => @intCast(usize, ctx.mcontext.rip), + else => unreachable, + }; + const bp = switch (builtin.os.tag) { + .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]), + .freebsd => @intCast(usize, ctx.mcontext.rbp), + else => unreachable, + }; dumpStackTraceFromBase(bp, ip); }, .arm => { |
