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:
driAn
2008-10-16 21:31:48 +00:00
parent fb3ff3da3a
commit cbee2fb7cb
3 changed files with 45 additions and 3 deletions
+40
View File
@@ -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)