2007-02-23 08:36:11 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#include "frame.h"
|
|
|
|
|
2007-03-03 10:23:06 -08:00
|
|
|
#if defined(WZ_OS_WIN)
|
|
|
|
|
2007-02-23 08:36:11 -08:00
|
|
|
# include "dbghelp.h"
|
2007-03-03 10:23:06 -08:00
|
|
|
|
2007-02-23 08:36:11 -08:00
|
|
|
static LONG WINAPI windowsExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
|
|
|
|
{
|
2007-03-05 16:46:34 -08:00
|
|
|
LPCSTR applicationName = "Warzone 2100";
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-03-05 16:46:34 -08:00
|
|
|
char miniDumpPath[MAX_PATH], resultMessage[MAX_PATH];
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
// Write to temp dir, to support unprivileged users
|
2007-03-05 16:46:34 -08:00
|
|
|
if (!GetTempPathA( MAX_PATH, miniDumpPath ))
|
2007-02-23 08:36:11 -08:00
|
|
|
strcpy( miniDumpPath, "c:\\temp\\" );
|
|
|
|
strcat( miniDumpPath, "warzone2100.mdmp" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
Alternative:
|
|
|
|
GetModuleFileName( NULL, miniDumpPath, MAX_PATH );
|
|
|
|
strcat( miniDumpPath, ".mdmp" );
|
|
|
|
*/
|
|
|
|
|
2007-03-05 16:46:34 -08:00
|
|
|
if ( MessageBoxA( NULL, "Warzone crashed unexpectedly, would you like to save a diagnostic file?", applicationName, MB_YESNO ) == IDYES )
|
2007-02-23 08:36:11 -08:00
|
|
|
{
|
2007-03-05 16:46:34 -08:00
|
|
|
HANDLE miniDumpFile = CreateFileA( miniDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
if (miniDumpFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2007-03-03 10:23:06 -08:00
|
|
|
MINIDUMP_USER_STREAM uStream = { LastReservedStream+1, strlen(VERSION), VERSION };
|
2007-02-23 08:36:11 -08:00
|
|
|
MINIDUMP_USER_STREAM_INFORMATION uInfo = { 1, &uStream };
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION eInfo = { GetCurrentThreadId(), pExceptionInfo, FALSE };
|
|
|
|
|
|
|
|
if ( MiniDumpWriteDump(
|
|
|
|
GetCurrentProcess(),
|
|
|
|
GetCurrentProcessId(),
|
|
|
|
miniDumpFile,
|
|
|
|
MiniDumpNormal,
|
|
|
|
pExceptionInfo ? &eInfo : NULL,
|
|
|
|
&uInfo,
|
|
|
|
NULL ) )
|
|
|
|
{
|
2007-03-05 16:46:34 -08:00
|
|
|
sprintf( resultMessage, "Saved dump file to '%s'", miniDumpPath );
|
|
|
|
MessageBoxA( NULL, resultMessage, applicationName, MB_OK );
|
2007-02-23 08:36:11 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-05 16:46:34 -08:00
|
|
|
sprintf( resultMessage, "Failed to save dump file to '%s' (error %d)", miniDumpPath, GetLastError() );
|
|
|
|
MessageBoxA( NULL, resultMessage, applicationName, MB_OK );
|
2007-02-23 08:36:11 -08:00
|
|
|
}
|
|
|
|
CloseHandle(miniDumpFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-05 16:46:34 -08:00
|
|
|
sprintf( resultMessage, "Failed to create dump file '%s' (error %d)", miniDumpPath, GetLastError() );
|
|
|
|
MessageBoxA( NULL, resultMessage, applicationName, MB_OK );
|
2007-02-23 08:36:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
2007-03-03 10:23:06 -08:00
|
|
|
|
|
|
|
#elif defined(WZ_OS_LINUX)
|
|
|
|
|
|
|
|
// C99 headers:
|
2007-03-04 16:24:23 -08:00
|
|
|
# include <stdint.h>
|
|
|
|
# include <signal.h>
|
|
|
|
# include <string.h>
|
2007-03-03 10:23:06 -08:00
|
|
|
|
|
|
|
// POSIX headers:
|
2007-03-04 16:24:23 -08:00
|
|
|
# include <unistd.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <sys/wait.h>
|
|
|
|
# include <sys/utsname.h>
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-03-03 10:23:06 -08:00
|
|
|
// GNU header:
|
2007-03-04 16:24:23 -08:00
|
|
|
# include <execinfo.h>
|
2007-03-03 10:23:06 -08:00
|
|
|
|
2007-03-04 05:04:36 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
# define MAX_BACKTRACE 20
|
|
|
|
# define MAX_PID_STRING 16
|
2007-02-24 10:21:22 -08:00
|
|
|
|
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
typedef void(*SigHandler)(int);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
static struct utsname sysInfo;
|
|
|
|
static BOOL gdbIsAvailable = FALSE, sysInfoValid = FALSE;
|
2007-02-28 17:29:07 -08:00
|
|
|
static SigHandler oldHandler[NSIG] = {SIG_DFL};
|
2007-03-05 16:30:07 -08:00
|
|
|
static char programPID[MAX_PID_STRING] = {'\0'}, gdbPath[MAX_PATH] = {'\0'}, * gdmpPath = NULL, * programCommand = NULL;
|
|
|
|
|
2007-03-04 05:52:41 -08:00
|
|
|
|
2007-03-04 14:50:41 -08:00
|
|
|
/* Ugly, but arguably correct */
|
2007-03-05 16:30:07 -08:00
|
|
|
static const char * wz_strsignal(int signum)
|
2007-03-04 05:52:41 -08:00
|
|
|
{
|
2007-03-04 14:50:41 -08:00
|
|
|
switch (signum)
|
|
|
|
{
|
|
|
|
/* Standard signals */
|
|
|
|
case SIGHUP : return "SIGHUP, Hangup";
|
|
|
|
case SIGINT : return "SIGINT, Interrupt";
|
|
|
|
case SIGQUIT : return "SIGQUIT, Quit";
|
|
|
|
case SIGILL : return "SIGILL, Illegal instruction";
|
|
|
|
case SIGTRAP : return "SIGTRAP, Trace trap";
|
|
|
|
case SIGABRT : return "SIGABRT, Abort";
|
|
|
|
case SIGBUS : return "SIGBUS, BUS error";
|
|
|
|
case SIGFPE : return "SIGFPE, Floating-point exception";
|
|
|
|
case SIGKILL : return "SIGKILL, Kill";
|
|
|
|
case SIGUSR1 : return "SIGUSR1, User-defined signal 1";
|
|
|
|
case SIGUSR2 : return "SIGUSR2, User-defined signal 2";
|
|
|
|
case SIGSEGV : return "SIGSEGV, Segmentation fault";
|
|
|
|
case SIGPIPE : return "SIGPIPE, Broken pipe";
|
|
|
|
case SIGALRM : return "SIGALRM, Alarm clock";
|
|
|
|
case SIGTERM : return "SIGTERM, Termination";
|
2007-03-04 16:24:23 -08:00
|
|
|
|
2007-03-04 14:50:41 -08:00
|
|
|
/* Less standard signals */
|
2007-03-04 16:24:23 -08:00
|
|
|
# if defined(SIGSTKFLT)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGSTKFLT : return "SIGSTKFLT, Stack fault";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGCHLD)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGCHLD : return "SIGCHLD, Child status has changed";
|
2007-03-04 16:24:23 -08:00
|
|
|
# elif defined(SIGCLD)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGCLD : return "SIGCLD, Child status has changed";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGCONT)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGCONT : return "SIGCONT, Continue";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGSTOP)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGSTOP : return "SIGSTOP, Stop";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGTSTP)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGTSTP : return "SIGTSTP, Keyboard stop";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGTTIN)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGTTIN : return "SIGTTIN, Background read from tty";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGTTOU)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGTTOU : return "SIGTTOU, Background write to tty";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGURG)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGURG : return "SIGURG, Urgent condition on socket";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGXCPU)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGXCPU : return "SIGXCPU, CPU limit exceeded";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGXFSZ)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGXFSZ : return "SIGXFSZ, File size limit exceeded";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGVTALRM)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGVTALRM : return "SIGVTALRM, Virtual alarm clock";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGPROF)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGPROF : return "SIGPROF, Profiling alarm clock";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGWINCH)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGWINCH : return "SIGWINCH, Window size change";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGIO)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGIO : return "SIGIO, I/O now possible";
|
2007-03-04 16:24:23 -08:00
|
|
|
# elif defined(SIGPOLL)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGPOLL : return "SIGPOLL, I/O now possible";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGPWR)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGPWR : return "SIGPWR, Power failure restart";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(SIGSYS)
|
2007-03-04 14:50:41 -08:00
|
|
|
case SIGSYS : return "SIGSYS, Bad system call";
|
2007-03-04 16:24:23 -08:00
|
|
|
# endif
|
2007-03-04 14:50:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown signal";
|
2007-03-04 05:52:41 -08:00
|
|
|
}
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-02-24 10:21:22 -08:00
|
|
|
static void setErrorHandler(SigHandler signalHandler)
|
2007-02-23 08:36:11 -08:00
|
|
|
{
|
|
|
|
// Save previous signal handler, eg. SDL parachute
|
|
|
|
oldHandler[SIGFPE] = signal(SIGFPE, signalHandler);
|
|
|
|
if ( oldHandler[SIGFPE] == SIG_IGN )
|
|
|
|
signal(SIGFPE, SIG_IGN);
|
|
|
|
|
|
|
|
oldHandler[SIGILL] = signal(SIGILL, signalHandler);
|
|
|
|
if ( oldHandler[SIGILL] == SIG_IGN )
|
|
|
|
signal(SIGILL, SIG_IGN);
|
|
|
|
|
|
|
|
oldHandler[SIGSEGV] = signal(SIGSEGV, signalHandler);
|
|
|
|
if ( oldHandler[SIGSEGV] == SIG_IGN )
|
|
|
|
signal(SIGSEGV, SIG_IGN);
|
|
|
|
|
|
|
|
oldHandler[SIGBUS] = signal(SIGBUS, signalHandler);
|
|
|
|
if ( oldHandler[SIGBUS] == SIG_IGN )
|
|
|
|
signal(SIGBUS, SIG_IGN);
|
|
|
|
|
|
|
|
oldHandler[SIGABRT] = signal(SIGABRT, signalHandler);
|
|
|
|
if ( oldHandler[SIGABRT] == SIG_IGN )
|
|
|
|
signal(SIGABRT, SIG_IGN);
|
|
|
|
|
|
|
|
oldHandler[SIGSYS] = signal(SIGSYS, signalHandler);
|
|
|
|
if ( oldHandler[SIGSYS] == SIG_IGN )
|
|
|
|
signal(SIGSYS, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void errorHandler(int sig)
|
|
|
|
{
|
|
|
|
static sig_atomic_t allreadyRunning = 0;
|
|
|
|
|
|
|
|
if (allreadyRunning)
|
|
|
|
raise(sig);
|
|
|
|
allreadyRunning = 1;
|
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
pid_t pid = 0;
|
2007-02-28 17:29:07 -08:00
|
|
|
void * btBuffer[MAX_BACKTRACE] = {NULL};
|
|
|
|
uint32_t btSize = backtrace(btBuffer, MAX_BACKTRACE);
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
int gdbPipe[2] = {0}, dumpFile = open(gdmpPath, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
|
|
|
|
if (!dumpFile)
|
|
|
|
{
|
2007-03-04 16:24:23 -08:00
|
|
|
printf("Failed to create dump file '%s'", gdmpPath);
|
2007-02-23 08:36:11 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
write(dumpFile, "Program command: ", strlen("Program command: "));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, programCommand, strlen(programCommand));
|
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
|
|
|
write(dumpFile, "Version: ", strlen("Version: "));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, VERSION, strlen(VERSION));
|
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
2007-03-03 10:23:06 -08:00
|
|
|
# if defined(DEBUG)
|
|
|
|
write(dumpFile, "Type: Debug\n", strlen("Type: Debug\n"));
|
|
|
|
# else
|
|
|
|
write(dumpFile, "Type: Release\n", strlen("Type: Release\n"));
|
|
|
|
# endif
|
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
write(dumpFile, "Compiled on: ", strlen("Compiled on: "));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, __DATE__, strlen(__DATE__));
|
|
|
|
write(dumpFile, "\n\n", 2);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
if (!sysInfoValid)
|
2007-02-28 17:29:07 -08:00
|
|
|
write(dumpFile, "System information may be invalid!\n",
|
|
|
|
strlen("System information may be invalid!\n\n"));
|
|
|
|
|
|
|
|
write(dumpFile, "Operating system: ", strlen("Operating system: "));
|
|
|
|
write(dumpFile, sysInfo.sysname, strlen(sysInfo.sysname));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
|
|
|
write(dumpFile, "Node name: ", strlen("Node name: "));
|
|
|
|
write(dumpFile, sysInfo.nodename, strlen(sysInfo.nodename));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
|
|
|
write(dumpFile, "Release: ", strlen("Release: "));
|
|
|
|
write(dumpFile, sysInfo.release, strlen(sysInfo.release));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 17:29:07 -08:00
|
|
|
|
|
|
|
write(dumpFile, "Version: ", strlen("Version: "));
|
|
|
|
write(dumpFile, sysInfo.version, strlen(sysInfo.version));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
write(dumpFile, "Machine: ", strlen("Machine: "));
|
|
|
|
write(dumpFile, sysInfo.machine, strlen(sysInfo.machine));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n\n", 2);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
write(dumpFile, "Dump caused by signal: ",
|
|
|
|
strlen("Dump caused by signal: "));
|
2007-03-04 05:52:41 -08:00
|
|
|
write(dumpFile, wz_strsignal(sig), strlen(wz_strsignal(sig)));
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n\n", 2);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
// Dump raw backtrace in case GDB is not available or fails
|
2007-02-28 17:29:07 -08:00
|
|
|
backtrace_symbols_fd(btBuffer, btSize, dumpFile);
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "\n", 1);
|
2007-02-28 16:15:50 -08:00
|
|
|
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
// Make sure everything is written before letting GDB write to it
|
2007-02-28 16:15:50 -08:00
|
|
|
fsync(dumpFile);
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
if (gdbIsAvailable)
|
2007-03-04 04:05:53 -08:00
|
|
|
{
|
2007-03-04 16:24:23 -08:00
|
|
|
if (pipe(gdbPipe) == 0)
|
2007-03-04 04:05:53 -08:00
|
|
|
{
|
2007-03-04 16:24:23 -08:00
|
|
|
pid = fork();
|
|
|
|
if (pid == (pid_t)0)
|
|
|
|
{
|
|
|
|
char * gdbArgv[] = { gdbPath, programCommand, programPID, NULL },
|
|
|
|
* gdbEnv[] = {NULL};
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
close(gdbPipe[1]); // No output to pipe
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
dup2(gdbPipe[0], STDIN_FILENO); // STDIN from pipe
|
|
|
|
dup2(dumpFile, STDOUT_FILENO); // STDOUT to dumpFile
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
execve(gdbPath, gdbArgv, gdbEnv);
|
|
|
|
}
|
|
|
|
else if (pid > (pid_t)0)
|
|
|
|
{
|
|
|
|
close(gdbPipe[0]); // No input from pipe
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
write(gdbPipe[1], "backtrace full\n" "quit\n",
|
|
|
|
strlen("backtrace full\n" "quit\n"));
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
if (waitpid(pid, NULL, 0) < 0)
|
|
|
|
{
|
|
|
|
printf("GDB failed\n");
|
|
|
|
}
|
2007-03-04 04:05:53 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
close(gdbPipe[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Fork failed\n");
|
|
|
|
}
|
2007-03-04 04:05:53 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-04 16:24:23 -08:00
|
|
|
printf("Pipe failed\n");
|
2007-03-04 04:05:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-04 16:24:23 -08:00
|
|
|
write(dumpFile, "GDB not available, no extended backtrace created\n",
|
|
|
|
strlen("GDB not available, no extended backtrace created\n"));
|
2007-03-04 04:05:53 -08:00
|
|
|
}
|
2007-02-23 08:36:11 -08:00
|
|
|
|
2007-03-04 16:24:23 -08:00
|
|
|
|
|
|
|
printf("Saved dump file to '%s'\n", gdmpPath);
|
|
|
|
close(dumpFile);
|
|
|
|
|
|
|
|
|
2007-02-23 08:36:11 -08:00
|
|
|
signal(sig, oldHandler[sig]);
|
|
|
|
raise(sig);
|
|
|
|
}
|
2007-03-03 10:23:06 -08:00
|
|
|
|
|
|
|
#endif // WZ_OS_*
|
2007-02-23 08:36:11 -08:00
|
|
|
|
|
|
|
|
2007-02-28 17:29:07 -08:00
|
|
|
void setupExceptionHandler(char * programCommand_x)
|
2007-02-23 08:36:11 -08:00
|
|
|
{
|
2007-03-03 10:23:06 -08:00
|
|
|
#if defined(WZ_OS_WIN)
|
2007-02-23 08:36:11 -08:00
|
|
|
SetUnhandledExceptionFilter(windowsExceptionHandler);
|
2007-03-03 10:23:06 -08:00
|
|
|
#elif defined(WZ_OS_LINUX)
|
2007-03-04 05:04:36 -08:00
|
|
|
// Get full path to 'gdb'
|
|
|
|
FILE * whichStream = popen("which gdb", "r");
|
2007-03-04 16:24:23 -08:00
|
|
|
fread(gdbPath, 1, MAX_PATH, whichStream);
|
2007-03-04 05:04:36 -08:00
|
|
|
pclose(whichStream);
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
// Did we find GDB?
|
2007-03-04 16:24:23 -08:00
|
|
|
if (strlen(gdbPath) > 0)
|
|
|
|
{
|
|
|
|
gdbIsAvailable = TRUE;
|
|
|
|
*(strrchr(gdbPath, '\n')) = '\0'; // `which' adds a \n which confuses exec()
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug(LOG_WARNING, "GDB not available, will not create extended backtrace\n");
|
|
|
|
}
|
|
|
|
|
2007-03-05 16:30:07 -08:00
|
|
|
sysInfoValid = (uname(&sysInfo) == 0);
|
|
|
|
|
2007-03-04 05:04:36 -08:00
|
|
|
snprintf( programPID, MAX_PID_STRING, "%i", getpid() );
|
2007-03-05 16:30:07 -08:00
|
|
|
programCommand = programCommand_x;
|
|
|
|
gdmpPath = "/tmp/warzone2100.gdmp";
|
2007-03-04 05:04:36 -08:00
|
|
|
|
2007-02-23 08:36:11 -08:00
|
|
|
setErrorHandler(errorHandler);
|
2007-03-03 10:23:06 -08:00
|
|
|
#endif // WZ_OS_*
|
2007-02-23 08:36:11 -08:00
|
|
|
}
|