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

0001 /*
0002     SPDX-FileCopyrightText: 2009 George Kiagiadakis <gkiagia@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #ifndef DRKONQIBACKENDS_H
0008 #define DRKONQIBACKENDS_H
0009 
0010 #include <QObject>
0011 
0012 class CrashedApplication;
0013 class DebuggerManager;
0014 
0015 class AbstractDrKonqiBackend : public QObject
0016 {
0017     Q_OBJECT
0018 public:
0019     using QObject::QObject;
0020     virtual ~AbstractDrKonqiBackend();
0021     virtual bool init();
0022     virtual void prepareForDebugger();
0023     void cleanup(); // cleanup on-disk caches
0024 
0025     inline CrashedApplication *crashedApplication() const
0026     {
0027         return m_crashedApplication;
0028     }
0029 
0030     inline DebuggerManager *debuggerManager() const
0031     {
0032         return m_debuggerManager;
0033     }
0034 
0035     static QString metadataPath();
0036 
0037 Q_SIGNALS:
0038     void preparedForDebugger();
0039 
0040 protected:
0041     virtual CrashedApplication *constructCrashedApplication() = 0;
0042     virtual DebuggerManager *constructDebuggerManager() = 0;
0043 
0044 private:
0045     CrashedApplication *m_crashedApplication = nullptr;
0046     DebuggerManager *m_debuggerManager = nullptr;
0047 };
0048 
0049 class KCrashBackend : public AbstractDrKonqiBackend
0050 {
0051     Q_OBJECT
0052 public:
0053     using AbstractDrKonqiBackend::AbstractDrKonqiBackend;
0054     ~KCrashBackend() override;
0055 
0056     bool init() override;
0057 
0058 protected:
0059     CrashedApplication *constructCrashedApplication() override;
0060     DebuggerManager *constructDebuggerManager() override;
0061 
0062 private Q_SLOTS:
0063     void stopAttachedProcess();
0064     void continueAttachedProcess();
0065     void onDebuggerStarting();
0066     void onDebuggerFinished();
0067 
0068 private:
0069     static void emergencySaveFunction(int signal);
0070     static qint64 s_pid; // for use by the emergencySaveFunction
0071 
0072     enum State { ProcessRunning, ProcessStopped, DebuggerRunning };
0073     State m_state = ProcessRunning;
0074 };
0075 
0076 #endif // DRKONQIBACKENDS_H