From cbee2fb7cb04fbaa24769d5d172781241b75f2c4 Mon Sep 17 00:00:00 2001 From: driAn Date: Thu, 16 Oct 2008 21:31:48 +0000 Subject: [PATCH] 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 --- source/src/Makefile | 6 +++--- source/src/pch.h | 2 ++ source/src/tools.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/source/src/Makefile b/source/src/Makefile index 7615a326..cb08208f 100644 --- a/source/src/Makefile +++ b/source/src/Makefile @@ -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 diff --git a/source/src/pch.h b/source/src/pch.h index 8611cc48..b5c44cfd 100644 --- a/source/src/pch.h +++ b/source/src/pch.h @@ -17,6 +17,8 @@ #include #ifdef __GNUC__ #include +#include +#include #else #include #endif diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 4e2fd492..a2becfc6 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -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)