2003-07-31 22:35:54 +00:00
|
|
|
#define __USE_GNU
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
2004-03-12 05:15:32 +00:00
|
|
|
#include "Backtrace.h"
|
|
|
|
|
#include "BacktraceNames.h"
|
|
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "CrashHandler.h"
|
|
|
|
|
#include "CrashHandlerInternal.h"
|
|
|
|
|
#include "RageLog.h" /* for RageLog::GetAdditionalLog, etc. only */
|
2003-08-19 02:30:10 +00:00
|
|
|
#include "ProductInfo.h"
|
2003-07-31 22:35:54 +00:00
|
|
|
|
|
|
|
|
#if defined(DARWIN)
|
|
|
|
|
#include "archutils/Darwin/Crash.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-08-02 12:51:25 +00:00
|
|
|
#if defined(HAVE_VERSION_INFO)
|
|
|
|
|
extern const unsigned version_num;
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-03-11 23:58:49 +00:00
|
|
|
const char *g_pCrashHandlerArgv0 = NULL;
|
|
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
|
|
|
|
|
static void output_stack_trace( FILE *out, void **BacktracePointers )
|
|
|
|
|
{
|
2003-08-16 20:54:15 +00:00
|
|
|
if( BacktracePointers[0] == BACKTRACE_METHOD_NOT_AVAILABLE )
|
|
|
|
|
{
|
|
|
|
|
fprintf( out, "No backtrace method available.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !BacktracePointers[0] )
|
|
|
|
|
{
|
|
|
|
|
fprintf( out, "Backtrace was empty.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
for( int i = 0; BacktracePointers[i]; ++i)
|
|
|
|
|
{
|
|
|
|
|
BacktraceNames bn;
|
|
|
|
|
bn.FromAddr( BacktracePointers[i] );
|
|
|
|
|
bn.Demangle();
|
|
|
|
|
|
2004-03-12 05:15:32 +00:00
|
|
|
/* Don't show the main module name. */
|
|
|
|
|
if( bn.File == g_pCrashHandlerArgv0 )
|
|
|
|
|
bn.File = "";
|
|
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
if( bn.Symbol == "__libc_start_main" )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
fprintf( out, "%s\n", bn.Format().c_str() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Once we get here, we should be * safe to do whatever we want;
|
|
|
|
|
* heavyweights like malloc and CString are OK. (Don't crash!) */
|
|
|
|
|
static void child_process()
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* 1. Read the backtrace pointers. */
|
|
|
|
|
void *BacktracePointers[BACKTRACE_MAX_SIZE];
|
|
|
|
|
ret = read(3, BacktracePointers, sizeof(void *)*BACKTRACE_MAX_SIZE);
|
|
|
|
|
|
|
|
|
|
/* 2. Read the signal. */
|
|
|
|
|
int SignalReceived;
|
|
|
|
|
ret = read(3, &SignalReceived, sizeof(SignalReceived));
|
|
|
|
|
|
|
|
|
|
/* 3. Read info. */
|
|
|
|
|
int size;
|
|
|
|
|
ret = read(3, &size, sizeof(size));
|
|
|
|
|
char *Info = new char [size];
|
|
|
|
|
ret = read(3, Info, size);
|
|
|
|
|
|
|
|
|
|
/* 4. Read AdditionalLog. */
|
|
|
|
|
ret = read(3, &size, sizeof(size));
|
|
|
|
|
char *AdditionalLog = new char [size];
|
|
|
|
|
ret = read(3, AdditionalLog, size);
|
|
|
|
|
|
|
|
|
|
/* 5. Read RecentLogs. */
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
ret = read(3, &cnt, sizeof(cnt));
|
|
|
|
|
char *Recent[1024];
|
|
|
|
|
for( int i = 0; i < cnt; ++i )
|
|
|
|
|
{
|
|
|
|
|
ret = read(3, &size, sizeof(size));
|
|
|
|
|
Recent[i] = new char [size];
|
|
|
|
|
ret = read(3, Recent[i], size);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-07 19:58:15 +00:00
|
|
|
/* 6. Read CHECKPOINTs. */
|
|
|
|
|
ret = read(3, &size, sizeof(size));
|
|
|
|
|
char *temp = new char [size];
|
|
|
|
|
ret = read(3, temp, size);
|
|
|
|
|
CStringArray Checkpoints;
|
|
|
|
|
split(temp, "$$", Checkpoints);
|
2003-10-21 09:00:15 +00:00
|
|
|
delete [] temp;
|
|
|
|
|
|
|
|
|
|
/* 7. Read the crashed thread's name. */
|
|
|
|
|
ret = read(3, &size, sizeof(size));
|
|
|
|
|
temp = new char [size];
|
|
|
|
|
ret = read(3, temp, size);
|
|
|
|
|
const CString CrashedThread(temp);
|
|
|
|
|
delete[] temp;
|
2003-08-07 19:58:15 +00:00
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
/* Wait for the child to either finish cleaning up or die. XXX:
|
|
|
|
|
* This should time out, in case something deadlocks. */
|
|
|
|
|
|
|
|
|
|
char x;
|
|
|
|
|
ret = read(3, &x, sizeof(x));
|
|
|
|
|
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));
|
|
|
|
|
/* keep going */
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-06 01:19:05 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2003-07-31 22:35:54 +00:00
|
|
|
|
2003-08-19 02:30:10 +00:00
|
|
|
fprintf(CrashDump, "%s crash report", PRODUCT_NAME_VER );
|
2003-08-02 12:51:25 +00:00
|
|
|
#if defined(HAVE_VERSION_INFO)
|
2003-08-19 02:30:10 +00:00
|
|
|
fprintf(CrashDump, " (build %u)", version_num);
|
2003-08-02 12:51:25 +00:00
|
|
|
#endif
|
2003-08-19 02:30:10 +00:00
|
|
|
fprintf(CrashDump, "\n");
|
|
|
|
|
fprintf(CrashDump, "--------------------------------------\n");
|
2003-07-31 22:35:54 +00:00
|
|
|
fprintf(CrashDump, "\n");
|
|
|
|
|
|
2004-03-19 03:13:27 +00:00
|
|
|
CString Signal = SignalName( SignalReceived );
|
2003-07-31 22:35:54 +00:00
|
|
|
|
2003-10-21 09:00:15 +00:00
|
|
|
fprintf( CrashDump, "Crash reason: %s\n", Signal.c_str() );
|
|
|
|
|
fprintf( CrashDump, "Crashed thread: %s\n\n", CrashedThread.c_str() );
|
2003-07-31 22:35:54 +00:00
|
|
|
|
2003-08-28 22:17:42 +00:00
|
|
|
fprintf(CrashDump, "Checkpoints:\n");
|
|
|
|
|
for (unsigned i=0; i<Checkpoints.size(); ++i)
|
|
|
|
|
fprintf(CrashDump, Checkpoints[i]);
|
|
|
|
|
fprintf(CrashDump, "\n");
|
|
|
|
|
|
2003-07-31 22:35:54 +00:00
|
|
|
output_stack_trace( CrashDump, BacktracePointers );
|
|
|
|
|
fprintf(CrashDump, "\n");
|
|
|
|
|
|
|
|
|
|
fprintf(CrashDump, "Static log:\n");
|
|
|
|
|
fprintf(CrashDump, "%s", Info);
|
|
|
|
|
fprintf(CrashDump, "%s", AdditionalLog);
|
|
|
|
|
fprintf(CrashDump, "\nPartial log:\n");
|
|
|
|
|
for( int i = 0; i < cnt; ++i )
|
|
|
|
|
fprintf(CrashDump, "%s\n", Recent[i] );
|
|
|
|
|
fprintf(CrashDump, "\n");
|
|
|
|
|
fprintf(CrashDump, "-- End of report\n");
|
|
|
|
|
fclose(CrashDump);
|
|
|
|
|
|
|
|
|
|
#if defined(DARWIN)
|
2004-03-06 01:19:05 +00:00
|
|
|
InformUserOfCrash( sCrashInfoPath );
|
2003-07-31 22:35:54 +00:00
|
|
|
#else
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"\n"
|
2003-08-19 02:30:10 +00:00
|
|
|
PRODUCT_NAME " has crashed. Debug information has been output to\n"
|
2003-07-31 22:35:54 +00:00
|
|
|
"\n"
|
2004-03-06 01:19:05 +00:00
|
|
|
" " + sCrashInfoPath + "\n"
|
2003-07-31 22:35:54 +00:00
|
|
|
"\n"
|
|
|
|
|
"Please report a bug at:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" http://sourceforge.net/tracker/?func=add&group_id=37892&atid=421366\n"
|
|
|
|
|
"\n"
|
|
|
|
|
);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Forcibly kill our parent. */
|
|
|
|
|
// kill( getppid(), SIGKILL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-11 23:58:49 +00:00
|
|
|
void CrashHandlerHandleArgs( int argc, char* argv[] )
|
2003-07-31 22:35:54 +00:00
|
|
|
{
|
2004-03-11 23:58:49 +00:00
|
|
|
g_pCrashHandlerArgv0 = argv[0];
|
|
|
|
|
if( argc == 2 && !strcmp(argv[1], CHILD_MAGIC_PARAMETER) )
|
|
|
|
|
{
|
|
|
|
|
child_process();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2003-07-31 22:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|