Cheetah Software  1.0
SegfaultHandler.cpp
Go to the documentation of this file.
1 
6 #include <cstdio>
7 #include <execinfo.h>
8 #include <csignal>
9 #include <cstdlib>
10 #include <unistd.h>
11 #include <cstring>
13 
14 
15 static void segfault_handler(int sig) {
16  void* stack_frames[200];
17  int size = backtrace(stack_frames, 200);
18  fprintf_color(PrintColor::Red, stderr, "CRASH: Caught %d (%s)\n",
19  sig, strsignal(sig));
20  backtrace_symbols_fd(stack_frames, size, STDERR_FILENO);
21  exit(1);
22 }
23 
24 
26  signal(SIGSEGV, segfault_handler);
27 }
void install_segfault_handler()
static void segfault_handler(int sig)
void fprintf_color(PrintColor color, FILE *stream, const char *fmt,...)