File indexing completed on 2022-11-23 12:12:12

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 DEBUGGER_H
0008 #define DEBUGGER_H
0009 
0010 #include <QString>
0011 
0012 #include <KSharedConfig>
0013 
0014 class Debugger
0015 {
0016 public:
0017     static QList<Debugger> availableInternalDebuggers(const QString &backend);
0018     static QList<Debugger> availableExternalDebuggers(const QString &backend);
0019 
0020     /** Returns true if this Debugger instance is valid, or false otherwise.
0021      * Debugger instances are valid only if they have been constructed from
0022      * availableInternalDebuggers() or availableExternalDebuggers(). If they
0023      * have been constructed directly using the Debugger constructor, they are invalid.
0024      */
0025     bool isValid() const;
0026 
0027     /** Returns true if this debugger is installed. This is determined by
0028      * looking for the executable that tryExec() returns. If it is in $PATH,
0029      * this method returns true.
0030      */
0031     bool isInstalled() const;
0032 
0033     /** Returns the translatable name of the debugger (eg. "GDB") */
0034     QString displayName() const;
0035 
0036     /** Returns the code name of the debugger (eg. "gdb"). */
0037     QString codeName() const;
0038 
0039     /** Returns the executable name that drkonqi should check if it exists
0040      * to determine whether the debugger is installed
0041      */
0042     QString tryExec() const;
0043 
0044     /** Returns a list with the drkonqi backends that this debugger supports */
0045     QStringList supportedBackends() const;
0046 
0047     /** Sets the backend to be used. This function must be called before using
0048      * command(), backtraceBatchCommands() or runInTerminal().
0049      */
0050     void setUsedBackend(const QString &backendName);
0051 
0052     /** Returns the command that should be run to use the debugger */
0053     QString command() const;
0054 
0055     /** Returns the commands that should be given to the debugger when
0056      * run in batch mode in order to generate a backtrace
0057      */
0058     QString backtraceBatchCommands() const;
0059 
0060     /** Returns the commands that should be given to the debugger before
0061      * getting the backtrace
0062      */
0063     QString preambleCommands() const;
0064 
0065     /** If this is an external debugger, it returns whether it should be run in a terminal or not */
0066     bool runInTerminal() const;
0067 
0068     /** Returns the value of the arbitrary configuration parameter @param key, or an empty QString if @param key isn't defined */
0069     QString backendValueOfParameter(const QString &key) const;
0070 
0071     enum ExpandStringUsage {
0072         ExpansionUsagePlainText,
0073         ExpansionUsageShell,
0074     };
0075 
0076     static void
0077     expandString(QString &str, ExpandStringUsage usage = ExpansionUsagePlainText, const QString &tempFile = QString(), const QString &preambleFile = QString());
0078 
0079     static Debugger findDebugger(const QList<Debugger> &debuggers, const QString &defaultDebuggerCodeName);
0080 
0081 private:
0082     // Similar to expandString but specifically for "staticish" expansion of commands with paths resolved at runtime.
0083     // Conceivably this could be changed to apply on (almost) every config read really.
0084     QString expandCommand(const QString &command) const;
0085     static QList<Debugger> availableDebuggers(const QString &path, const QString &backend);
0086     KSharedConfig::Ptr m_config;
0087     QString m_backend;
0088 };
0089 
0090 #endif