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 QV4DEBUGGER_H |
5 | #define QV4DEBUGGER_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qv4datacollector.h" |
19 | #include <private/qv4debugging_p.h> |
20 | #include <private/qv4function_p.h> |
21 | #include <private/qv4context_p.h> |
22 | #include <private/qv4persistent_p.h> |
23 | |
24 | #include <QtCore/qmutex.h> |
25 | #include <QtCore/qwaitcondition.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QV4DebugJob; |
30 | class QV4DataCollector; |
31 | class QV4Debugger : public QV4::Debugging::Debugger |
32 | { |
33 | Q_OBJECT |
34 | public: |
35 | struct BreakPoint { |
36 | BreakPoint(const QString &fileName, int line); |
37 | QString fileName; |
38 | int lineNumber; |
39 | }; |
40 | |
41 | enum State { |
42 | Running, |
43 | Paused |
44 | }; |
45 | |
46 | enum Speed { |
47 | FullThrottle = 0, |
48 | StepOut, |
49 | StepOver, |
50 | StepIn, |
51 | |
52 | NotStepping = FullThrottle |
53 | }; |
54 | |
55 | enum PauseReason { |
56 | PauseRequest, |
57 | BreakPointHit, |
58 | Throwing, |
59 | Step |
60 | }; |
61 | |
62 | QV4Debugger(QV4::ExecutionEngine *engine); |
63 | |
64 | QV4::ExecutionEngine *engine() const; |
65 | const QV4DataCollector *collector() const; |
66 | QV4DataCollector *collector(); |
67 | |
68 | void pause(); |
69 | void resume(Speed speed); |
70 | |
71 | State state() const; |
72 | |
73 | void addBreakPoint(const QString &fileName, int lineNumber, |
74 | const QString &condition = QString()); |
75 | void removeBreakPoint(const QString &fileName, int lineNumber); |
76 | |
77 | void setBreakOnThrow(bool onoff); |
78 | |
79 | void clearPauseRequest(); |
80 | |
81 | // used for testing |
82 | struct ExecutionState |
83 | { |
84 | QString fileName; |
85 | int lineNumber; |
86 | }; |
87 | ExecutionState currentExecutionState() const; |
88 | |
89 | QVector<QV4::StackFrame> stackTrace(int frameLimit = -1) const; |
90 | QVector<QV4::Heap::ExecutionContext::ContextType> getScopeTypes(int frame = 0) const; |
91 | |
92 | QV4::Function *getFunction() const; |
93 | void runInEngine(QV4DebugJob *job); |
94 | |
95 | // compile-time interface |
96 | void maybeBreakAtInstruction() override; |
97 | |
98 | // execution hooks |
99 | void enteringFunction() override; |
100 | void leavingFunction(const QV4::ReturnedValue &retVal) override; |
101 | void aboutToThrow() override; |
102 | |
103 | bool pauseAtNextOpportunity() const override; |
104 | |
105 | Q_SIGNALS: |
106 | void debuggerPaused(QV4Debugger *self, QV4Debugger::PauseReason reason); |
107 | void scheduleJob(); |
108 | |
109 | private: |
110 | // requires lock to be held |
111 | void pauseAndWait(PauseReason reason); |
112 | bool reallyHitTheBreakPoint(const QString &filename, int linenr); |
113 | void runInEngine_havingLock(QV4DebugJob *job); |
114 | void runJobUnpaused(); |
115 | |
116 | QV4::ExecutionEngine *m_engine; |
117 | QV4::CppStackFrame *m_currentFrame = 0; |
118 | QMutex m_lock; |
119 | QWaitCondition m_runningCondition; |
120 | State m_state; |
121 | Speed m_stepping; |
122 | bool m_pauseRequested; |
123 | bool m_haveBreakPoints; |
124 | bool m_breakOnThrow; |
125 | |
126 | QHash<BreakPoint, QString> m_breakPoints; |
127 | QV4::PersistentValue m_returnedValue; |
128 | |
129 | QV4DebugJob *m_gatherSources; |
130 | QV4DebugJob *m_runningJob; |
131 | QV4DataCollector m_collector; |
132 | QWaitCondition m_jobIsRunning; |
133 | }; |
134 | |
135 | QT_END_NAMESPACE |
136 | |
137 | Q_DECLARE_METATYPE(QV4Debugger::PauseReason) |
138 | Q_DECLARE_METATYPE(QV4Debugger*) |
139 | |
140 | #endif // QV4DEBUGGER_H |
141 | |