Just playground. Do not use in production!
Library for extracting stacktrace from exception.
$ # depends on `libboost-stacktrace-dev`
$ git clone [email protected]:axolm/libsfe.git
$ cd libsfe
$ make build-release
$ sudo make install
basic.cpp file
#include <iostream>
#include <sfe/sfe.hpp>
#include <stdexcept>
void throw_something() {
throw std::runtime_error("SOME ERROR");
}
int main() {
try {
throw_something();
} catch (const std::exception& exc) {
auto trace = sfe::get_current_exception_stacktrace();
std::cerr << "Caught exception. Err: `" << exc.what() << "`, Trace:\n"
<< trace;
}
return 0;
}
Compiling and runing
$ g++ -g -DBOOST_STACKTRACE_DYN_LINK basic.cpp -obasic -lsfe_basic -lboost_stacktrace_backtrace
$ ./basic
Caught exception. Err: `SOME ERROR`, Trace:
# Debug info without recompiling!
$ LD_PRELOAD=/usr/local/lib/libsfe_preload.so ./basic
Caught exception. Err: `SOME ERROR`, Trace:
0# throw_something() at /home/axolm/basic.cpp:6
1# main at /home/axolm/basic.cpp:17
2# 0x00007FB823D77BF7 in /lib/x86_64-linux-gnu/libc.so.6
3# 0x0000558E89A2202A in ./basic
libsfe_basic.so
just returns empty stacktrace fromsfe::get_current_exception_stacktrace()
.libsfe_preload.so
overrides function__cxa_allocate_exception
, dumpsboost::stacktrace
near exception obj and insfe::get_current_exception_stacktrace()
loads it and returns.
- libdl
- boost/stacktrace