aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-16 16:17:52 -0500
committerGitHub <noreply@github.com>2019-12-16 16:17:52 -0500
commit13cdc137e6389af83f225ab851bf8ef768ebcc69 (patch)
tree34675041bfef45efd3c294f7df9fb244674c6dbf /lib/std/debug.zig
parentde0d8885b4623dab14c379fc844ae0b18d9f8405 (diff)
parent839b3a61ad51b385ac28a0123b6cc63d90ef83f8 (diff)
downloadzig-13cdc137e6389af83f225ab851bf8ef768ebcc69.tar.gz
zig-13cdc137e6389af83f225ab851bf8ef768ebcc69.zip
Merge pull request #3570 from ziglang/c-sanitize-undef
use -fsanitize=undefined for C code in safe build modes
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 69b9e894bb..9b24e1acd3 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -2404,6 +2404,7 @@ pub fn attachSegfaultHandler() void {
};
os.sigaction(os.SIGSEGV, &act, null);
+ os.sigaction(os.SIGILL, &act, null);
}
fn resetSegfaultHandler() void {
@@ -2420,6 +2421,7 @@ fn resetSegfaultHandler() void {
.flags = 0,
};
os.sigaction(os.SIGSEGV, &act, null);
+ os.sigaction(os.SIGILL, &act, null);
}
extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) noreturn {
@@ -2429,8 +2431,11 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
resetSegfaultHandler();
const addr = @ptrToInt(info.fields.sigfault.addr);
- std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr});
-
+ switch (sig) {
+ os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}),
+ os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}),
+ else => unreachable,
+ }
switch (builtin.arch) {
.i386 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));