diff --git a/engine/Makefile b/engine/Makefile index 2b34730af..03c518607 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -270,6 +270,7 @@ CLIENT_ONLY_CFLAGS=-DCLIENTONLY SERVER_ONLY_CFLAGS=-DSERVERONLY JOINT_CFLAGS= DEBUG_CFLAGS=-ggdb -g +DEBUG_CFLAGS=-rdynamic PROFILE_CFLAGS=-pg ifeq ($(FTE_TARGET),win32) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index dc1cd72d5..1216fab6a 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -3117,10 +3117,6 @@ void CL_Init (void) Cmd_AddCommand ("demo_jump", CL_DemoJump_f); Cmd_AddCommand ("timedemo", CL_TimeDemo_f); -#ifdef _DEBUG - Cmd_AddCommand ("crashme", (void*)~0); -#endif - Cmd_AddCommand ("showpic", SCR_ShowPic_Script_f); Cmd_AddCommand ("startdemos", CL_Startdemos_f); diff --git a/engine/common/common.c b/engine/common/common.c index 419dd825c..d20f08eaa 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -3309,6 +3309,8 @@ void COM_Init (void) Cmd_AddCommand ("dir", COM_Dir_f); //q3 like Cmd_AddCommand ("flocate", COM_Locate_f); //prints the pak or whatever where this file can be found. Cmd_AddCommand ("version", COM_Version_f); //prints the pak or whatever where this file can be found. + + Cmd_AddCommand ("crashme", (void*)0); //debugging feature, makes it jump to an invalid address COM_InitFilesystem (); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index d166b5e9f..9818faed8 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -1630,6 +1630,22 @@ void SV_AcceptMessage(int protocol) Netchan_OutOfBand (NS_SERVER, net_from, len, (qbyte *)string); } +#ifndef _WIN32 +#include +static void SV_CheckRecentCrashes(client_t *tellclient) +{ + struct stat sb; + if (-1 != stat("crash.log", &sb)) + { + SV_ClientPrintf(tellclient, PRINT_HIGH, "\1WARNING: crash.log exists, dated %s\n", ctime(&sb.st_mtime)); + } +} +#else +static void SV_CheckRecentCrashes(client_t *tellclient) +{ +} +#endif + /* ================== SVC_DirectConnect @@ -2389,6 +2405,8 @@ client_t *SVC_DirectConnect(void) SV_ClientPrintf(newcl, PRINT_CHAT, "%s\n", sv_motd[i].string); } + SV_CheckRecentCrashes(newcl); + #ifdef PEXT2_VOICECHAT SV_VoiceInitClient(newcl); #endif diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index df9db8d83..b819f99c5 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -637,6 +637,32 @@ void Sys_Shutdown (void) { } +#include +static void Friendly_Crash_Handler(int sig) +{ + int fd; + void *array[10]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 10); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(array, size, 2); + + fd = open("crash.log", O_WRONLY|O_CREAT|O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP); + if (fd != -1) + { + write(fd, "Crash Log:\n", 11); + size = backtrace(array, 10); + backtrace_symbols_fd(array, size, fd); + write(fd, "\n", 1); + close(fd); + } + exit(1); +} + /* ============= main @@ -661,6 +687,12 @@ int main(int argc, char *argv[]) parms.argc = com_argc; parms.argv = com_argv; + if (COM_CheckParm("-dumpstack")) + { + signal(SIGILL, Friendly_Crash_Handler); + signal(SIGSEGV, Friendly_Crash_Handler); + signal(SIGBUS, Friendly_Crash_Handler); + } parms.memsize = 16*1024*1024;