Commit b6064c1f authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Cleaning the crashhandler code.

Backtrace generation is now in its own file, depending on the OS. First N symbols may be
skipped. Backtrace generation code isn't built when crash handler GUI is
disactivated.
parent 6651be7c
...@@ -218,9 +218,13 @@ SET(VLMC_RCC ...@@ -218,9 +218,13 @@ SET(VLMC_RCC
) )
IF (WITH_CRASHHANDLER_GUI) IF (WITH_CRASHHANDLER_GUI)
LIST( APPEND VLMC_SRCS Gui/widgets/CrashHandler.cpp ) LIST( APPEND VLMC_SRCS Gui/widgets/CrashHandler.cpp)
LIST( APPEND VLMC_HDRS Gui/widgets/CrashHandler.h ) IF (UNIX)
LIST( APPEND VLMC_SRCS Tools/UnixBacktraceGenerator.cpp)
ENDIF(UNIX)
LIST( APPEND VLMC_HDRS Gui/widgets/CrashHandler.h Tools/BacktraceGenerator.h )
LIST( APPEND VLMC_UIS Gui/widgets/CrashHandler.ui ) LIST( APPEND VLMC_UIS Gui/widgets/CrashHandler.ui )
ENDIF(WITH_CRASHHANDLER_GUI) ENDIF(WITH_CRASHHANDLER_GUI)
#include paths for vlmc #include paths for vlmc
......
...@@ -21,13 +21,9 @@ ...@@ -21,13 +21,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef WIN32
#include <execinfo.h>
#include <cxxabi.h>
#endif
#include <signal.h> #include <signal.h>
#include "BacktraceGenerator.h"
#include "CrashHandler.h" #include "CrashHandler.h"
#include "ui_CrashHandler.h" #include "ui_CrashHandler.h"
...@@ -39,40 +35,12 @@ CrashHandler::CrashHandler( int sig, QWidget *parent ) : ...@@ -39,40 +35,12 @@ CrashHandler::CrashHandler( int sig, QWidget *parent ) :
connect( ui->okButton, SIGNAL( clicked() ), this, SLOT( close() ) ); connect( ui->okButton, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( ui->restartButton, SIGNAL( clicked() ), this, SLOT( restart() ) ); connect( ui->restartButton, SIGNAL( clicked() ), this, SLOT( restart() ) );
#ifndef WIN32 QStringList backtrace = Tools::generateBacktrace( 4 );
void *buff[CrashHandler::backtraceSize]; foreach ( QString symb, backtrace )
int nbSymb = backtrace( buff, CrashHandler::backtraceSize );
char** backtraceStr = backtrace_symbols( buff, nbSymb );
char* symbName;
char* mangledName;
int status;
int pos;
for ( int i = 0; i < nbSymb; ++i )
{ {
mangledName = strchr( backtraceStr[i], '(' ); ui->backtraceDisplay->insertPlainText( symb );
char* endPos = strchr( mangledName, '+' ); ui->backtraceDisplay->insertPlainText( "\n" );
if ( endPos != NULL && endPos != NULL )
{
pos = endPos - mangledName;
char *copy = strdup( mangledName + 1 ); //Skipping the parenthesis
copy[pos - 1] = 0;
symbName = abi::__cxa_demangle( copy, NULL, 0, &status);
if ( status == 0 )
{
ui->backtraceDisplay->insertPlainText( QString( symbName ) + "\n" );
free( symbName );
continue ;
}
free(symbName);
free(copy);
}
ui->backtraceDisplay->insertPlainText( QString( backtraceStr[i]) + "\n" );
} }
free(backtraceStr);
#else
ui->backtraceDisplay->insertPlainText( tr( "Unable to get backtrace." ) );
#endif
QString sigName = tr( "Unknown signal" ); QString sigName = tr( "Unknown signal" );
if ( sig == SIGSEGV ) if ( sig == SIGSEGV )
sigName = "SIGSEGV (Segmentation Fault)"; sigName = "SIGSEGV (Segmentation Fault)";
......
...@@ -47,7 +47,6 @@ class CrashHandler : public QDialog ...@@ -47,7 +47,6 @@ class CrashHandler : public QDialog
private: private:
Ui::CrashHandler* ui; Ui::CrashHandler* ui;
static const int backtraceSize = 256;
}; };
#endif // CRASHHANDLER_H #endif // CRASHHANDLER_H
...@@ -47,12 +47,12 @@ void ProjectManager::signalHandler( int sig ) ...@@ -47,12 +47,12 @@ void ProjectManager::signalHandler( int sig )
ProjectManager::getInstance()->emergencyBackup(); ProjectManager::getInstance()->emergencyBackup();
#ifdef WITH_CRASHHANDLER_GUI #ifdef WITH_CRASHHANDLER_GUI
CrashHandler* ch = new CrashHandler( sig ); CrashHandler* ch = new CrashHandler( sig );
::exit( ch->exec() ); ::exit( ch->exec() );
#else #else
::exit( 1 ); ::exit( 1 );
#endif #endif
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment