From 7cfcbc37756b999d4a312c640814da8c5a4965e0 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 9 Dec 2022 12:23:52 +0200 Subject: [PATCH] kdeui: new KCrash::Backtrace to log backtraces for programs that cannot call drkonqi to show backtrace (such as ksmserver or any non-GUI D-Bus service) Signed-off-by: Ivailo Monev --- kdeui/util/kcrash.cpp | 4 ++-- kdeui/util/kcrash.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kdeui/util/kcrash.cpp b/kdeui/util/kcrash.cpp index dbd80828..5bf8742c 100644 --- a/kdeui/util/kcrash.cpp +++ b/kdeui/util/kcrash.cpp @@ -58,7 +58,7 @@ static const int s_signals[] = { void KCrash::setFlags(KCrash::CrashFlags flags) { s_flags = flags; - if (s_flags & KCrash::AutoRestart || s_flags & KCrash::DrKonqi) { + if (s_flags & KCrash::AutoRestart || s_flags & KCrash::DrKonqi || s_flags & KCrash::Backtrace) { // Default crash handler is required for the flags to work but one may be set already if (!s_crashHandler) { KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde"); @@ -166,7 +166,7 @@ void KCrash::defaultCrashHandler(int sig) } ::system(systemargs.constData()); - } else { + } else if (s_flags & KCrash::Backtrace) { // NOTE: if HAVE_BACKTRACE is not defined kBacktrace() will return empty string #ifdef HAVE_BACKTRACE kError() << QCoreApplication::applicationName() << "crashed:\n" << kBacktrace(); diff --git a/kdeui/util/kcrash.h b/kdeui/util/kcrash.h index 84a561d7..a6e17ff2 100644 --- a/kdeui/util/kcrash.h +++ b/kdeui/util/kcrash.h @@ -84,12 +84,14 @@ namespace KCrash /** * Options to determine how the default crash handler should behave. - * @note AutoRestart takes priority over the other options even if they are set + * @note Options are prioritised in their numerical order, i.e. if + * AutoRestart is set all other options are ignored. */ enum CrashFlag { AutoRestart = 1, ///< autorestart this application. Only sensible for KUniqueApplications. @since 4.1. DrKonqi = 2, ///< launchers DrKonqi. @since 4.23. - NoRestart = 4 ///< tell DrKonqi not to restart the program. @since 4.23. + NoRestart = 4, ///< tell DrKonqi not to restart the program. @since 4.23. + Backtrace = 8 ///< log backtrace if the program crashes. @since 4.23. }; Q_DECLARE_FLAGS(CrashFlags, CrashFlag)