void printStackAndExit( int signalNum ) { const int fd = 0; formattedWrite( fd , "Received signal %d\n" , signalNum ); formattedWrite( fd , "Backtrace: " ); formattedBacktrace( fd ); formattedWrite( fd , "===\n" ); ::_exit( EXIT_ABRUPT ); }
void printStackAndExit( int signalNum ) { int fd = Logstream::getLogDesc(); if ( fd >= 0 ) { formattedWrite( fd , "Received signal %d\n" , signalNum ); formattedWrite( fd , "Backtrace: " ); formattedBacktrace( fd ); formattedWrite( fd , "===\n" ); } ::_exit( EXIT_ABRUPT ); }
static void formattedBacktrace( int fd ) { #ifdef MONGO_HAVE_EXECINFO_BACKTRACE int numFrames; const int MAX_DEPTH = 20; void* stackFrames[MAX_DEPTH]; numFrames = backtrace( stackFrames , 20 ); for ( int i = 0; i < numFrames; i++ ) { formattedWrite( fd , "%p " , stackFrames[i] ); } formattedWrite( fd , "\n" ); backtrace_symbols_fd( stackFrames , numFrames , fd ); #else formattedWrite( fd, "backtracing not implemented for this platform yet\n" ); #endif }