From d06261ccac56987f57258b679bb1db2ced1ec41f Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 22 May 2010 12:56:46 +0200 Subject: added sigsegv handler with backtrace --- main.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 36133bcf..50644574 100644 --- a/main.c +++ b/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H # include #endif @@ -427,10 +428,39 @@ sigterm_handler (int sig) { exit (0); } +void +sigsegv_handler (int sig) { + fprintf (stderr, "Segmentation Fault\n"); + int j, nptrs; +#define SIZE 100 + void *buffer[100]; + char **strings; + + nptrs = backtrace(buffer, SIZE); + printf("backtrace() returned %d addresses\n", nptrs); + + /* The call + * backtrace_symbols_fd(buffer, + * nptrs, + * STDOUT_FILENO) + would produce similar output to the following: */ + + strings = backtrace_symbols(buffer, nptrs); + if (strings == NULL) { + perror("backtrace_symbols"); + exit(EXIT_FAILURE); + } + + for (j = 0; j < nptrs; j++) + printf("%s\n", strings[j]); + + free(strings); + exit (0); +} + int main (int argc, char *argv[]) { - //u8_lc_map_test (); - //return -1; + signal (SIGSEGV, sigsegv_handler); setlocale (LC_ALL, ""); setlocale (LC_NUMERIC, "C"); fprintf (stderr, "starting deadbeef " VERSION "\n"); -- cgit v1.2.3