Navigation Menu

Skip to content

Commit

Permalink
windows: generate minidump on crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Apr 20, 2013
1 parent e5366b0 commit 99fac00
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -462,11 +462,12 @@ TARGET_LINK_LIBRARIES(${QGIS_APP_NAME}
)

IF (ANDROID)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} log)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} log)
ENDIF (ANDROID)

IF(WIN32)
ADD_DEFINITIONS(-DQWT_DLL)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} DbgHelp)
ENDIF(WIN32)

IF (APPLE)
Expand Down
49 changes: 48 additions & 1 deletion src/app/main.cpp
Expand Up @@ -31,6 +31,7 @@
#include <QPlastiqueStyle>
#include <QTranslator>
#include <QImageReader>
#include <QMessageBox>

#include "qgscustomization.h"
#include "qgspluginregistry.h"
Expand All @@ -44,6 +45,8 @@
#ifdef WIN32
// Open files in binary mode
#include <fcntl.h> /* _O_BINARY */
#include <windows.h>
#include <dbghelp.h>
#ifdef MSVC
#undef _fmode
int _fmode = _O_BINARY;
Expand Down Expand Up @@ -75,7 +78,7 @@ typedef SInt32 SRefCon;
#include "qgsrectangle.h"
#include "qgslogger.h"

#if defined(linux) && ! defined(ANDROID)
#if defined(linux) && !defined(ANDROID)
#include <unistd.h>
#include <execinfo.h>
#endif
Expand Down Expand Up @@ -147,6 +150,46 @@ bool bundleclicked( int argc, char *argv[] )
return ( argc > 1 && memcmp( argv[1], "-psn_", 5 ) == 0 );
}

#ifdef Q_OS_WIN
LONG WINAPI qgisCrashDump( struct _EXCEPTION_POINTERS *ExceptionInfo )
{
QString dumpName = QDir::toNativeSeparators(
QString( "%1\\qgis-%2-%3-%4.dmp" )
.arg( QDir::tempPath() )
.arg( QDateTime::currentDateTime().toString( "yyyyMMdd-hhmmss" ) )
.arg( GetCurrentProcessId() )
.arg( GetCurrentThreadId() ) );

QString msg;
HANDLE hDumpFile = CreateFile( dumpName.toAscii(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0 );
if ( hDumpFile != INVALID_HANDLE_VALUE )
{
MINIDUMP_EXCEPTION_INFORMATION ExpParam;
ExpParam.ThreadId = GetCurrentThreadId();
ExpParam.ExceptionPointers = ExceptionInfo;
ExpParam.ClientPointers = TRUE;

if ( MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithDataSegs, ExceptionInfo ? &ExpParam : NULL, NULL, NULL ) )
{
msg = QObject::tr( "minidump written to %1" ).arg( dumpName );
}
else
{
msg = QObject::tr( "writing of minidump to %1 failed (%2)" ).arg( dumpName ).arg( GetLastError(), 0, 16 );
}

CloseHandle( hDumpFile );
}
else
{
msg = QObject::tr( "creation of minidump to %1 failed (%2)" ).arg( dumpName ).arg( GetLastError(), 0, 16 );
}

QMessageBox::critical( 0, QObject::tr( "Crash dumped" ), msg );

return EXCEPTION_EXECUTE_HANDLER;
}
#endif

/*
* Hook into the qWarning/qFatal mechanism so that we can channel messages
Expand Down Expand Up @@ -227,6 +270,10 @@ int main( int argc, char *argv[] )
qInstallMsgHandler( myMessageOutput );
#endif

#ifdef Q_OS_WIN
SetUnhandledExceptionFilter( qgisCrashDump );
#endif

/////////////////////////////////////////////////////////////////
// Command line options 'behaviour' flag setup
////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -8483,6 +8483,13 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
{
stopRendering();
}
#if defined(Q_OS_WIN)&& defined(QGISDEBUG)
else if ( e->key() == Qt::Key_Backslash && e->modifiers() & Qt::ControlModifier )
{
extern LONG WINAPI qgisCrashDump( struct _EXCEPTION_POINTERS *ExceptionInfo );
qgisCrashDump( 0 );
}
#endif
else
{
e->ignore();
Expand Down

0 comments on commit 99fac00

Please sign in to comment.