From 7c35904062f3befdda1b91ca53e8891c9a80a85a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 13 May 2022 12:12:36 +0800 Subject: [PATCH] Use stacktrace dialog when GUI is enabled PR #17022. --- src/app/signalhandler.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/app/signalhandler.cpp b/src/app/signalhandler.cpp index d478dd690..841cc4c7c 100644 --- a/src/app/signalhandler.cpp +++ b/src/app/signalhandler.cpp @@ -36,11 +36,9 @@ #include #include -#ifndef Q_OS_WIN -#ifndef Q_OS_HAIKU +#ifdef Q_OS_UNIX #include -#endif -#elif defined DISABLE_GUI +#elif defined Q_OS_WIN #include #endif @@ -51,7 +49,7 @@ #ifdef STACKTRACE #include "stacktrace.h" -#if defined Q_OS_WIN && !defined DISABLE_GUI +#ifndef DISABLE_GUI #include "gui/stacktracedialog.h" #endif #endif //STACKTRACE @@ -74,7 +72,6 @@ namespace #endif }; -#if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU void safePrint(const char *str) { const size_t strLen = strlen(str); @@ -86,14 +83,11 @@ namespace std::ignore = write(STDOUT_FILENO, str, strLen); #endif } -#endif void normalExitHandler(const int signum) { -#if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU const char *msgs[] = {"Catching signal: ", sysSigName[signum], "\nExiting cleanly\n"}; std::for_each(std::begin(msgs), std::end(msgs), safePrint); -#endif // !defined Q_OS_WIN && !defined Q_OS_HAIKU signal(signum, SIG_DFL); QCoreApplication::exit(); // unsafe, but exit anyway } @@ -101,26 +95,19 @@ namespace #ifdef STACKTRACE void abnormalExitHandler(const int signum) { - const char *sigName = sysSigName[signum]; - -#if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU const char msg[] = "\n\n*************************************************************\n" "Please file a bug report at http://bug.qbittorrent.org and provide the following information:\n\n" "qBittorrent version: " QBT_VERSION "\n\n" "Caught signal: "; - const char *msgs[] = {msg, sigName, "\n"}; - std::for_each(std::begin(msgs), std::end(msgs), safePrint); + const char *sigName = sysSigName[signum]; + const std::string stacktrace = getStacktrace(); -#if !defined Q_OS_WIN - safePrint("```\n"); - safePrint(getStacktrace().c_str()); - safePrint("```\n\n"); -#endif -#endif + const char *msgs[] = {msg, sigName, "\n```\n", stacktrace.c_str(), "```\n\n"}; + std::for_each(std::begin(msgs), std::end(msgs), safePrint); -#if defined Q_OS_WIN && !defined DISABLE_GUI +#ifndef DISABLE_GUI StacktraceDialog dlg; // unsafe - dlg.setText(QString::fromLatin1(sigName), QString::fromStdString(getStacktrace())); + dlg.setText(QString::fromLatin1(sigName), QString::fromStdString(stacktrace)); dlg.exec(); #endif @@ -134,6 +121,7 @@ void registerSignalHandlers() { signal(SIGINT, normalExitHandler); signal(SIGTERM, normalExitHandler); + #ifdef STACKTRACE signal(SIGABRT, abnormalExitHandler); signal(SIGSEGV, abnormalExitHandler);