File indexing completed on 2022-11-29 20:01:35

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 class CrashedApplication : public QObject
0019 {
0020     Q_OBJECT
0021     Q_PROPERTY(QString name READ name CONSTANT)
0022     Q_PROPERTY(QFileInfo executable READ executable CONSTANT)
0023     Q_PROPERTY(QString exectuableAbsoluteFilePath READ exectuableAbsoluteFilePath CONSTANT)
0024     Q_PROPERTY(QString fakeExecutableBaseName READ fakeExecutableBaseName CONSTANT)
0025     Q_PROPERTY(QString version READ version CONSTANT)
0026     Q_PROPERTY(QString bugReportAddress READ bugReportAddress CONSTANT)
0027     Q_PROPERTY(QString productName READ productName CONSTANT)
0028     Q_PROPERTY(int pid READ pid CONSTANT)
0029     Q_PROPERTY(int signalNumber READ signalNumber CONSTANT)
0030     Q_PROPERTY(QString signalName READ signalName CONSTANT)
0031     Q_PROPERTY(bool hasBeenRestarted READ hasBeenRestarted NOTIFY restarted)
0032     Q_PROPERTY(QDateTime datetime READ datetime CONSTANT)
0033     Q_PROPERTY(bool hasDeletedFiles READ hasDeletedFiles CONSTANT)
0034 public:
0035     CrashedApplication(int pid,
0036                        int thread,
0037                        int signalNumber,
0038                        const QFileInfo &executable,
0039                        const QString &version,
0040                        const BugReportAddress &reportAddress,
0041                        const QString &name = QString(),
0042                        const QString &productName = QString(),
0043                        const QDateTime &datetime = QDateTime::currentDateTime(),
0044                        bool restarted = false,
0045                        bool hasDeletedFiles = false,
0046                        const QString &fakeBaseName = QString(),
0047                        QObject *parent = nullptr);
0048 
0049     ~CrashedApplication() override;
0050 
0051     /** Returns the crashed program's name, possibly translated (ex. "The KDE Crash Handler") */
0052     QString name() const;
0053 
0054     /** Returns a QFileInfo with information about the executable that crashed */
0055     QFileInfo executable() const;
0056 
0057     /** convenience wrapper to make access from QML easier */
0058     QString exectuableAbsoluteFilePath() const
0059     {
0060         return m_executable.absoluteFilePath();
0061     }
0062 
0063     /** When an application is run via kdeinit, the executable() method returns kdeinit4, but
0064      * we still need a way to know which is the application that was loaded by kdeinit. So,
0065      * this method returns the base name of the executable that would have been launched if
0066      * the app had not been loaded by kdeinit (ex. "plasma-desktop"). If the application was
0067      * not launched via kdeinit, this method returns executable().baseName();
0068      */
0069     QString fakeExecutableBaseName() const;
0070 
0071     /** Returns the version of the crashed program */
0072     QString version() const;
0073 
0074     /** Returns the address where the bug report for this application should go */
0075     BugReportAddress bugReportAddress() const;
0076 
0077     /** Bugzilla product name, if the crashed application has explicitly specified that. */
0078     QString productName() const;
0079 
0080     /** Returns the pid of the crashed program */
0081     int pid() const;
0082 
0083     /** Returns the signal number that the crashed program received */
0084     int signalNumber() const;
0085 
0086     /** Returns the name of the signal (ex. SIGSEGV) */
0087     QString signalName() const;
0088 
0089     bool hasBeenRestarted() const;
0090 
0091     int thread() const;
0092 
0093     const QDateTime &datetime() const;
0094 
0095     /** @returns whether mmap'd files have been deleted, e.g. updated since start of app */
0096     bool hasDeletedFiles() const;
0097 
0098 public Q_SLOTS:
0099     void restart();
0100 
0101 Q_SIGNALS:
0102     void restarted(bool success);
0103 
0104 protected:
0105     int m_pid;
0106     int m_signalNumber;
0107     QString m_name;
0108     QFileInfo m_executable;
0109     QString m_fakeBaseName;
0110     QString m_version;
0111     BugReportAddress m_reportAddress;
0112     QString m_productName;
0113     bool m_restarted;
0114     int m_thread;
0115     QDateTime m_datetime;
0116     bool m_hasDeletedFiles;
0117 
0118 public:
0119     // Only set for the 'coredumpd' backend. Path to on-disk core dump.
0120     QString m_coreFile;
0121 };
0122 
0123 QString getSuggestedKCrashFilename(const CrashedApplication *app);
0124 
0125 #endif // CRASHEDAPPLICATION_H