diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-10-01 15:57:38 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-10-01 13:58:58 -0400 |
| commit | 17f2af10b56dd508ebd4a22834fd594cb5a49864 (patch) | |
| tree | 38da45089fee93cf06ff7753eae768c922b5fdab /lib/std/debug.zig | |
| parent | bed4bfa69ad57595e4595caa96653d9241a8dc2e (diff) | |
| download | zig-17f2af10b56dd508ebd4a22834fd594cb5a49864.tar.gz zig-17f2af10b56dd508ebd4a22834fd594cb5a49864.zip | |
Correct signal bits for MIPS
Also enable the segfault handler for all the supported architectures
beside MIPS.
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 52f33660fb..25868d67a1 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -2336,7 +2336,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 = (builtin.arch == builtin.Arch.x86_64 and builtin.os == .linux) or builtin.os == .windows; +pub const have_segfault_handling_support = builtin.os == .linux or builtin.os == .windows; pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) root.enable_segfault_handler else @@ -2390,12 +2390,31 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con // and the resulting segfault will crash the process rather than continually dump stack traces. resetSegfaultHandler(); - 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 addr = @ptrToInt(info.fields.sigfault.addr); std.debug.warn("Segmentation fault at address 0x{x}\n", addr); - dumpStackTraceFromBase(bp, ip); + + switch (builtin.arch) { + .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]); + dumpStackTraceFromBase(bp, ip); + }, + .arm => { + const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); + const ip = @intCast(usize, ctx.mcontext.arm_pc); + const bp = @intCast(usize, ctx.mcontext.arm_fp); + dumpStackTraceFromBase(bp, ip); + }, + .aarch64 => { + const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); + const ip = @intCast(usize, ctx.mcontext.pc); + // x29 is the ABI-designated frame pointer + const bp = @intCast(usize, ctx.mcontext.regs[29]); + dumpStackTraceFromBase(bp, ip); + }, + else => {}, + } // We cannot allow the signal handler to return because when it runs the original instruction // again, the memory may be mapped and undefined behavior would occur rather than repeating |
