Skip to content
Permalink
Browse files

windows: generate minidump on crash

  • Loading branch information
jef-n committed Apr 20, 2013
1 parent e5366b0 commit 99fac00c0b8ee6016fcb96a897e39b8543d76146
Showing with 57 additions and 2 deletions.
  1. +2 −1 src/app/CMakeLists.txt
  2. +48 −1 src/app/main.cpp
  3. +7 −0 src/app/qgisapp.cpp
@@ -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)
@@ -31,6 +31,7 @@
#include <QPlastiqueStyle>
#include <QTranslator>
#include <QImageReader>
#include <QMessageBox>

#include "qgscustomization.h"
#include "qgspluginregistry.h"
@@ -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;
@@ -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
@@ -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
@@ -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
////////////////////////////////////////////////////////////////
@@ -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();

0 comments on commit 99fac00

Please sign in to comment.
You can’t perform that action at this time.