1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QV4DEBUGGER_H
41#define QV4DEBUGGER_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qv4datacollector.h"
55#include <private/qv4debugging_p.h>
56#include <private/qv4function_p.h>
57#include <private/qv4context_p.h>
58#include <private/qv4persistent_p.h>
59
60#include <QtCore/qmutex.h>
61#include <QtCore/qwaitcondition.h>
62
63QT_BEGIN_NAMESPACE
64
65class QV4DebugJob;
66class QV4DataCollector;
67class QV4Debugger : public QV4::Debugging::Debugger
68{
69 Q_OBJECT
70public:
71 struct BreakPoint {
72 BreakPoint(const QString &fileName, int line);
73 QString fileName;
74 int lineNumber;
75 };
76
77 enum State {
78 Running,
79 Paused
80 };
81
82 enum Speed {
83 FullThrottle = 0,
84 StepOut,
85 StepOver,
86 StepIn,
87
88 NotStepping = FullThrottle
89 };
90
91 enum PauseReason {
92 PauseRequest,
93 BreakPointHit,
94 Throwing,
95 Step
96 };
97
98 QV4Debugger(QV4::ExecutionEngine *engine);
99
100 QV4::ExecutionEngine *engine() const;
101 const QV4DataCollector *collector() const;
102 QV4DataCollector *collector();
103
104 void pause();
105 void resume(Speed speed);
106
107 State state() const;
108
109 void addBreakPoint(const QString &fileName, int lineNumber,
110 const QString &condition = QString());
111 void removeBreakPoint(const QString &fileName, int lineNumber);
112
113 void setBreakOnThrow(bool onoff);
114
115 void clearPauseRequest();
116
117 // used for testing
118 struct ExecutionState
119 {
120 QString fileName;
121 int lineNumber;
122 };
123 ExecutionState currentExecutionState() const;
124
125 QVector<QV4::StackFrame> stackTrace(int frameLimit = -1) const;
126 QVector<QV4::Heap::ExecutionContext::ContextType> getScopeTypes(int frame = 0) const;
127
128 QV4::Function *getFunction() const;
129 void runInEngine(QV4DebugJob *job);
130
131 // compile-time interface
132 void maybeBreakAtInstruction() override;
133
134 // execution hooks
135 void enteringFunction() override;
136 void leavingFunction(const QV4::ReturnedValue &retVal) override;
137 void aboutToThrow() override;
138
139 bool pauseAtNextOpportunity() const override;
140
141signals:
142 void debuggerPaused(QV4Debugger *self, QV4Debugger::PauseReason reason);
143 void scheduleJob();
144
145private:
146 // requires lock to be held
147 void pauseAndWait(PauseReason reason);
148 bool reallyHitTheBreakPoint(const QString &filename, int linenr);
149 void runInEngine_havingLock(QV4DebugJob *job);
150 void runJobUnpaused();
151
152 QV4::ExecutionEngine *m_engine;
153 QV4::CppStackFrame *m_currentFrame = 0;
154 QMutex m_lock;
155 QWaitCondition m_runningCondition;
156 State m_state;
157 Speed m_stepping;
158 bool m_pauseRequested;
159 bool m_haveBreakPoints;
160 bool m_breakOnThrow;
161
162 QHash<BreakPoint, QString> m_breakPoints;
163 QV4::PersistentValue m_returnedValue;
164
165 QV4DebugJob *m_gatherSources;
166 QV4DebugJob *m_runningJob;
167 QV4DataCollector m_collector;
168 QWaitCondition m_jobIsRunning;
169};
170
171QT_END_NAMESPACE
172
173Q_DECLARE_METATYPE(QV4Debugger::PauseReason)
174Q_DECLARE_METATYPE(QV4Debugger*)
175
176#endif // QV4DEBUGGER_H
177

source code of qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.h