File indexing completed on 2024-05-12 04:37:36

0001 /*
0002     SPDX-FileCopyrightText: 2009 Niko Sams <niko.sams@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_IDEBUGSESSION_H
0008 #define KDEVPLATFORM_IDEBUGSESSION_H
0009 
0010 #include <debugger/debuggerexport.h>
0011 
0012 #include <QObject>
0013 #include <QUrl>
0014 
0015 namespace KDevelop {
0016 
0017 class IVariableController;
0018 class IBreakpointController;
0019 class IFrameStackModel;
0020 class Breakpoint;
0021 class StackModel;
0022 class IDebugSessionPrivate;
0023 
0024 class KDEVPLATFORMDEBUGGER_EXPORT IDebugSession : public QObject
0025 {
0026     Q_OBJECT
0027 public:
0028     IDebugSession();
0029     ~IDebugSession() override;
0030 
0031     enum DebuggerState {
0032         NotStartedState,
0033         StartingState,
0034         ActiveState,
0035         PausedState,
0036         StoppingState,
0037         StoppedState,
0038         EndedState
0039     };
0040     Q_ENUM(DebuggerState)
0041 
0042     enum event_t {
0043         program_state_changed = 1,
0044         program_exited,
0045         debugger_exited,
0046         // Emitted when the thread or frame that is selected in UI
0047         // changes.
0048         thread_or_frame_changed,
0049         debugger_busy,
0050         debugger_ready,
0051         // Raised when debugger believe that program start running.
0052         // Can be used to hide current line indicator.
0053         // Don't count on this being raise in all cases where
0054         // program is running.
0055         program_running,
0056         // Raise when the debugger is in touch with the program,
0057         // and should have access to its debug symbols. The program
0058         // is not necessary running yet, or might already exited,
0059         // or be otherwise dead.
0060         connected_to_program
0061     };
0062 
0063 public:
0064     /**
0065      * Current state of the debug session
0066      */
0067     virtual DebuggerState state() const = 0;
0068 
0069     /**
0070      * Should return if restart is currently available
0071      */
0072     virtual bool restartAvaliable() const = 0;
0073 
0074     /**
0075      * Returns if the debugee is currently running. This includes paused.
0076      */
0077     bool isRunning() const;
0078     
0079     /**
0080      * Returns the local Url for a source file used in the current debug session.
0081      *
0082      * The default implementation just returns the url and is sufficient for
0083      * local debuggers. Remote debuggers can implement a path mapping mechanism.
0084      */
0085     virtual QPair<QUrl, int> convertToLocalUrl(const QPair<QUrl, int> &remoteUrl) const;
0086 
0087     /**
0088      * Returns the remote Url for a source file used in the current debug session.
0089      *
0090      * The default implementation just returns the url and is sufficient for
0091      * local debuggers. Remote debuggers can implement a path mapping mechanism.
0092      */
0093     virtual QPair<QUrl, int> convertToRemoteUrl(const QPair<QUrl, int> &localUrl) const;
0094 
0095     /**
0096      * @return the breakpoint controller of this session
0097      *
0098      * @note Implementations must ensure that a breakpoint controller always exists (even if it
0099      * is a dummy stub implementation that does nothing), and that it does not change during
0100      * the lifetime of a session.
0101      */
0102     virtual IBreakpointController* breakpointController() const = 0;
0103 
0104     /**
0105      * @return the variable controller of this session
0106      *
0107      * @note Implementations must ensure that a variable controller always exists (even if it
0108      * is a dummy stub implementation that does nothing), and that it does not change during
0109      * the lifetime of a session.
0110      */
0111     virtual IVariableController* variableController() const = 0;
0112 
0113     /**
0114      * @return the frame stack model of this session
0115      *
0116      * @note Implementations must ensure that a frame stack model always exists (even if it
0117      * is a dummy stub implementation that does nothing), and that it does not change during
0118      * the lifetime of a session.
0119      */
0120     virtual IFrameStackModel* frameStackModel() const = 0;
0121 
0122 public Q_SLOTS:
0123     virtual void restartDebugger() = 0;
0124     virtual void stopDebugger() = 0;
0125     /// @brief Kills the debugger process synchronously if it is still running.
0126     virtual void killDebuggerNow() = 0;
0127     virtual void interruptDebugger() = 0;
0128     virtual void run() = 0;
0129     virtual void runToCursor() = 0;
0130     virtual void jumpToCursor() = 0;
0131     virtual void stepOver() = 0;
0132     virtual void stepIntoInstruction() = 0;
0133     virtual void stepInto() = 0;
0134     virtual void stepOverInstruction() = 0;
0135     virtual void stepOut() = 0;
0136 
0137 Q_SIGNALS:
0138     void stateChanged(KDevelop::IDebugSession::DebuggerState state);
0139     void showStepInSource(const QUrl& file, int line, const QString &addr);
0140     void showStepInDisassemble(const QString &addr);
0141     void clearExecutionPoint();
0142     void finished();
0143 
0144     void raiseFramestackViews();
0145 
0146     /** This signal is emitted whenever the given event in a program
0147         happens. See DESIGN.txt for expected handled of each event.
0148 
0149         NOTE: this signal should never be emitted directly. Instead,
0150         use raiseEvent.
0151     */
0152     void event(IDebugSession::event_t e);
0153 
0154 public:
0155     using QObject::event; // prevent hiding of base method.
0156 
0157     QUrl currentUrl() const;
0158     int currentLine() const;
0159     QString currentAddr() const;
0160     
0161 protected:
0162 
0163     // Clear the position before running code
0164     void clearCurrentPosition();
0165     /// Sets new position and emits showStepInSource or showStepInDisassemble (if source file is unavailable) signal
0166     void setCurrentPosition(const QUrl& url, int line, const QString& addr);
0167 
0168     /** Raises the specified event. Should be used instead of
0169         emitting 'event' directly, since this method can perform
0170         additional book-keeping for events.
0171         FIXME: it might make sense to automatically route
0172         events to all debugger components, as opposed to requiring
0173         that they connect to any signal.
0174     */
0175     virtual void raiseEvent(event_t e);
0176     friend class FrameStackModel;
0177 
0178 private:
0179     friend class IDebugSessionPrivate;
0180     const QScopedPointer<class IDebugSessionPrivate> d_ptr;
0181     Q_DECLARE_PRIVATE(IDebugSession)
0182 };
0183 
0184 }
0185 
0186 #endif