- Notifications
You must be signed in to change notification settings - Fork2
Catch C/C++ program errors and print a stack trace before exiting
License
dermojo/ooopsi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This library installs C/C++ and OS hooks and handlers for events that would crash your program.Instead of silently printing a message before terminating or sending a bug report to your OS vendor,it allows to log a backtrace of the program's current stack and the reason why it terminates.
libooopsi currently catches:
- unhandled C++ exceptions (leading to
std::terminate
) - segmentation faults
- stack overflows
- illegal instructions
- floating-point errors (e.g. division by zero)
std::abort
- ...
By default, the stack trace is logged to STDERR. To override this behavior, useooopsi::setAbortLogFunc()
in your program to set a custom logging function. This function willbe called line-wise for every line in the stack trace, followed by a call with anullptr
argument to indicate the end (to allow flushing etc.).
Please be aware that the log function will potentially be called from a signal handler, whichshould do only very restrictive things. Make sure to read up onman signal-safety
(for Linux)before customizing log function.
The library needs a C++11 compiler and supports Linux and Windows, both in 64 bit only.
To build the library, you needlibunwind-dev
on Linux andimagehlp
on Windows as wellas CMake. The unit tests require GoogleTest, which is used as a git submodule.
It's sufficient to simply link the shared library against your program. No adaptations arerequired. On Linux, it's also possible to useLD_PRELOAD
to "inject" the library withouthaving to modify the program at all.
It's an acronym for:
- Out
- Of
- Options
- Stack
- Information
Because that's all we can do then ;-)
This project is licensed under the MIT License - see theLICENSE file for details.
tl;dr: Feel free to use and modify the code or to include it in your commercial application.