From 636daddc61b3ac3e9eecbaaac02b5103357ec158 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 1 Apr 2021 16:15:50 +1100 Subject: [PATCH] cleaned up crashpad code --- app/common/crashpadinterface.cpp | 7 +--- app/common/filefunctions.cpp | 9 +++++ app/common/filefunctions.h | 2 ++ app/dialog/crashhandler/crashhandler.cpp | 46 ++++++++++++------------ app/dialog/crashhandler/crashhandler.h | 2 ++ 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/common/crashpadinterface.cpp b/app/common/crashpadinterface.cpp index 735d8d3ab..300a12b86 100644 --- a/app/common/crashpadinterface.cpp +++ b/app/common/crashpadinterface.cpp @@ -71,12 +71,7 @@ bool LinuxExceptionHandler(int, siginfo_t*, ucontext_t*) bool InitializeCrashpad() { - QString handler_fn = QStringLiteral("crashpad_handler");; - - // Determine filename of handler from platform -#ifdef OS_WIN - handler_fn.append(QStringLiteral(".exe")); -#endif + QString handler_fn = olive::FileFunctions::GetFormattedExecutableForPlatform(QStringLiteral("crashpad_handler")); // Generate absolute path QString handler_abs_path = QDir(QCoreApplication::applicationDirPath()).filePath(handler_fn); diff --git a/app/common/filefunctions.cpp b/app/common/filefunctions.cpp index 31fe563b1..d3fe94c7d 100644 --- a/app/common/filefunctions.cpp +++ b/app/common/filefunctions.cpp @@ -240,4 +240,13 @@ bool FileFunctions::RenameFileAllowOverwrite(const QString &from, const QString return true; } +QString FileFunctions::GetFormattedExecutableForPlatform(QString unformatted) +{ +#ifdef Q_OS_WINDOWS + unformatted.append(QStringLiteral(".exe")); +#endif + + return unformatted; +} + } diff --git a/app/common/filefunctions.h b/app/common/filefunctions.h index 124d42b17..6270298b2 100644 --- a/app/common/filefunctions.h +++ b/app/common/filefunctions.h @@ -84,6 +84,8 @@ public: */ static bool RenameFileAllowOverwrite(const QString& from, const QString& to); + static QString GetFormattedExecutableForPlatform(QString unformatted); + }; diff --git a/app/dialog/crashhandler/crashhandler.cpp b/app/dialog/crashhandler/crashhandler.cpp index 1e58633b3..197d23f99 100644 --- a/app/dialog/crashhandler/crashhandler.cpp +++ b/app/dialog/crashhandler/crashhandler.cpp @@ -37,6 +37,7 @@ #include #include "common/crashpadutils.h" +#include "common/filefunctions.h" namespace olive { @@ -107,6 +108,21 @@ void CrashHandlerDialog::SetGUIObjectsEnabled(bool e) dont_send_btn_->setEnabled(e); } +QString CrashHandlerDialog::GetSymbolPath() +{ + QString symbols_path; + +#if defined(OS_WIN) + symbols_path = app_path.filePath(QStringLiteral("symbols")); +#elif defined(OS_LINUX) + symbols_path = app_path.filePath(QStringLiteral("../share/olive-editor/symbols")); +#elif defined(OS_APPLE) + symbols_path = app_path.filePath(QStringLiteral("../Resources/symbols")); +#endif + + return symbols_path; +} + void CrashHandlerDialog::GenerateReport() { QProcess* p = new QProcess(); @@ -117,18 +133,10 @@ void CrashHandlerDialog::GenerateReport() QDir app_path(qApp->applicationDirPath()); - QString stackwalk_filename = QStringLiteral("minidump_stackwalk"); - QString symbols_path; - -#if defined(OS_WIN) - stackwalk_filename.append(QStringLiteral(".exe")); - symbols_path = app_path.filePath(QStringLiteral("symbols")); -#elif defined(Q_OS_LINUX) - symbols_path = app_path.filePath(QStringLiteral("../share/olive-editor/symbols")); -#endif + QString stackwalk_filename = FileFunctions::GetFormattedExecutableForPlatform(QStringLiteral("minidump_stackwalk")); QString stackwalk_bin = app_path.filePath(stackwalk_filename); - p->start(stackwalk_bin, {report_filename_, symbols_path}); + p->start(stackwalk_bin, {report_filename_, GetSymbolPath()}); crash_report_->setText(QStringLiteral("Trying to run: %1").arg(stackwalk_bin)); } @@ -237,25 +245,17 @@ void CrashHandlerDialog::SendErrorReport() multipart->append(dump_part); // Find symbol file - QDir symbol_dir(QDir(qApp->applicationDirPath()).filePath(QStringLiteral("symbols"))); + QDir symbol_dir(GetSymbolPath()); #ifdef Q_OS_WINDOWS symbol_dir = QDir(symbol_dir.filePath(QStringLiteral("olive-editor.pdb"))); #else symbol_dir = QDir(symbol_dir.filePath(QStringLiteral("olive-editor"))); #endif - QStringList folders_in_symbol_path = symbol_dir.entryList(); + QStringList folders_in_symbol_path = symbol_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - bool found = false; - foreach (const QString& symbol_folder, folders_in_symbol_path) { - if (!symbol_folder.startsWith('.')) { - // Assume that the first folder we find is the one with the symbols in it - symbol_dir = QDir(symbol_dir.filePath(symbol_folder)); - found = true; - break; - } - } - - if (!found) { + if (folders_in_symbol_path.size() > 0) { + symbol_dir = QDir(symbol_dir.filePath(folders_in_symbol_path.first())); + } else { QMessageBox::critical(this, tr("Failed to send report"), tr("Failed to find symbols necessary to send report. " "This is a packaging issue. Please notify " "the maintainers of this package.")); diff --git a/app/dialog/crashhandler/crashhandler.h b/app/dialog/crashhandler/crashhandler.h index bc226c9a8..058bb93fe 100644 --- a/app/dialog/crashhandler/crashhandler.h +++ b/app/dialog/crashhandler/crashhandler.h @@ -43,6 +43,8 @@ private: void GenerateReport(); + static QString GetSymbolPath(); + QTextEdit* summary_edit_; QTextEdit* crash_report_;