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
)
IF (WITH_CRASHHANDLER_GUI)
LIST( APPEND VLMC_SRCS Gui/widgets/CrashHandler.cpp )
LIST( APPEND VLMC_HDRS Gui/widgets/CrashHandler.h )
LIST( APPEND VLMC_SRCS Gui/widgets/CrashHandler.cpp)
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 )
ENDIF(WITH_CRASHHANDLER_GUI)
#include paths for vlmc
......
......@@ -21,13 +21,9 @@
* 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 "BacktraceGenerator.h"
#include "CrashHandler.h"
#include "ui_CrashHandler.h"
......@@ -39,40 +35,12 @@ CrashHandler::CrashHandler( int sig, QWidget *parent ) :
connect( ui->okButton, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( ui->restartButton, SIGNAL( clicked() ), this, SLOT( restart() ) );
#ifndef WIN32
void *buff[CrashHandler::backtraceSize];
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], '(' );
char* endPos = strchr( mangledName, '+' );
if ( endPos != NULL && endPos != NULL )
QStringList backtrace = Tools::generateBacktrace( 4 );
foreach ( QString symb, backtrace )
{
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" );
ui->backtraceDisplay->insertPlainText( symb );
ui->backtraceDisplay->insertPlainText( "\n" );
}
free(backtraceStr);
#else
ui->backtraceDisplay->insertPlainText( tr( "Unable to get backtrace." ) );
#endif
QString sigName = tr( "Unknown signal" );
if ( sig == SIGSEGV )
sigName = "SIGSEGV (Segmentation Fault)";
......
......@@ -47,7 +47,6 @@ class CrashHandler : public QDialog
private:
Ui::CrashHandler* ui;
static const int backtraceSize = 256;
};
#endif // CRASHHANDLER_H
......@@ -47,12 +47,12 @@ void ProjectManager::signalHandler( int sig )
ProjectManager::getInstance()->emergencyBackup();
#ifdef WITH_CRASHHANDLER_GUI
#ifdef WITH_CRASHHANDLER_GUI
CrashHandler* ch = new CrashHandler( sig );
::exit( ch->exec() );
#else
#else
::exit( 1 );
#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