Catch exceptions on Winows if using Mingw compiler.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-13 14:14:00 +02:00
parent d8ead200a8
commit 1f0521ea30
7 changed files with 92 additions and 47 deletions

View File

@ -525,10 +525,12 @@ GCC_DEBUG_CXXFLAGS += \
-Wall \
-Wextra \
-pedantic \
-fno-omit-frame-pointer # Need for exchndl.dll
CLANG_DEBUG_CXXFLAGS += \
-O0 \
-Wall \
-Wextra \
-pedantic \
-fno-omit-frame-pointer # Need for exchndl.dll
}

View File

@ -145,9 +145,17 @@ CONFIG(debug, debug|release){
# Release mode
DEFINES += QT_NO_DEBUG_OUTPUT
!unix:*-g++{
QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll
}
# Turn on debug symbols in release mode on Unix systems.
# On Mac OS X temporarily disabled. Need find way how to strip binary file.
unix:!macx:QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
!macx:!win32-msvc*{
QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
QMAKE_CFLAGS_RELEASE += -g -gdwarf-3
QMAKE_LFLAGS_RELEASE =
}
#local revision number for using in version
HG_REV=$$system(hg parents --template '{rev}')
@ -369,11 +377,18 @@ DEPENDPATH += $${PWD}/../libs/vpropertyexplorer
# Strip after you link all libaries.
CONFIG(release, debug|release){
win32:!win32-msvc*{
# Strip debug symbols.
QMAKE_POST_LINK += objcopy --only-keep-debug bin/${TARGET} bin/${TARGET}.dbg &&
QMAKE_POST_LINK += objcopy --strip-debug bin/${TARGET} &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink="bin/${TARGET}.dbg" bin/${TARGET}
}
unix:!macx{
# Strip debug symbols.
QMAKE_POST_LINK += objcopy --only-keep-debug $(TARGET) $(TARGET).debug &&
QMAKE_POST_LINK += strip --strip-debug --strip-unneeded $(TARGET) &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink $(TARGET).debug $(TARGET)
QMAKE_POST_LINK += objcopy --only-keep-debug ${TARGET} ${TARGET}.dbg &&
QMAKE_POST_LINK += objcopy --strip-debug ${TARGET} &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink="${TARGET}.dbg" ${TARGET}
}
}

View File

@ -122,6 +122,48 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
}
}
//---------------------------------------------------------------------------------------------------------------------
// Catch exception and create report. Use if program build with Mingw compiler.
// See more about catcher https://github.com/jrfonseca/drmingw/blob/master/README.md
void DrMingw()
{
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
// Put exchndl.dll near binary file
QFile drmingw("exchndl.dll");
if(drmingw.exists())
{// If don't want create reports just delete exchndl.dll from installer
LoadLibrary(L"exchndl.dll");
}
#endif
}
//---------------------------------------------------------------------------------------------------------------------
// Check if last run was crash.
// Each new crash we will lose old crashes reports if don't move them in save place.
// See more about catcher https://github.com/jrfonseca/drmingw/blob/master/README.md
void CollectReport()
{
// Seek file "binary_name.RPT"
const QString reportName = QString("%1/%2.RPT").arg(qApp->applicationDirPath())
.arg(QFileInfo(qApp->arguments().at(0)).baseName());
QFile reportFile(reportName);
if (reportFile.exists())
{ // Hooray we have found crash
const QString reportsDir = QString("%1/reports").arg(qApp->applicationDirPath());
QDir reports(reportsDir);
if (reports.exists() == false)
{
reports.mkpath("."); // Create directory for reports if need
}
const QDateTime now = QDateTime::currentDateTime();
const QString timestamp = now.toString(QLatin1String("yyyyMMdd-hhmmsszzz"));
const QString filename = QString("%1/reports/crash-%2.RPT").arg(qApp->applicationDirPath()).arg(timestamp);
reportFile.copy(filename); // Collect new crash
reportFile.remove(); // Clear after yourself
}
}
//---------------------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
@ -133,6 +175,12 @@ int main(int argc, char *argv[])
QT_REQUIRE_VERSION(argc, argv, "5.0.2");
VApplication app(argc, argv);
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
DrMingw();
CollectReport();
#endif
#ifdef QT_DEBUG
// Because our "noisy" message handler uses the GUI subsystem for message
// boxes, we can't install it until after the QApplication is constructed. But it

View File

@ -54,23 +54,7 @@
#endif
//In Windows you can't use same header in all modes.
#if defined(Q_OS_WIN)
# if defined(QT_NO_DEBUG)//release mode
# ifdef QT_WIDGETS_LIB
# include <QtWidgets>
# endif
# ifdef QT_SVG_LIB
# include <QtSvg/QtSvg>
# endif
# ifdef QT_PRINTSUPPORT_LIB
# include <QtPrintSupport>
# endif
# endif/*QT_NO_DEBUG*/
#else
#if !defined(Q_OS_WIN)
# ifdef QT_WIDGETS_LIB
# include <QtWidgets>
# endif

View File

@ -103,14 +103,20 @@ CONFIG(debug, debug|release){
# Release mode
DEFINES += QT_NO_DEBUG_OUTPUT
unix:!macx{
!unix:*-g++{
QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll
}
!macx:!win32-msvc*{
# Turn on debug symbols in release mode on Unix systems.
# On Mac OS X temporarily disabled. TODO: find way how to strip binary file.
QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
QMAKE_CFLAGS_RELEASE += -g -gdwarf-3
QMAKE_LFLAGS_RELEASE =
# Strip debug symbols.
QMAKE_POST_LINK += objcopy --only-keep-debug $(DESTDIR)/$(TARGET) $(DESTDIR)/$(TARGET).debug &&
QMAKE_POST_LINK += strip --strip-debug --strip-unneeded $(DESTDIR)/$(TARGET) &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink $(DESTDIR)/$(TARGET).debug $(DESTDIR)/$(TARGET)
QMAKE_POST_LINK += objcopy --only-keep-debug bin/${TARGET} bin/${TARGET}.dbg &&
QMAKE_POST_LINK += objcopy --strip-debug bin/${TARGET} &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink="bin/${TARGET}.dbg" bin/${TARGET}
}
}

View File

@ -36,23 +36,6 @@
# include <QtCore>
#endif
//In Windows you can't use same header in all modes.
#if defined(Q_OS_WIN)
# if defined(QT_NO_DEBUG)//release mode
# ifdef QT_WIDGETS_LIB
# include <QtWidgets>
# endif
# endif/*QT_NO_DEBUG*/
#else
# ifdef QT_WIDGETS_LIB
# include <QtWidgets>
# endif
#endif/*Q_OS_WIN*/
#endif /*__cplusplus*/
#endif // STABLE_H

View File

@ -145,13 +145,20 @@ CONFIG(debug, debug|release){
# Release mode
DEFINES += QT_NO_DEBUG_OUTPUT
unix:!macx{
!unix:*-g++{
QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll
}
!macx:!win32-msvc*{
# Turn on debug symbols in release mode on Unix systems.
# On Mac OS X temporarily disabled. TODO: find way how to strip binary file.
QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
# On Linux
QMAKE_POST_LINK += objcopy --only-keep-debug $(DESTDIR)/$(TARGET) $(DESTDIR)/$(TARGET).debug &&
QMAKE_POST_LINK += strip --strip-debug --strip-unneeded $(DESTDIR)/$(TARGET) &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink $(DESTDIR)/$(TARGET).debug $(DESTDIR)/$(TARGET)
QMAKE_CFLAGS_RELEASE += -g -gdwarf-3
QMAKE_LFLAGS_RELEASE =
# Strip debug symbols.
QMAKE_POST_LINK += objcopy --only-keep-debug bin/${TARGET} bin/${TARGET}.dbg &&
QMAKE_POST_LINK += objcopy --strip-debug bin/${TARGET} &&
QMAKE_POST_LINK += objcopy --add-gnu-debuglink="bin/${TARGET}.dbg" bin/${TARGET}
}
}