Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

attachSegfaultHandler

Public Function
std.debug.attachSegfaultHandler
pub fn attachSegfaultHandler() void

Attaches a global handler for several signals which, when triggered, prints output to stderr similar to the default panic handler, with a message containing the type of signal and a stack trace if possible. This implementation does not just call the panic handler, because unwinding the stack (for a stack trace) when a signal is received requires special target-specific logic.

On POSIX targets, the signal handler is configured to use the alternative signal stack. Such a stack is configured by the Zig Standard Library if std.options.signal_stack_size is set.

The signals for which a handler is installed are:

  • SIGSEGV (segmentation fault)
  • SIGILL (illegal instruction)
  • SIGBUS (bus error)
  • SIGFPE (arithmetic exception)

File

debug.zig:1570
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
pub fn attachSegfaultHandler() void {
    if (!have_segfault_handling_support) {
        @compileError("segfault handler not supported for this target");
    }
    if (native_os == .windows) {
        windows_segfault_handle = windows.ntdll.RtlAddVectoredExceptionHandler(0, handleSegfaultWindows);
        return;
    }
    const act: posix.Sigaction = .{
        .handler = .{ .sigaction = handleSegfaultPosix },
        .mask = posix.sigemptyset(),
        .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND | posix.SA.ONSTACK),
    };
    updateSegfaultHandler(&act);
}