Skip to content

Drop-in crash handler for POSIX based systems

License

Notifications You must be signed in to change notification settings

martensi1/airbag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Airbag

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.

Usage

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.

Example

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);
}

Limitations

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

Resources

About

Drop-in crash handler for POSIX based systems

Topics

Resources

License

Stars

Watchers

Forks