From 1f0521ea3090a0031906b6bb45a9718083b82a4b Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 13 Nov 2014 14:14:00 +0200 Subject: [PATCH] Catch exceptions on Winows if using Mingw compiler. --HG-- branch : develop --- Valentina.pri | 2 + src/app/app.pro | 23 +++++++-- src/app/main.cpp | 48 +++++++++++++++++++ src/app/stable.h | 18 +------ src/libs/qmuparser/qmuparser.pro | 14 ++++-- src/libs/vpropertyexplorer/stable.h | 17 ------- .../vpropertyexplorer/vpropertyexplorer.pro | 17 +++++-- 7 files changed, 92 insertions(+), 47 deletions(-) diff --git a/Valentina.pri b/Valentina.pri index 854a22269..584ba5c5e 100644 --- a/Valentina.pri +++ b/Valentina.pri @@ -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 } diff --git a/src/app/app.pro b/src/app/app.pro index 87857f750..e6e6e13c8 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -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} } } diff --git a/src/app/main.cpp b/src/app/main.cpp index a9a470cfd..79dfad9c8 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -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 diff --git a/src/app/stable.h b/src/app/stable.h index 5bd360ac9..695fe3df7 100644 --- a/src/app/stable.h +++ b/src/app/stable.h @@ -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 -# endif - -# ifdef QT_SVG_LIB -# include -# endif - -# ifdef QT_PRINTSUPPORT_LIB -# include -# endif -# endif/*QT_NO_DEBUG*/ -#else - +#if !defined(Q_OS_WIN) # ifdef QT_WIDGETS_LIB # include # endif diff --git a/src/libs/qmuparser/qmuparser.pro b/src/libs/qmuparser/qmuparser.pro index 0ec702b72..b5247f8ad 100644 --- a/src/libs/qmuparser/qmuparser.pro +++ b/src/libs/qmuparser/qmuparser.pro @@ -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} } } diff --git a/src/libs/vpropertyexplorer/stable.h b/src/libs/vpropertyexplorer/stable.h index 6390189fc..119249ac7 100644 --- a/src/libs/vpropertyexplorer/stable.h +++ b/src/libs/vpropertyexplorer/stable.h @@ -36,23 +36,6 @@ # include #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 -# endif - -# endif/*QT_NO_DEBUG*/ -#else - -# ifdef QT_WIDGETS_LIB -# include -# endif - -#endif/*Q_OS_WIN*/ - #endif /*__cplusplus*/ #endif // STABLE_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index a797ab03c..c0f8f0f2f 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -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} } }