| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QV4DEBUGGERAGENT_H |
| 5 | #define QV4DEBUGGERAGENT_H |
| 6 | |
| 7 | #include "qv4debugger.h" |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | class QV4DebugServiceImpl; |
| 12 | |
| 13 | class QV4DebuggerAgent : public QObject |
| 14 | { |
| 15 | Q_OBJECT |
| 16 | public: |
| 17 | QV4DebuggerAgent(QV4DebugServiceImpl *debugService) : m_debugService(debugService) {} |
| 18 | |
| 19 | QV4Debugger *pausedDebugger() const; |
| 20 | bool isRunning() const; |
| 21 | |
| 22 | void addDebugger(QV4Debugger *debugger); |
| 23 | void removeDebugger(QV4Debugger *debugger); |
| 24 | const QList<QV4Debugger *> &debuggers(); |
| 25 | |
| 26 | void pause(QV4Debugger *debugger) const; |
| 27 | void pauseAll() const; |
| 28 | void resumeAll() const; |
| 29 | int addBreakPoint(const QString &fileName, int lineNumber, bool enabled = true, const QString &condition = QString()); |
| 30 | void removeBreakPoint(int id); |
| 31 | void removeAllBreakPoints(); |
| 32 | void enableBreakPoint(int id, bool onoff); |
| 33 | QList<int> breakPointIds(const QString &fileName, int lineNumber) const; |
| 34 | |
| 35 | bool breakOnThrow() const { return m_breakOnThrow; } |
| 36 | void setBreakOnThrow(bool onoff); |
| 37 | void clearAllPauseRequests(); |
| 38 | |
| 39 | void debuggerPaused(QV4Debugger *debugger, QV4Debugger::PauseReason reason); |
| 40 | void handleDebuggerDeleted(QObject *debugger); |
| 41 | |
| 42 | private: |
| 43 | QList<QV4Debugger *> m_debuggers; |
| 44 | |
| 45 | struct BreakPoint { |
| 46 | QString fileName; |
| 47 | int lineNr; |
| 48 | bool enabled; |
| 49 | QString condition; |
| 50 | |
| 51 | BreakPoint(): lineNr(-1), enabled(false) {} |
| 52 | BreakPoint(const QString &fileName, int lineNr, bool enabled, const QString &condition) |
| 53 | : fileName(fileName), lineNr(lineNr), enabled(enabled), condition(condition) |
| 54 | {} |
| 55 | |
| 56 | bool isValid() const { return lineNr >= 0 && !fileName.isEmpty(); } |
| 57 | }; |
| 58 | |
| 59 | QHash<int, BreakPoint> m_breakPoints; |
| 60 | int m_lastBreakPointId = 0; |
| 61 | bool m_breakOnThrow = false; |
| 62 | QV4DebugServiceImpl *m_debugService = nullptr; |
| 63 | }; |
| 64 | |
| 65 | QT_END_NAMESPACE |
| 66 | |
| 67 | #endif // QV4DEBUGGERAGENT_H |
| 68 | |