| author | |
| committer | |
| log | 60020fd545e508453ee599c9b792ddb6e164b115 |
| tree | b947e98852242e6addfb027d9c8d7e5f2ee2f776 |
| parent | d9fe7ea81592e0978166a2fcfb5edb01ee7d48ef |
2 files changed, 60 insertions(+), 2 deletions(-)
lib/std/debug.zig+12-2| ... | ... | @@ -1696,6 +1696,7 @@ fn getDebugInfoAllocator() *mem.Allocator { |
| 1696 | 1696 | pub const have_segfault_handling_support = switch (builtin.os.tag) { |
| 1697 | 1697 | .linux, .netbsd => true, |
| 1698 | 1698 | .windows => true, |
| 1699 | .freebsd => @hasDecl(os, "ucontext_t"), | |
| 1699 | 1700 | else => false, |
| 1700 | 1701 | }; |
| 1701 | 1702 | 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 |
| 1757 | 1758 | |
| 1758 | 1759 | const addr = switch (builtin.os.tag) { |
| 1759 | 1760 | .linux => @ptrToInt(info.fields.sigfault.addr), |
| 1761 | .freebsd => @ptrToInt(info.addr), | |
| 1760 | 1762 | .netbsd => @ptrToInt(info.info.reason.fault.addr), |
| 1761 | 1763 | else => unreachable, |
| 1762 | 1764 | }; |
| ... | ... | @@ -1781,8 +1783,16 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v |
| 1781 | 1783 | }, |
| 1782 | 1784 | .x86_64 => { |
| 1783 | 1785 | const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); |
| 1784 | const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]); | |
| 1785 | const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]); | |
| 1786 | const ip = switch (builtin.os.tag) { | |
| 1787 | .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]), | |
| 1788 | .freebsd => @intCast(usize, ctx.mcontext.rip), | |
| 1789 | else => unreachable, | |
| 1790 | }; | |
| 1791 | const bp = switch (builtin.os.tag) { | |
| 1792 | .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]), | |
| 1793 | .freebsd => @intCast(usize, ctx.mcontext.rbp), | |
| 1794 | else => unreachable, | |
| 1795 | }; | |
| 1786 | 1796 | dumpStackTraceFromBase(bp, ip); |
| 1787 | 1797 | }, |
| 1788 | 1798 | .arm => { |
lib/std/os/bits/freebsd.zig+48| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const std = @import("../../std.zig"); |
| 7 | const builtin = std.builtin; | |
| 7 | 8 | const maxInt = std.math.maxInt; |
| 8 | 9 | |
| 9 | 10 | // See https://svnweb.freebsd.org/base/head/sys/sys/_types.h?view=co |
| ... | ... | @@ -815,6 +816,53 @@ pub const sigset_t = extern struct { |
| 815 | 816 | |
| 816 | 817 | pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; |
| 817 | 818 | |
| 819 | pub usingnamespace switch (builtin.arch) { | |
| 820 | .x86_64 => struct { | |
| 821 | pub const ucontext_t = extern struct { | |
| 822 | sigmask: sigset_t, | |
| 823 | mcontext: mcontext_t, | |
| 824 | link: ?*ucontext_t, | |
| 825 | stack: stack_t, | |
| 826 | flags: c_int, | |
| 827 | __spare__: [4]c_int, | |
| 828 | }; | |
| 829 | ||
| 830 | /// XXX x86_64 specific | |
| 831 | pub const mcontext_t = extern struct { | |
| 832 | onstack: u64, | |
| 833 | rdi: u64, | |
| 834 | rsi: u64, | |
| 835 | rdx: u64, | |
| 836 | rcx: u64, | |
| 837 | r8: u64, | |
| 838 | r9: u64, | |
| 839 | rax: u64, | |
| 840 | rbx: u64, | |
| 841 | rbp: u64, | |
| 842 | r10: u64, | |
| 843 | r11: u64, | |
| 844 | r12: u64, | |
| 845 | r13: u64, | |
| 846 | r14: u64, | |
| 847 | r15: u64, | |
| 848 | trapno: u32, | |
| 849 | fs: u16, | |
| 850 | gs: u16, | |
| 851 | addr: u64, | |
| 852 | flags: u32, | |
| 853 | es: u16, | |
| 854 | ds: u16, | |
| 855 | err: u64, | |
| 856 | rip: u64, | |
| 857 | cs: u64, | |
| 858 | rflags: u64, | |
| 859 | rsp: u64, | |
| 860 | ss: u64, | |
| 861 | }; | |
| 862 | }, | |
| 863 | else => struct {}, | |
| 864 | }; | |
| 865 | ||
| 818 | 866 | pub const EPERM = 1; // Operation not permitted |
| 819 | 867 | pub const ENOENT = 2; // No such file or directory |
| 820 | 868 | pub const ESRCH = 3; // No such process |