medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 44d94742e1af707dddc6b14204140c1bbca07995
parent 81ae2096832cc28783764e26f6b95a052d43b067
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Oct 13 23:53:12 +0300

Autogdb improvements

- Pass -q to gdb
- Exit when gdb exits
- Read the newline from stdin too
- Prompt to debug on SIGINT

Diffstat:
autogdb.h | 31+++++++++++++++++++++----------
main.cc | 2+-
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/autogdb.h b/autogdb.h @@ -10,37 +10,48 @@ #include <unistd.h> #include <err.h> +static void uninstall_debug_signal_handlers() { + signal( SIGINT, SIG_DFL ); + signal( SIGILL, SIG_DFL ); + signal( SIGABRT, SIG_DFL ); + signal( SIGSEGV, SIG_DFL ); +} + static void prompt_to_run_gdb( int signal ) { const char * signal_names[ NSIG ]; - signal_names[ SIGABRT ] = "SIGABRT"; + signal_names[ SIGINT ] = "SIGINT"; signal_names[ SIGILL ] = "SIGILL"; + signal_names[ SIGABRT ] = "SIGABRT"; signal_names[ SIGSEGV ] = "SIGSEGV"; char crashed_pid[ 16 ]; snprintf( crashed_pid, sizeof( crashed_pid ), "%d", getpid() ); printf( "PID %s received %s. Debug? (y/n)\n", crashed_pid, signal_names[ signal ] ); - char c; - read( STDIN_FILENO, &c, 1 ); - if( c != 'y' ) exit( 1 ); + char buf[ 2 ]; + read( STDIN_FILENO, &buf, sizeof( buf ) ); + if( buf[ 0 ] != 'y' ) exit( 1 ); // fork off and run gdb pid_t child_pid = fork(); if( child_pid == -1 ) err( 1, "fork" ); if( child_pid == 0 ) { - execlp( "gdbx", "gdbx", "--", "-p", crashed_pid, ( char * ) 0 ); - execlp( "gdb", "gdb", "-p", crashed_pid, ( char * ) 0 ); + execlp( "gdbx", "gdbx", "--", "-q", "-p", crashed_pid, ( char * ) 0 ); + execlp( "gdb", "gdb", "-q", "-p", crashed_pid, ( char * ) 0 ); err( 1, "execlp" ); } - // pause the parent while we wait for gdb to attach - pause(); + waitpid( child_pid, NULL, 0 ); + exit( 1 ); } -static void install_debug_signal_handlers() { - signal( SIGABRT, prompt_to_run_gdb ); +static void install_debug_signal_handlers( bool debug_on_sigint ) { + if( debug_on_sigint ) { + signal( SIGINT, prompt_to_run_gdb ); + } signal( SIGILL, prompt_to_run_gdb ); + signal( SIGABRT, prompt_to_run_gdb ); signal( SIGSEGV, prompt_to_run_gdb ); } diff --git a/main.cc b/main.cc @@ -79,7 +79,7 @@ static bool should_reload_game( const char * const path, const time_t lib_write_ int main( int argc, char ** argv ) { #if PLATFORM_LINUX - install_debug_signal_handlers(); + install_debug_signal_handlers( true ); #endif const char * game_library_path = argc == 2 ? argv[ 1 ] : "./hm.so";