This commit is contained in:
Steve Checkoway
2006-01-09 02:10:14 +00:00
parent 7858052c43
commit e7943393b9
@@ -47,7 +47,7 @@ static void output_stack_trace( FILE *out, const void **BacktracePointers )
bn.FromAddr( BacktracePointers[i] ); bn.FromAddr( BacktracePointers[i] );
bn.Demangle(); bn.Demangle();
/* Don't show the main module name. */ /* Don't show the main module name. */
if( bn.File == g_pCrashHandlerArgv0 ) if( bn.File == g_pCrashHandlerArgv0 )
bn.File = ""; bn.File = "";
@@ -110,7 +110,7 @@ const char *SignalCodeName( int signo, int code )
} }
break; break;
case SIGBUS: case SIGBUS:
switch( code ) switch( code )
{ {
case BUS_ADRALN: return "invalid address alignment"; case BUS_ADRALN: return "invalid address alignment";
@@ -175,7 +175,7 @@ bool child_read( int fd, void *p, int size )
if( ret == 0 ) if( ret == 0 )
{ {
fprintf( stderr, "Crash handler: EOF communicating with parent.\n"); fprintf( stderr, "Crash handler: EOF communicating with parent.\n" );
return false; return false;
} }
@@ -192,45 +192,45 @@ static void child_process()
/* 1. Read the CrashData. */ /* 1. Read the CrashData. */
CrashData crash; CrashData crash;
if( !child_read(3, &crash, sizeof(CrashData)) ) if( !child_read(3, &crash, sizeof(CrashData)) )
return; return;
/* 2. Read info. */ /* 2. Read info. */
int size; int size;
if( !child_read(3, &size, sizeof(size)) ) if( !child_read(3, &size, sizeof(size)) )
return; return;
char *Info = new char [size]; char *Info = new char [size];
if( !child_read(3, Info, size) ) if( !child_read(3, Info, size) )
return; return;
/* 3. Read AdditionalLog. */ /* 3. Read AdditionalLog. */
if( !child_read(3, &size, sizeof(size)) ) if( !child_read(3, &size, sizeof(size)) )
return; return;
char *AdditionalLog = new char [size]; char *AdditionalLog = new char [size];
if( !child_read(3, AdditionalLog, size) ) if( !child_read(3, AdditionalLog, size) )
return; return;
/* 4. Read RecentLogs. */ /* 4. Read RecentLogs. */
int cnt = 0; int cnt = 0;
if( !child_read(3, &cnt, sizeof(cnt)) ) if( !child_read(3, &cnt, sizeof(cnt)) )
return; return;
char *Recent[1024]; char *Recent[1024];
for( int i = 0; i < cnt; ++i ) for( int i = 0; i < cnt; ++i )
{ {
if( !child_read(3, &size, sizeof(size)) ) if( !child_read(3, &size, sizeof(size)) )
return; return;
Recent[i] = new char [size]; Recent[i] = new char [size];
if( !child_read(3, Recent[i], size) ) if( !child_read(3, Recent[i], size) )
return; return;
} }
/* 5. Read CHECKPOINTs. */ /* 5. Read CHECKPOINTs. */
if( !child_read(3, &size, sizeof(size)) ) if( !child_read(3, &size, sizeof(size)) )
return; return;
char *temp = new char [size]; char *temp = new char [size];
if( !child_read(3, temp, size) ) if( !child_read(3, temp, size) )
return; return;
vector<CString> Checkpoints; vector<CString> Checkpoints;
split(temp, "$$", Checkpoints); split(temp, "$$", Checkpoints);
@@ -238,10 +238,10 @@ static void child_process()
/* 6. Read the crashed thread's name. */ /* 6. Read the crashed thread's name. */
if( !child_read(3, &size, sizeof(size)) ) if( !child_read(3, &size, sizeof(size)) )
return; return;
temp = new char [size]; temp = new char [size];
if( !child_read(3, temp, size) ) if( !child_read(3, temp, size) )
return; return;
const CString CrashedThread(temp); const CString CrashedThread(temp);
delete[] temp; delete[] temp;
@@ -249,15 +249,16 @@ static void child_process()
* This should time out, in case something deadlocks. */ * This should time out, in case something deadlocks. */
char x; char x;
int ret = read(3, &x, sizeof(x)); int ret = read( 3, &x, sizeof(x) );
if( ret > 0 ) if( ret > 0 )
{ {
fprintf( stderr, "Unexpected child read() result: %i\n", ret ); fprintf( stderr, "Unexpected child read() result: %i\n", ret );
/* keep going */ /* 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? */ /* 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 */ /* keep going */
} }
@@ -274,52 +275,57 @@ static void child_process()
exit(1); exit(1);
} }
fprintf(CrashDump, "%s crash report", PRODUCT_NAME_VER ); fprintf( CrashDump, "%s crash report", PRODUCT_NAME_VER );
#if defined(HAVE_VERSION_INFO) #if defined(HAVE_VERSION_INFO)
fprintf(CrashDump, " (build %u)", version_num); fprintf( CrashDump, " (build %u)", version_num);
#endif #endif
fprintf(CrashDump, "\n"); fprintf( CrashDump, "\n" );
fprintf(CrashDump, "--------------------------------------\n"); fprintf( CrashDump, "--------------------------------------\n" );
fprintf(CrashDump, "\n"); fprintf( CrashDump, "\n" );
CString reason; CString reason;
switch( crash.type ) switch( crash.type )
{ {
case CrashData::SIGNAL: case CrashData::SIGNAL:
{ {
CString Signal = SignalName( crash.signal ); CString Signal = SignalName( crash.signal );
#if !defined(MACOSX) #if !defined(MACOSX)
reason = ssprintf( "%s - %s", Signal.c_str(), SignalCodeName(crash.signal, crash.si.si_code) ); reason = ssprintf( "%s - %s", Signal.c_str(), SignalCodeName(crash.signal, crash.si.si_code) );
#else #else
reason = Signal; reason = Signal;
#endif #endif
/* Linux puts the PID that sent the signal in si_addr for SI_USER. */ /* Linux puts the PID that sent the signal in si_addr for SI_USER. */
if( crash.si.si_code == SI_USER ) if( crash.si.si_code == SI_USER )
reason += ssprintf( " from pid %li", (long) crash.si.si_addr ); {
else switch( crash.signal ) reason += ssprintf( " from pid %li", (long) crash.si.si_addr );
{ }
case SIGILL: else
case SIGFPE: {
case SIGSEGV: switch( crash.signal )
case SIGBUS: {
reason += ssprintf( " at 0x%0*lx", int(sizeof(void*)*2), (unsigned long) crash.si.si_addr ); 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;
case CrashData::FORCE_CRASH: reason = crash.reason;
crash.reason[ sizeof(crash.reason)-1] = 0; break;
reason = crash.reason;
break;
} }
fprintf( CrashDump, "Crash reason: %s\n", reason.c_str() ); fprintf( CrashDump, "Crash reason: %s\n", reason.c_str() );
fprintf( CrashDump, "Crashed thread: %s\n\n", CrashedThread.c_str() ); fprintf( CrashDump, "Crashed thread: %s\n\n", CrashedThread.c_str() );
fprintf(CrashDump, "Checkpoints:\n"); fprintf(CrashDump, "Checkpoints:\n");
for (unsigned i=0; i<Checkpoints.size(); ++i) for( unsigned i=0; i<Checkpoints.size(); ++i )
fprintf(CrashDump, Checkpoints[i]); fprintf( CrashDump, Checkpoints[i] );
fprintf(CrashDump, "\n"); fprintf( CrashDump, "\n" );
for( int i = 0; i < CrashData::MAX_BACKTRACE_THREADS; ++i ) for( int i = 0; i < CrashData::MAX_BACKTRACE_THREADS; ++i )
{ {
@@ -327,18 +333,18 @@ static void child_process()
break; break;
fprintf( CrashDump, "Thread: %s\n", crash.m_ThreadName[i] ); fprintf( CrashDump, "Thread: %s\n", crash.m_ThreadName[i] );
output_stack_trace( CrashDump, crash.BacktracePointers[i] ); output_stack_trace( CrashDump, crash.BacktracePointers[i] );
fprintf(CrashDump, "\n"); fprintf( CrashDump, "\n" );
} }
fprintf(CrashDump, "Static log:\n"); fprintf( CrashDump, "Static log:\n" );
fprintf(CrashDump, "%s", Info); fprintf( CrashDump, "%s", Info );
fprintf(CrashDump, "%s", AdditionalLog); fprintf( CrashDump, "%s", AdditionalLog );
fprintf(CrashDump, "\nPartial log:\n"); fprintf(CrashDump, "\nPartial log:\n" );
for( int i = 0; i < cnt; ++i ) for( int i = 0; i < cnt; ++i )
fprintf(CrashDump, "%s\n", Recent[i] ); fprintf( CrashDump, "%s\n", Recent[i] );
fprintf(CrashDump, "\n"); fprintf( CrashDump, "\n" );
fprintf(CrashDump, "-- End of report\n"); fprintf( CrashDump, "-- End of report\n" );
fclose(CrashDump); fclose( CrashDump) ;
#if defined(MACOSX) #if defined(MACOSX)
/* Forcibly kill our parent. */ /* Forcibly kill our parent. */
@@ -346,22 +352,21 @@ static void child_process()
InformUserOfCrash( sCrashInfoPath ); InformUserOfCrash( sCrashInfoPath );
#else #else
/* stdout may have been inadvertently closed by the crash in the parent; /* stdout may have been inadvertently closed by the crash in the parent;
* write to /dev/tty instead. */ * write to /dev/tty instead. */
FILE *tty = fopen( "/dev/tty", "w" ); FILE *tty = fopen( "/dev/tty", "w" );
if( tty == NULL ) if( tty == NULL )
tty = stderr; tty = stderr;
fprintf(tty, fprintf( tty,
"\n" "\n"
PRODUCT_NAME " has crashed. Debug information has been output to\n" PRODUCT_NAME " has crashed. Debug information has been output to\n"
"\n" "\n"
" " + sCrashInfoPath + "\n" " " + sCrashInfoPath + "\n"
"\n" "\n"
"Please report a bug at:\n" "Please report a bug at:\n"
"\n" "\n"
" " REPORT_BUG_URL "\n" " " REPORT_BUG_URL "\n"
"\n" "\n" );
);
#endif #endif
} }