File indexing completed on 2024-04-21 05:26:41
0001 /* 0002 SPDX-FileCopyrightText: 2009 George Kiagiadakis <gkiagia@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef CRASHEDAPPLICATION_H 0008 #define CRASHEDAPPLICATION_H 0009 0010 #include <QDateTime> 0011 #include <QFileInfo> 0012 #include <QObject> 0013 0014 #include "bugreportaddress.h" 0015 0016 class KCrashBackend; 0017 0018 using EntriesHash = QHash<QByteArray, QByteArray>; 0019 0020 class CrashedApplication : public QObject 0021 { 0022 Q_OBJECT 0023 Q_PROPERTY(QString name READ name CONSTANT) 0024 Q_PROPERTY(QFileInfo executable READ executable CONSTANT) 0025 Q_PROPERTY(QString exectuableAbsoluteFilePath READ exectuableAbsoluteFilePath CONSTANT) 0026 Q_PROPERTY(QString fakeExecutableBaseName READ fakeExecutableBaseName CONSTANT) 0027 Q_PROPERTY(QString version READ version CONSTANT) 0028 Q_PROPERTY(QString bugReportAddress READ bugReportAddress CONSTANT) 0029 Q_PROPERTY(QString productName READ productName CONSTANT) 0030 Q_PROPERTY(int pid READ pid CONSTANT) 0031 Q_PROPERTY(int signalNumber READ signalNumber CONSTANT) 0032 Q_PROPERTY(QString signalName READ signalName CONSTANT) 0033 Q_PROPERTY(bool hasBeenRestarted READ hasBeenRestarted NOTIFY restarted) 0034 Q_PROPERTY(QDateTime datetime READ datetime CONSTANT) 0035 Q_PROPERTY(bool hasDeletedFiles READ hasDeletedFiles CONSTANT) 0036 public: 0037 CrashedApplication(int pid, 0038 int thread, 0039 int signalNumber, 0040 const QFileInfo &executable, 0041 const QString &version, 0042 const BugReportAddress &reportAddress, 0043 const QString &name = QString(), 0044 const QString &productName = QString(), 0045 const QDateTime &datetime = QDateTime::currentDateTime(), 0046 bool restarted = false, 0047 bool hasDeletedFiles = false, 0048 const QString &fakeBaseName = QString(), 0049 QObject *parent = nullptr); 0050 0051 ~CrashedApplication() override; 0052 0053 /** Returns the crashed program's name, possibly translated (ex. "The KDE Crash Handler") */ 0054 QString name() const; 0055 0056 /** Returns a QFileInfo with information about the executable that crashed */ 0057 QFileInfo executable() const; 0058 0059 /** convenience wrapper to make access from QML easier */ 0060 QString exectuableAbsoluteFilePath() const 0061 { 0062 return m_executable.absoluteFilePath(); 0063 } 0064 0065 /** When an application is run via kdeinit, the executable() method returns kdeinit4, but 0066 * we still need a way to know which is the application that was loaded by kdeinit. So, 0067 * this method returns the base name of the executable that would have been launched if 0068 * the app had not been loaded by kdeinit (ex. "plasma-desktop"). If the application was 0069 * not launched via kdeinit, this method returns executable().baseName(); 0070 */ 0071 QString fakeExecutableBaseName() const; 0072 0073 /** Returns the version of the crashed program */ 0074 QString version() const; 0075 0076 /** Returns the address where the bug report for this application should go */ 0077 BugReportAddress bugReportAddress() const; 0078 0079 /** Bugzilla product name, if the crashed application has explicitly specified that. */ 0080 QString productName() const; 0081 0082 /** Returns the pid of the crashed program */ 0083 int pid() const; 0084 0085 /** Returns the signal number that the crashed program received */ 0086 int signalNumber() const; 0087 0088 /** Returns the name of the signal (ex. SIGSEGV) */ 0089 QString signalName() const; 0090 0091 bool hasBeenRestarted() const; 0092 0093 int thread() const; 0094 0095 const QDateTime &datetime() const; 0096 0097 /** @returns whether mmap'd files have been deleted, e.g. updated since start of app */ 0098 bool hasDeletedFiles() const; 0099 0100 public Q_SLOTS: 0101 void restart(); 0102 0103 Q_SIGNALS: 0104 void restarted(bool success); 0105 0106 protected: 0107 int m_pid; 0108 int m_signalNumber; 0109 QString m_name; 0110 QFileInfo m_executable; 0111 QString m_fakeBaseName; 0112 QString m_version; 0113 BugReportAddress m_reportAddress; 0114 QString m_productName; 0115 bool m_restarted; 0116 int m_thread; 0117 QDateTime m_datetime; 0118 bool m_hasDeletedFiles; 0119 0120 public: 0121 // Only set for the 'coredumpd' backend. Path to on-disk core dump. 0122 QString m_coreFile; 0123 // Also only set for coredumpd backend. A bunch of log entries from journal. 0124 QList<EntriesHash> m_logs; 0125 }; 0126 0127 QString getSuggestedKCrashFilename(const CrashedApplication *app); 0128 0129 #endif // CRASHEDAPPLICATION_H