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

0001 /*****************************************************************
0002  * drkonqi - The KDE Crash Handler
0003  *
0004  * SPDX-FileCopyrightText: 2000-2003 Hans Petter Bieker <bieker@kde.org>
0005  * SPDX-FileCopyrightText: 2021 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 <QProcess>
0014 #include <QTemporaryFile>
0015 
0016 #include "debugger.h"
0017 
0018 class KProcess;
0019 class BacktraceParser;
0020 
0021 class BacktraceGenerator : public QObject
0022 {
0023     Q_OBJECT
0024 
0025     Q_PROPERTY(State state READ state NOTIFY stateChanged)
0026 public:
0027     enum State {
0028         NotLoaded,
0029         Loading,
0030         Loaded,
0031         Failed,
0032         FailedToStart,
0033     };
0034     Q_ENUM(State)
0035 
0036     BacktraceGenerator(const Debugger &debugger, QObject *parent);
0037     ~BacktraceGenerator() override;
0038 
0039     State state() const
0040     {
0041         return m_state;
0042     }
0043 
0044     Q_INVOKABLE BacktraceParser *parser() const
0045     {
0046         return m_parser;
0047     }
0048 
0049     Q_INVOKABLE QString backtrace() const
0050     {
0051         return m_parsedBacktrace;
0052     }
0053 
0054     // Called by manager when it is ready for us.
0055     void setBackendPrepared();
0056 
0057     Q_INVOKABLE bool debuggerIsGDB() const;
0058     Q_INVOKABLE QString debuggerName() const;
0059 
0060 public Q_SLOTS:
0061     void start();
0062 
0063 Q_SIGNALS:
0064     void starting();
0065     void newLine(const QString &str); // emitted for every line
0066     void someError();
0067     void failedToStart();
0068     void done();
0069     void preparing();
0070     void stateChanged();
0071 
0072 private Q_SLOTS:
0073     void slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus);
0074     void slotReadInput();
0075     void slotOnErrorOccurred(QProcess::ProcessError error);
0076 
0077 private:
0078     const Debugger m_debugger;
0079     KProcess *m_proc = nullptr;
0080     QTemporaryFile *m_temp = nullptr;
0081     QByteArray m_output;
0082     State m_state = NotLoaded;
0083     BacktraceParser *m_parser = nullptr;
0084     QString m_parsedBacktrace;
0085 
0086 #ifdef BACKTRACE_PARSER_DEBUG
0087     BacktraceParser *m_debugParser = nullptr;
0088 #endif
0089 };
0090 
0091 #endif