Drop-in crash handlers for POSIX, particularly embedded Linux.
Copyright 2011-2014 Chuck Coffing email@example.com, MIT licensed
Dumps registers, backtrace, and instruction stream to a file descriptor. Intended to be self-contained and resilient. Where possible, will detect and intelligently handle corrupt state, such as jumping through a bad pointer or a blown stack. The harvesting and reporting of the crash log is left as an exercise for the reader.
airbag_fd.hin your project.
- If it doesn't build, define the appropriate
- Call one of the
airbag_init_*functions early, to accept crash data via a file descriptor.
- Post-crash (perhaps in a watchdog or on next startup) harvest crash logs.
All of airbag_fd's crash-gathering work is intended to be async-signal safe. In fact, the fundamental design is influenced by the fact that writing to file descriptors is async-signal safe, but many higher-level functions are not. (See http://man7.org/linux/man-pages/man7/signal.7.html.)
One common design may be to exec a watchdog process early, which opens a
crash-handling file descriptor and then fork/execs the main child process,
passing the listening file descriptor to the child process, which then calls
airbag_init_fd with that file descriptor. Even if the child crashes
horribly, the watchdog can gather the crash, report it, and possibly re-exec
airbag_fd is intended to compile cleanly under various C and C++ standards and compilers. Tested semi-regularly on combinations of:
- x86 Linux
- x64 Linux
- ARM Linux
Rarely tested on:
- MIPS Linux
Help welcome anywhere.
Currently no heuristics for trashed stack (x86_64 ABI encourages not saving FP).
Optionally build your application with
-mpoke-function-name for more readable