File indexing completed on 2024-12-01 11:06:28
0001 /***************************************************************** 0002 * drkonqi - The KDE Crash Handler 0003 * 0004 * SPDX-FileCopyrightText: 2000-2003 Hans Petter Bieker <bieker@kde.org> 0005 * SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org> 0006 * 0007 * SPDX-License-Identifier: BSD-2-Clause 0008 *****************************************************************/ 0009 0010 #ifndef BACKTRACEGENERATOR_H 0011 #define BACKTRACEGENERATOR_H 0012 0013 #include <memory> 0014 0015 #include <QProcess> 0016 #include <QTemporaryFile> 0017 0018 #include "debugger.h" 0019 0020 class KProcess; 0021 class BacktraceParser; 0022 class QTemporaryDir; 0023 0024 class BacktraceGenerator : public QObject 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(State state READ state NOTIFY stateChanged) 0029 Q_PROPERTY(bool supportsSymbolResolution MEMBER m_supportsSymbolResolution CONSTANT) 0030 Q_PROPERTY(bool symbolResolution MEMBER m_symbolResolution NOTIFY symbolResolutionChanged) 0031 public: 0032 enum State { 0033 NotLoaded, 0034 Loading, 0035 Loaded, 0036 Failed, 0037 FailedToStart, 0038 }; 0039 Q_ENUM(State) 0040 0041 BacktraceGenerator(const Debugger &debugger, QObject *parent); 0042 ~BacktraceGenerator() override; 0043 0044 State state() const 0045 { 0046 return m_state; 0047 } 0048 0049 Q_INVOKABLE BacktraceParser *parser() const 0050 { 0051 return m_parser; 0052 } 0053 0054 Q_INVOKABLE QString backtrace() const 0055 { 0056 return m_parsedBacktrace; 0057 } 0058 0059 // Called by manager when it is ready for us. 0060 void setBackendPrepared(); 0061 0062 Q_INVOKABLE bool debuggerIsGDB() const; 0063 Q_INVOKABLE QString debuggerName() const; 0064 QByteArray sentryPayload() const; 0065 0066 public Q_SLOTS: 0067 void start(); 0068 0069 Q_SIGNALS: 0070 void starting(); 0071 void newLine(const QString &str); // emitted for every line 0072 void someError(); 0073 void failedToStart(); 0074 void done(); 0075 void preparing(); 0076 void stateChanged(); 0077 void symbolResolutionChanged(); 0078 0079 private Q_SLOTS: 0080 void slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus); 0081 void slotReadInput(); 0082 void slotOnErrorOccurred(QProcess::ProcessError error); 0083 0084 private: 0085 const Debugger m_debugger; 0086 KProcess *m_proc = nullptr; 0087 QTemporaryFile *m_temp = nullptr; 0088 QByteArray m_output; 0089 State m_state = NotLoaded; 0090 BacktraceParser *m_parser = nullptr; 0091 QString m_parsedBacktrace; 0092 std::unique_ptr<QTemporaryDir> m_tempDirectory; 0093 const bool m_supportsSymbolResolution = false; 0094 bool m_symbolResolution = false; 0095 0096 #ifdef BACKTRACE_PARSER_DEBUG 0097 BacktraceParser *m_debugParser = nullptr; 0098 #endif 0099 }; 0100 0101 #endif