Search
lxdream.org :: lxdream/src/util.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/util.c
changeset 495:4db4702b0778
prev481:3b2d6c5a19ad
next502:c4ecae2b1b5e
author nkeynes
date Wed Nov 07 11:45:53 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add crash handler to get a backtrace via gdb
file annotate diff log raw
1.1 --- a/src/util.c Wed Oct 31 12:05:23 2007 +0000
1.2 +++ b/src/util.c Wed Nov 07 11:45:53 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: util.c,v 1.12 2007-10-31 12:05:23 nkeynes Exp $
1.6 + * $Id: util.c,v 1.13 2007-11-07 11:45:53 nkeynes Exp $
1.7 *
1.8 * Miscellaneous utility functions.
1.9 *
1.10 @@ -16,11 +16,14 @@
1.11 * GNU General Public License for more details.
1.12 */
1.13
1.14 +#define HAVE_EXECINFO_H 1
1.15 +
1.16 #include <assert.h>
1.17 #include <ctype.h>
1.18 #include <stdarg.h>
1.19 #include <stdio.h>
1.20 #include <stdlib.h>
1.21 +#include <signal.h>
1.22 #include <time.h>
1.23 #include <zlib.h>
1.24 #include <glib.h>
1.25 @@ -31,7 +34,30 @@
1.26 #include "sh4/sh4core.h"
1.27
1.28 char *msg_levels[] = { "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" };
1.29 -int global_msg_level = EMIT_WARN;
1.30 +int global_msg_level = EMIT_INFO;
1.31 +
1.32 +static void report_crash( int signo, siginfo_t *info, void *ptr )
1.33 +{
1.34 + char buf[128];
1.35 +
1.36 + fprintf( stderr, "--- Aborting with signal %d ---\n", signo );
1.37 + // Get gdb to print a nice backtrace for us
1.38 + snprintf( buf, 128, "gdb -batch -f --quiet --pid=%d -ex bt", getpid() );
1.39 + system(buf);
1.40 +
1.41 + abort();
1.42 +}
1.43 +
1.44 +void install_crash_handler(void)
1.45 +{
1.46 + struct sigaction sa;
1.47 +
1.48 + sa.sa_sigaction = report_crash;
1.49 + sigemptyset(&sa.sa_mask);
1.50 + sa.sa_flags = SA_RESETHAND|SA_SIGINFO;
1.51 + sigaction( SIGSEGV, &sa, NULL );
1.52 +}
1.53 +
1.54
1.55 void fwrite_string( const char *s, FILE *f )
1.56 {
.