catch SIGSEGV and other signals on Linux to print stacktrace when crashing, don't strip bins on compilation
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3075 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
||||
CXXOPTFLAGS=-O3 -fomit-frame-pointer
|
||||
INCLUDES=-I/usr/X11R6/include -I../enet/include -I../src `sdl-config --cflags`
|
||||
CXXFLAGS=$(CXXOPTFLAGS) $(INCLUDES) -fsigned-char -Wall -Wno-deprecated
|
||||
CXXFLAGS=$(CXXOPTFLAGS) $(INCLUDES) -fsigned-char -Wall -Wno-deprecated -rdynamic
|
||||
|
||||
PLATFORM_PREFIX=native
|
||||
CLIENT_LIBS=-L/usr/X11R6/lib -L../enet -lenet `sdl-config --libs` -lSDL_image -lz -lGL -lGLU -lopenal -lvorbisfile
|
||||
@@ -80,5 +80,5 @@ server: $(SERVER_FILES)
|
||||
install: all
|
||||
cp ac_client ../../bin_unix/$(PLATFORM_PREFIX)_client
|
||||
cp ac_server ../../bin_unix/$(PLATFORM_PREFIX)_server
|
||||
strip ../../bin_unix/$(PLATFORM_PREFIX)_client
|
||||
strip ../../bin_unix/$(PLATFORM_PREFIX)_server
|
||||
# strip ../../bin_unix/$(PLATFORM_PREFIX)_client
|
||||
# strip ../../bin_unix/$(PLATFORM_PREFIX)_server
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <limits.h>
|
||||
#ifdef __GNUC__
|
||||
#include <new>
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#else
|
||||
#include <new.h>
|
||||
#endif
|
||||
|
||||
@@ -329,8 +329,48 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep)
|
||||
}
|
||||
fatal(out);
|
||||
}
|
||||
#elif !defined(WIN32) && defined(__GNUC__)
|
||||
|
||||
// stack dumping on linux, inspired by Sachin Agrawal's sample code
|
||||
|
||||
struct signalbinder
|
||||
{
|
||||
static void stackdumper(int sig)
|
||||
{
|
||||
printf("stacktrace:\n");
|
||||
|
||||
const int BTSIZE = 25;
|
||||
void *array[BTSIZE];
|
||||
int n = backtrace(array, BTSIZE);
|
||||
char **symbols = backtrace_symbols(array, n);
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
printf("%s\n", symbols[i]);
|
||||
}
|
||||
free(symbols);
|
||||
|
||||
fatal("AssaultCube error (%d)", sig);
|
||||
|
||||
}
|
||||
|
||||
signalbinder()
|
||||
{
|
||||
// register signals to dump the stack if they are raised,
|
||||
// use constructor for early registering
|
||||
signal(SIGSEGV, stackdumper);
|
||||
signal(SIGFPE, stackdumper);
|
||||
signal(SIGILL, stackdumper);
|
||||
signal(SIGBUS, stackdumper);
|
||||
signal(SIGSYS, stackdumper);
|
||||
signal(SIGABRT, stackdumper);
|
||||
}
|
||||
};
|
||||
|
||||
signalbinder sigbinder;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////// misc tools ///////////////////////
|
||||
|
||||
bool cmpb(void *b, int n, enet_uint32 c)
|
||||
|
||||
Reference in New Issue
Block a user