2015-09-29 22:43:55 +02:00
|
|
|
#include "backtrace.h"
|
|
|
|
#include <execinfo.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-09-29 22:52:06 +02:00
|
|
|
//TODO Use the following? https://github.com/bombela/backward-cpp
|
|
|
|
|
2015-09-29 22:43:55 +02:00
|
|
|
namespace cpputils {
|
|
|
|
|
|
|
|
void sigsegv_handler(int) {
|
2015-10-03 01:23:30 +02:00
|
|
|
constexpr unsigned int MAX_SIZE = 100;
|
|
|
|
void *array[MAX_SIZE];
|
|
|
|
size_t size = backtrace(array, MAX_SIZE);
|
2015-09-29 22:43:55 +02:00
|
|
|
|
|
|
|
std::cerr << "Error: SIGSEGV" << std::endl;
|
|
|
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showBacktraceOnSigSegv() {
|
|
|
|
signal(SIGSEGV, sigsegv_handler);
|
|
|
|
}
|
|
|
|
}
|