File indexing completed on 2023-09-24 05:44:48

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 short list of the first good functions that appear in the backtrace
0058      * (in the crashing thread). This is used for quering for duplicate reports.
0059      */
0060     Q_INVOKABLE virtual QStringList firstValidFunctions() const;
0061 
0062     /*! Returns a list of libraries/executables that are missing debug symbols. */
0063     Q_INVOKABLE virtual QStringList librariesWithMissingDebugSymbols() const;
0064 
0065     /*! Check if the crash is because of the client aborting after a compositor crash.
0066      * https://bugs.kde.org/show_bug.cgi?id=431561
0067      */
0068     bool hasCompositorCrashed() const;
0069 
0070     QString informationLines() const;
0071 
0072 private Q_SLOTS:
0073     void resetState();
0074 
0075 protected Q_SLOTS:
0076     /*! Called every time there is a new line from the generator. Subclasses should parse
0077      * the line here and insert it in the m_linesList field of BacktraceParserPrivate.
0078      * If the line is useful for rating as well, it should also be inserted in the m_linesToRate
0079      * field, so that calculateRatingData() can use it.
0080      */
0081     virtual void newLine(const QString &lineStr) = 0;
0082 
0083 protected:
0084     explicit BacktraceParser(QObject *parent = nullptr);
0085 
0086     /*! Subclasses should override to provide their own BacktraceParserPrivate instance */
0087     virtual BacktraceParserPrivate *constructPrivate() const;
0088 
0089     /*! This method should fill the m_usefulness, m_simplifiedBacktrace, m_firstValidFunctions
0090      * and m_librariesWithMissingDebugSymbols members of the BacktraceParserPrivate instance.
0091      * The default implementation uses the lines inserted in m_linesToRate and applies a
0092      * generic algorithm that should work for many debuggers.
0093      */
0094     virtual void calculateRatingData();
0095 
0096     BacktraceParserPrivate *d_ptr;
0097 };
0098 
0099 Q_DECLARE_METATYPE(BacktraceParser::Usefulness)
0100 
0101 #endif // BACKTRACEPARSER_H