File indexing completed on 2024-04-14 15:32:46

0001 /*
0002     SPDX-FileCopyrightText: 2009 George Kiagiadakis <gkiagia@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2021-2022 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     /// Supports dynamic symbol resolution
0056     bool supportsCommandWithSymbolResolution() const;
0057 
0058     /** Returns the command that should be run to use the debugger with symbol resolution enabled */
0059     QString commandWithSymbolResolution() const;
0060 
0061     /** Returns the commands that should be given to the debugger when
0062      * run in batch mode in order to generate a backtrace
0063      */
0064     QString backtraceBatchCommands() const;
0065 
0066     /** Returns the commands that should be given to the debugger before
0067      * getting the backtrace
0068      */
0069     QString preambleCommands() const;
0070 
0071     /** If this is an external debugger, it returns whether it should be run in a terminal or not */
0072     bool runInTerminal() const;
0073 
0074     /** Returns the value of the arbitrary configuration parameter @param key, or an empty QString if @param key isn't defined */
0075     QString backendValueOfParameter(const QString &key) const;
0076 
0077     enum ExpandStringUsage {
0078         ExpansionUsagePlainText,
0079         ExpansionUsageShell,
0080     };
0081 
0082     static void
0083     expandString(QString &str, ExpandStringUsage usage = ExpansionUsagePlainText, const QString &tempFile = QString(), const QString &preambleFile = QString());
0084 
0085     static Debugger findDebugger(const QList<Debugger> &debuggers, const QString &defaultDebuggerCodeName);
0086 
0087 private:
0088     // Similar to expandString but specifically for "staticish" expansion of commands with paths resolved at runtime.
0089     // Conceivably this could be changed to apply on (almost) every config read really.
0090     QString expandCommand(const QString &command) const;
0091     static QList<Debugger> availableDebuggers(const QString &path, const QString &backend);
0092     KSharedConfig::Ptr m_config;
0093     QString m_backend;
0094 };
0095 
0096 #endif