From e7943393b9d3516fdfaf363bbe8a2a31d1f4138e Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 9 Jan 2006 02:10:14 +0000 Subject: [PATCH] Cleanup --- .../src/archutils/Unix/CrashHandlerChild.cpp | 219 +++++++++--------- 1 file changed, 112 insertions(+), 107 deletions(-) diff --git a/stepmania/src/archutils/Unix/CrashHandlerChild.cpp b/stepmania/src/archutils/Unix/CrashHandlerChild.cpp index 1aee0d3c9b..9436b6383b 100644 --- a/stepmania/src/archutils/Unix/CrashHandlerChild.cpp +++ b/stepmania/src/archutils/Unix/CrashHandlerChild.cpp @@ -34,26 +34,26 @@ static void output_stack_trace( FILE *out, const void **BacktracePointers ) fprintf( out, "No backtrace method available.\n"); return; } - + if( !BacktracePointers[0] ) { fprintf( out, "Backtrace was empty.\n"); return; } - + for( int i = 0; BacktracePointers[i]; ++i) { BacktraceNames bn; bn.FromAddr( BacktracePointers[i] ); bn.Demangle(); - - /* Don't show the main module name. */ + + /* Don't show the main module name. */ if( bn.File == g_pCrashHandlerArgv0 ) bn.File = ""; - + if( bn.Symbol == "__libc_start_main" ) break; - + fprintf( out, "%s\n", bn.Format().c_str() ); } } @@ -71,7 +71,7 @@ const char *SignalCodeName( int signo, int code ) case SI_ASYNCIO: return "async I/O completed"; case SI_SIGIO: return "queued SIGIO"; } - + switch( signo ) { case SIGILL: @@ -87,7 +87,7 @@ const char *SignalCodeName( int signo, int code ) case ILL_BADSTK: return "internal stack error"; } break; - + case SIGFPE: switch( code ) { @@ -101,7 +101,7 @@ const char *SignalCodeName( int signo, int code ) case FPE_FLTSUB: return "subscript out of range"; } break; - + case SIGSEGV: switch( code ) { @@ -109,8 +109,8 @@ const char *SignalCodeName( int signo, int code ) case SEGV_ACCERR: return "invalid permissions"; } break; - - case SIGBUS: + + case SIGBUS: switch( code ) { case BUS_ADRALN: return "invalid address alignment"; @@ -118,7 +118,7 @@ const char *SignalCodeName( int signo, int code ) case BUS_OBJERR: return "object specific hardware error"; } break; - + case SIGTRAP: switch( code ) { @@ -126,7 +126,7 @@ const char *SignalCodeName( int signo, int code ) case TRAP_TRACE: return "process trace trap"; } break; - + case SIGCHLD: switch( code ) { @@ -138,7 +138,7 @@ const char *SignalCodeName( int signo, int code ) case CLD_CONTINUED: return "stopped child has continued"; } break; - + case SIGPOLL: switch( code ) { @@ -151,7 +151,7 @@ const char *SignalCodeName( int signo, int code ) } break; } - + static char buf[128]; sprintf( buf, "Unknown code %i", code ); return buf; @@ -172,16 +172,16 @@ bool child_read( int fd, void *p, int size ) fprintf( stderr, "Crash handler: error communicating with parent: %s\n", strerror(errno) ); return false; } - + if( ret == 0 ) { - fprintf( stderr, "Crash handler: EOF communicating with parent.\n"); + fprintf( stderr, "Crash handler: EOF communicating with parent.\n" ); return false; } - + got += ret; } - + return true; } @@ -192,176 +192,181 @@ static void child_process() /* 1. Read the CrashData. */ CrashData crash; if( !child_read(3, &crash, sizeof(CrashData)) ) - return; - + return; + /* 2. Read info. */ int size; if( !child_read(3, &size, sizeof(size)) ) - return; + return; char *Info = new char [size]; if( !child_read(3, Info, size) ) - return; - + return; + /* 3. Read AdditionalLog. */ if( !child_read(3, &size, sizeof(size)) ) - return; - + return; + char *AdditionalLog = new char [size]; if( !child_read(3, AdditionalLog, size) ) - return; - + return; + /* 4. Read RecentLogs. */ int cnt = 0; if( !child_read(3, &cnt, sizeof(cnt)) ) - return; + return; char *Recent[1024]; for( int i = 0; i < cnt; ++i ) { if( !child_read(3, &size, sizeof(size)) ) - return; + return; Recent[i] = new char [size]; if( !child_read(3, Recent[i], size) ) - return; + return; } - + /* 5. Read CHECKPOINTs. */ if( !child_read(3, &size, sizeof(size)) ) - return; - + return; + char *temp = new char [size]; if( !child_read(3, temp, size) ) - return; - + return; + vector Checkpoints; split(temp, "$$", Checkpoints); delete [] temp; - + /* 6. Read the crashed thread's name. */ if( !child_read(3, &size, sizeof(size)) ) - return; + return; temp = new char [size]; if( !child_read(3, temp, size) ) - return; + return; const CString CrashedThread(temp); delete[] temp; - + /* Wait for the child to either finish cleaning up or die. XXX: * This should time out, in case something deadlocks. */ - + char x; - int ret = read(3, &x, sizeof(x)); + int ret = read( 3, &x, sizeof(x) ); if( ret > 0 ) { fprintf( stderr, "Unexpected child read() result: %i\n", ret ); /* keep going */ - } else if( (ret == -1 && errno != EPIPE) || ret != 0 ) + } + else if( (ret == -1 && errno != EPIPE) || ret != 0 ) { /* We expect an EOF or EPIPE. What happened? */ - fprintf(stderr, "Unexpected child read() result: %i (%s)\n", ret, strerror(errno)); + fprintf( stderr, "Unexpected child read() result: %i (%s)\n", ret, strerror(errno) ); /* keep going */ } - + const char *home = getenv( "HOME" ); CString sCrashInfoPath = "/tmp"; if( home ) sCrashInfoPath = home; sCrashInfoPath += "/crashinfo.txt"; - + FILE *CrashDump = fopen( sCrashInfoPath, "w+" ); if(CrashDump == NULL) { fprintf( stderr, "Couldn't open " + sCrashInfoPath + ": %s\n", strerror(errno) ); exit(1); } - - fprintf(CrashDump, "%s crash report", PRODUCT_NAME_VER ); + + fprintf( CrashDump, "%s crash report", PRODUCT_NAME_VER ); #if defined(HAVE_VERSION_INFO) - fprintf(CrashDump, " (build %u)", version_num); + fprintf( CrashDump, " (build %u)", version_num); #endif - fprintf(CrashDump, "\n"); - fprintf(CrashDump, "--------------------------------------\n"); - fprintf(CrashDump, "\n"); - + fprintf( CrashDump, "\n" ); + fprintf( CrashDump, "--------------------------------------\n" ); + fprintf( CrashDump, "\n" ); + CString reason; switch( crash.type ) { - case CrashData::SIGNAL: - { - CString Signal = SignalName( crash.signal ); - -#if !defined(MACOSX) - reason = ssprintf( "%s - %s", Signal.c_str(), SignalCodeName(crash.signal, crash.si.si_code) ); -#else - reason = Signal; -#endif - /* Linux puts the PID that sent the signal in si_addr for SI_USER. */ - if( crash.si.si_code == SI_USER ) - reason += ssprintf( " from pid %li", (long) crash.si.si_addr ); - else switch( crash.signal ) + case CrashData::SIGNAL: { - case SIGILL: - case SIGFPE: - case SIGSEGV: - case SIGBUS: - reason += ssprintf( " at 0x%0*lx", int(sizeof(void*)*2), (unsigned long) crash.si.si_addr ); + CString Signal = SignalName( crash.signal ); + +#if !defined(MACOSX) + reason = ssprintf( "%s - %s", Signal.c_str(), SignalCodeName(crash.signal, crash.si.si_code) ); +#else + reason = Signal; +#endif + /* Linux puts the PID that sent the signal in si_addr for SI_USER. */ + if( crash.si.si_code == SI_USER ) + { + reason += ssprintf( " from pid %li", (long) crash.si.si_addr ); + } + else + { + switch( crash.signal ) + { + case SIGILL: + case SIGFPE: + case SIGSEGV: + case SIGBUS: + reason += ssprintf( " at 0x%0*lx", int(sizeof(void*)*2), (unsigned long) crash.si.si_addr ); + } + break; + } } - break; + case CrashData::FORCE_CRASH: + crash.reason[ sizeof(crash.reason)-1] = 0; + reason = crash.reason; + break; } - case CrashData::FORCE_CRASH: - crash.reason[ sizeof(crash.reason)-1] = 0; - reason = crash.reason; - break; - } - + fprintf( CrashDump, "Crash reason: %s\n", reason.c_str() ); fprintf( CrashDump, "Crashed thread: %s\n\n", CrashedThread.c_str() ); - + fprintf(CrashDump, "Checkpoints:\n"); - for (unsigned i=0; i