CrashHandler.cpp 2.58 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * CrashHandler.cpp: Display the backtrace and some other information when a
 *                      crash occurs
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
5
 * Copyright (C) 2008-2010 VideoLAN
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

24
#include <signal.h>
25

26
#include "BacktraceGenerator.h"
27 28 29
#include "CrashHandler.h"
#include "ui_CrashHandler.h"

30
CrashHandler::CrashHandler( int sig, QWidget *parent ) :
31 32 33 34
        QDialog( parent ),
        ui( new Ui::CrashHandler )
{
    ui->setupUi( this );
35 36
    connect( ui->okButton, SIGNAL( clicked() ), this, SLOT( close() ) );
    connect( ui->restartButton, SIGNAL( clicked() ), this, SLOT( restart() ) );
37

38 39
    QStringList     backtrace = Tools::generateBacktrace( 4 );
    foreach ( QString symb, backtrace )
40
    {
41 42
        ui->backtraceDisplay->insertPlainText( symb );
        ui->backtraceDisplay->insertPlainText( "\n" );
43
    }
44 45 46
    QString sigName = tr( "Unknown signal" );
    if ( sig == SIGSEGV )
        sigName = "SIGSEGV (Segmentation Fault)";
47
    else if ( sig == SIGFPE )
48
        sigName = "SIGFPE (Floating Exception)";
49 50 51 52
    else if ( sig == SIGABRT )
        sigName = "SIGABRT (Aborted)";
    else if ( sig == SIGILL )
        sigName = "SIGILL (Illegal Instruction)";
53 54
    else
        sigName = "Unknown";
55
    ui->crashDescriptionLabel->setText( tr("A crash occurred. Signal received: ") + sigName );
56 57 58 59 60 61 62
}

CrashHandler::~CrashHandler()
{
    delete ui;
}

63 64
void
CrashHandler::changeEvent(QEvent *e)
65 66 67 68 69 70 71 72 73 74 75
{
    QWidget::changeEvent(e);
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        ui->retranslateUi( this );
        break;
    default:
        break;
    }
}
76

77 78
void
CrashHandler::close()
79
{
80
    done(1);
81 82
}

83 84
void
CrashHandler::restart()
85
{
86
    done(2);
87
}