File indexing completed on 2024-04-21 05:26:38
0001 /* 0002 SPDX-FileCopyrightText: 2009-2010 George Kiagiadakis <kiagiadakis.george@gmail.com> 0003 SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef BACKTRACEPARSER_H 0008 #define BACKTRACEPARSER_H 0009 0010 #include "backtraceline.h" 0011 #include <QMetaType> 0012 #include <QObject> 0013 #include <QSet> 0014 #include <QStringList> 0015 class BacktraceParserPrivate; 0016 0017 class BacktraceParser : public QObject 0018 { 0019 Q_OBJECT 0020 Q_DECLARE_PRIVATE(BacktraceParser) 0021 public: 0022 enum Usefulness { 0023 InvalidUsefulness, 0024 Useless, 0025 ProbablyUseless, 0026 MayBeUseful, 0027 ReallyUseful, 0028 }; 0029 Q_ENUM(Usefulness) 0030 0031 static BacktraceParser *newParser(const QString &debuggerName, QObject *parent = nullptr); 0032 ~BacktraceParser() override; 0033 0034 /*! Connects the parser to the backtrace generator. 0035 * Any QObject that defines the starting() and newLine(QString) signals will do. 0036 */ 0037 void connectToGenerator(QObject *generator); 0038 0039 /*! Returns the parsed backtrace. Any garbage that should not be shown to the user is removed. */ 0040 virtual QString parsedBacktrace() const; 0041 0042 /*! Same as parsedBacktrace(), but the backtrace here is returned as a list of 0043 * BacktraceLine objects, which provide extra information on each line. 0044 */ 0045 virtual QList<BacktraceLine> parsedBacktraceLines() const; 0046 0047 /*! Returns a simplified version of the backtrace. This backtrace: 0048 * \li Starts from the first useful function 0049 * \li Has maximum 5 lines 0050 * \li Replaces garbage with [...] 0051 */ 0052 virtual QString simplifiedBacktrace() const; 0053 0054 /*! Returns a value that indicates how much useful is the backtrace that we got */ 0055 Q_INVOKABLE virtual BacktraceParser::Usefulness backtraceUsefulness() const; 0056 0057 /*! Returns a list of libraries/executables that are missing debug symbols. */ 0058 Q_INVOKABLE virtual QStringList librariesWithMissingDebugSymbols() const; 0059 0060 /*! Check if the crash is because of the client aborting after a compositor crash. 0061 * https://bugs.kde.org/show_bug.cgi?id=431561 0062 */ 0063 bool hasCompositorCrashed() const; 0064 0065 QString informationLines() const; 0066 0067 private Q_SLOTS: 0068 void resetState(); 0069 void newLineInternal(const QString &lineStr); 0070 0071 protected Q_SLOTS: 0072 /*! Called every time there is a new line from the generator. Subclasses should parse 0073 * the line here and insert it in the m_linesList field of BacktraceParserPrivate. 0074 * If the line is useful for rating as well, it should also be inserted in the m_linesToRate 0075 * field, so that calculateRatingData() can use it. 0076 */ 0077 virtual void newLine(const QString &lineStr) = 0; 0078 0079 protected: 0080 explicit BacktraceParser(QObject *parent = nullptr); 0081 0082 /*! Subclasses should override to provide their own BacktraceParserPrivate instance */ 0083 virtual BacktraceParserPrivate *constructPrivate() const; 0084 0085 /*! This method should fill the m_usefulness, m_simplifiedBacktrace 0086 * and m_librariesWithMissingDebugSymbols members of the BacktraceParserPrivate instance. 0087 * The default implementation uses the lines inserted in m_linesToRate and applies a 0088 * generic algorithm that should work for many debuggers. 0089 */ 0090 virtual void calculateRatingData(); 0091 0092 BacktraceParserPrivate *d_ptr; 0093 }; 0094 0095 Q_DECLARE_METATYPE(BacktraceParser::Usefulness) 0096 0097 #endif // BACKTRACEPARSER_H