File indexing completed on 2021-12-21 13:15:51

0001 /*
0002  * XDebug Debugger Support
0003  *
0004  * Copyright 2009 Niko Sams <niko.sams@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of the
0009  * License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public
0017  * License along with this program; if not, write to the
0018  * Free Software Foundation, Inc.,
0019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0020  */
0021 
0022 #ifndef XDEBUG_DEBUGSESSION_H
0023 #define XDEBUG_DEBUGSESSION_H
0024 
0025 #include <QString>
0026 #include <debugger/interfaces/idebugsession.h>
0027 
0028 namespace KDevelop {
0029 class ILaunchConfiguration;
0030 }
0031 class KJob;
0032 class QTcpServer;
0033 class KProcess;
0034 
0035 namespace XDebug {
0036 class BreakpointController;
0037 class FrameStackModel;
0038 class VariableController;
0039 class Connection;
0040 
0041 class DebugSession
0042     : public KDevelop::IDebugSession
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     DebugSession();
0048     ~DebugSession() override;
0049 
0050     void setLaunchConfiguration(KDevelop::ILaunchConfiguration* cfg);
0051     void setAcceptMultipleConnections(bool v);
0052 
0053     bool listenForConnection(QString& error);
0054 
0055     bool waitForState(DebuggerState state, int msecs = 30000);
0056     bool waitForFinished(int msecs = 30000);
0057     bool waitForConnected(int msecs = 30000);
0058 
0059     Connection* connection();
0060 
0061     DebuggerState state() const override;
0062 
0063     bool restartAvaliable() const override;
0064 
0065     QPair<QUrl, int> convertToLocalUrl(const QPair<QUrl, int>& url) const override;
0066     QPair<QUrl, int> convertToRemoteUrl(const QPair<QUrl, int>& url) const override;
0067 
0068     KDevelop::IBreakpointController* breakpointController() const override;
0069     KDevelop::IVariableController* variableController() const override;
0070     KDevelop::IFrameStackModel* frameStackModel() const override;
0071 
0072 Q_SIGNALS:
0073     void output(QString line);
0074     void outputLine(QString line);
0075 
0076 public Q_SLOTS:
0077     void run() override;
0078     void stepOut() override;
0079     void stepOverInstruction() override;
0080     void stepInto() override;
0081     void stepIntoInstruction() override;
0082     void stepOver() override;
0083     void jumpToCursor() override;
0084     void runToCursor() override;
0085     void interruptDebugger() override;
0086     void stopDebugger() override;
0087     void killDebuggerNow() override;
0088     void restartDebugger() override;
0089 
0090     void eval(QByteArray source);
0091 
0092 private Q_SLOTS:
0093     void incomingConnection();
0094     void _stateChanged(KDevelop::IDebugSession::DebuggerState);
0095     void connectionClosed();
0096     void currentPositionChanged(const QUrl& url, int line);
0097 
0098 private:
0099     void closeServer();
0100 
0101 private:
0102     BreakpointController* m_breakpointController;
0103     VariableController* m_variableController;
0104     FrameStackModel* m_frameStackModel;
0105 
0106     QTcpServer* m_server;
0107     Connection* m_connection;
0108     KDevelop::ILaunchConfiguration* m_launchConfiguration;
0109     bool m_acceptMultipleConnections;
0110 };
0111 }
0112 
0113 #endif // XDEBUG_DEBUGSESSION_H