Add backtrace after segfault.
This commit is contained in:
parent
d1d8c91f14
commit
804f01b162
17
main.cpp
17
main.cpp
@ -8,7 +8,24 @@
|
||||
#include <log4cpp/OstreamAppender.hh>
|
||||
#include <log4cpp/PatternLayout.hh>
|
||||
|
||||
#include <execinfo.h>
|
||||
|
||||
/*
|
||||
* Code from http://stackoverflow.com/a/77336/5419223
|
||||
*/
|
||||
static void sigsegv_handler(int sig) {
|
||||
constexpr int STACK_DEPTH = 10;
|
||||
void *array[STACK_DEPTH];
|
||||
|
||||
size_t size = backtrace(array, STACK_DEPTH);
|
||||
|
||||
fprintf(stderr, "ERROR: signal %d:\n", sig);
|
||||
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
signal(SIGSEGV, sigsegv_handler);
|
||||
|
||||
log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &std::cout);
|
||||
log4cpp::PatternLayout layout;
|
||||
|
Loading…
Reference in New Issue
Block a user