# HG changeset patch # User nkeynes # Date 1194435953 0 # Node ID 4db4702b07785fc7d92232ae989622993ab6bc7d # Parent 67c133a17400ccd0d19f94b4e8424ad78865d4aa Add crash handler to get a backtrace via gdb --- a/src/dream.h Tue Nov 06 12:23:25 2007 +0000 +++ b/src/dream.h Wed Nov 07 11:45:53 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: dream.h,v 1.16 2007-10-31 09:10:23 nkeynes Exp $ + * $Id: dream.h,v 1.17 2007-11-07 11:45:53 nkeynes Exp $ * * Miscellaneous application-wide declarations (mainly logging atm) * @@ -95,6 +95,8 @@ void fwrite_dump32( unsigned int *buf, unsigned int length, FILE *f ); void fwrite_dump32v( unsigned int *buf, unsigned int length, int wordsPerLine, FILE *f ); +void install_crash_handler(void); + gboolean write_png_to_stream( FILE *f, frame_buffer_t ); frame_buffer_t read_png_from_stream( FILE *f ); --- a/src/main.c Tue Nov 06 12:23:25 2007 +0000 +++ b/src/main.c Wed Nov 07 11:45:53 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: main.c,v 1.34 2007-10-31 11:53:35 nkeynes Exp $ + * $Id: main.c,v 1.35 2007-11-07 11:45:53 nkeynes Exp $ * * Main program, initializes dreamcast and gui, then passes control off to * the gtk main loop (currently). @@ -64,6 +64,8 @@ { int opt, i; double t; + + install_crash_handler(); #ifdef ENABLE_NLS bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); textdomain (PACKAGE); --- a/src/util.c Tue Nov 06 12:23:25 2007 +0000 +++ b/src/util.c Wed Nov 07 11:45:53 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: util.c,v 1.12 2007-10-31 12:05:23 nkeynes Exp $ + * $Id: util.c,v 1.13 2007-11-07 11:45:53 nkeynes Exp $ * * Miscellaneous utility functions. * @@ -16,11 +16,14 @@ * GNU General Public License for more details. */ +#define HAVE_EXECINFO_H 1 + #include #include #include #include #include +#include #include #include #include @@ -31,7 +34,30 @@ #include "sh4/sh4core.h" char *msg_levels[] = { "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" }; -int global_msg_level = EMIT_WARN; +int global_msg_level = EMIT_INFO; + +static void report_crash( int signo, siginfo_t *info, void *ptr ) +{ + char buf[128]; + + fprintf( stderr, "--- Aborting with signal %d ---\n", signo ); + // Get gdb to print a nice backtrace for us + snprintf( buf, 128, "gdb -batch -f --quiet --pid=%d -ex bt", getpid() ); + system(buf); + + abort(); +} + +void install_crash_handler(void) +{ + struct sigaction sa; + + sa.sa_sigaction = report_crash; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESETHAND|SA_SIGINFO; + sigaction( SIGSEGV, &sa, NULL ); +} + void fwrite_string( const char *s, FILE *f ) {