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 <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-09 12:23:52 +02:00
parent bdff3fa4e7
commit 7cfcbc3775
2 changed files with 6 additions and 4 deletions

View file

@ -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();

View file

@ -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)