Simple drop-in crash handler written in C for POSIX based systems. It allows for capturing crash signals such as segmentation faults, aborts, and other fatal signals, providing a mechanism to log diagnostic information before terminating the program.
Add the airbag.c
and airbag.h
files to your project. Use the airbag_init
function to install the crash handler and the airbag_cleanup
function to remove it.
The following example demonstrates how to use the airbag library to capture crashes and log diagnostic information to a file.
#include "airbag.h"
#include <stdio.h>
int main() {
// Install the crash handler
FILE* file = fopen("airbag.out", "w");
int fd = fileno(file);
airbag_init(fd);
// Your program logic goes here
// ...
// Removes the crash handler
airbag_cleanup();
flose(file);
}
The printed backtrace will not always be reliable/complete if the code has been optimized during compilation. For example:
- Inlined functions will not appear in the backtrace (does not have stack frames)
- Omission of frame pointers may cause the backtrace to be incomplete (which is common in optimized builds)
- Tail-call optimization may cause the backtrace to be incomplete