Created
June 14, 2011 22:06
-
-
Save Nadrin/1026045 to your computer and use it in GitHub Desktop.
Capturing SIGSEGV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#include <execinfo.h> | |
static void sig_debug(int sig) | |
{ | |
FILE* file; | |
char filename[256]; | |
void* bt[200]; | |
int bt_size, i; | |
char** bt_symbols; | |
fprintf(stderr, "Segmentation fault\n"); | |
fflush(stderr); | |
bt_size = backtrace(bt, 200); | |
file = fopen("backtrace.log", "w"); | |
if(!file) exit(255); | |
bt_symbols = backtrace_symbols(bt, bt_size); | |
for(i=0; i<bt_size; i++) { | |
fprintf(file, "%s\n", bt_symbols[i]); | |
} | |
fclose(file); | |
free(bt_symbols); | |
exit(255); | |
} | |
int main(int argc, char** argv) | |
{ | |
signal(SIGSEGV, sig_debug); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment