Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | #include "qv4debugger.h" | - | ||||||||||||
41 | #include "qv4debugjob.h" | - | ||||||||||||
42 | #include "qv4datacollector.h" | - | ||||||||||||
43 | - | |||||||||||||
44 | #include <private/qv4scopedvalue_p.h> | - | ||||||||||||
45 | #include <private/qv4script_p.h> | - | ||||||||||||
46 | #include <private/qqmlcontext_p.h> | - | ||||||||||||
47 | #include <private/qqmlengine_p.h> | - | ||||||||||||
48 | - | |||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
50 | - | |||||||||||||
51 | QV4Debugger::BreakPoint::BreakPoint(const QString &fileName, int line) | - | ||||||||||||
52 | : fileName(fileName), lineNumber(line) | - | ||||||||||||
53 | {} executed 810 times by 2 tests: end of block Executed by:
| 810 | ||||||||||||
54 | - | |||||||||||||
55 | inline uint qHash(const QV4Debugger::BreakPoint &b, uint seed = 0) Q_DECL_NOTHROW | - | ||||||||||||
56 | { | - | ||||||||||||
57 | return qHash(b.fileName, seed) ^ b.lineNumber; executed 810 times by 2 tests: return qHash(b.fileName, seed) ^ b.lineNumber; Executed by:
| 810 | ||||||||||||
58 | } | - | ||||||||||||
59 | - | |||||||||||||
60 | inline bool operator==(const QV4Debugger::BreakPoint &a, | - | ||||||||||||
61 | const QV4Debugger::BreakPoint &b) | - | ||||||||||||
62 | { | - | ||||||||||||
63 | return a.lineNumber == b.lineNumber && a.fileName == b.fileName; executed 124 times by 2 tests: return a.lineNumber == b.lineNumber && a.fileName == b.fileName; Executed by:
| 124 | ||||||||||||
64 | } | - | ||||||||||||
65 | - | |||||||||||||
66 | QV4Debugger::QV4Debugger(QV4::ExecutionEngine *engine) | - | ||||||||||||
67 | : m_engine(engine) | - | ||||||||||||
68 | , m_state(Running) | - | ||||||||||||
69 | , m_stepping(NotStepping) | - | ||||||||||||
70 | , m_pauseRequested(false) | - | ||||||||||||
71 | , m_haveBreakPoints(false) | - | ||||||||||||
72 | , m_breakOnThrow(false) | - | ||||||||||||
73 | , m_returnedValue(engine, QV4::Primitive::undefinedValue()) | - | ||||||||||||
74 | , m_gatherSources(nullptr) | - | ||||||||||||
75 | , m_runningJob(nullptr) | - | ||||||||||||
76 | , m_collector(engine) | - | ||||||||||||
77 | { | - | ||||||||||||
78 | static int debuggerId = qRegisterMetaType<QV4Debugger*>(); | - | ||||||||||||
79 | static int pauseReasonId = qRegisterMetaType<QV4Debugger::PauseReason>(); | - | ||||||||||||
80 | Q_UNUSED(debuggerId); | - | ||||||||||||
81 | Q_UNUSED(pauseReasonId); | - | ||||||||||||
82 | connect(this, &QV4Debugger::scheduleJob, | - | ||||||||||||
83 | this, &QV4Debugger::runJobUnpaused, Qt::QueuedConnection); | - | ||||||||||||
84 | } executed 110 times by 3 tests: end of block Executed by:
| 110 | ||||||||||||
85 | - | |||||||||||||
86 | QV4::ExecutionEngine *QV4Debugger::engine() const | - | ||||||||||||
87 | { | - | ||||||||||||
88 | return m_engine; executed 2128 times by 2 tests: return m_engine; Executed by:
| 2128 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | const QV4DataCollector *QV4Debugger::collector() const | - | ||||||||||||
92 | { | - | ||||||||||||
93 | return &m_collector; never executed: return &m_collector; | 0 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | QV4DataCollector *QV4Debugger::collector() | - | ||||||||||||
97 | { | - | ||||||||||||
98 | return &m_collector; executed 16 times by 1 test: return &m_collector; Executed by:
| 16 | ||||||||||||
99 | } | - | ||||||||||||
100 | - | |||||||||||||
101 | void QV4Debugger::pause() | - | ||||||||||||
102 | { | - | ||||||||||||
103 | QMutexLocker locker(&m_lock); | - | ||||||||||||
104 | if (m_state == Paused)
| 0-4 | ||||||||||||
105 | return; never executed: return; | 0 | ||||||||||||
106 | m_pauseRequested = true; | - | ||||||||||||
107 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
108 | - | |||||||||||||
109 | void QV4Debugger::resume(Speed speed) | - | ||||||||||||
110 | { | - | ||||||||||||
111 | QMutexLocker locker(&m_lock); | - | ||||||||||||
112 | if (m_state != Paused)
| 0-480 | ||||||||||||
113 | return; never executed: return; | 0 | ||||||||||||
114 | - | |||||||||||||
115 | if (!m_returnedValue.isUndefined())
| 0-480 | ||||||||||||
116 | m_returnedValue.set(m_engine, QV4::Encode::undefined()); never executed: m_returnedValue.set(m_engine, QV4::Encode::undefined()); | 0 | ||||||||||||
117 | - | |||||||||||||
118 | m_currentFrame = m_engine->currentStackFrame; | - | ||||||||||||
119 | m_stepping = speed; | - | ||||||||||||
120 | m_runningCondition.wakeAll(); | - | ||||||||||||
121 | } executed 480 times by 2 tests: end of block Executed by:
| 480 | ||||||||||||
122 | - | |||||||||||||
123 | QV4Debugger::State QV4Debugger::state() const | - | ||||||||||||
124 | { | - | ||||||||||||
125 | return m_state; executed 722 times by 2 tests: return m_state; Executed by:
| 722 | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | void QV4Debugger::addBreakPoint(const QString &fileName, int lineNumber, const QString &condition) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | QMutexLocker locker(&m_lock); | - | ||||||||||||
131 | m_breakPoints.insert(BreakPoint(fileName.mid(fileName.lastIndexOf('/') + 1), | - | ||||||||||||
132 | lineNumber), condition); | - | ||||||||||||
133 | m_haveBreakPoints = true; | - | ||||||||||||
134 | } executed 104 times by 2 tests: end of block Executed by:
| 104 | ||||||||||||
135 | - | |||||||||||||
136 | void QV4Debugger::removeBreakPoint(const QString &fileName, int lineNumber) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | QMutexLocker locker(&m_lock); | - | ||||||||||||
139 | m_breakPoints.remove(BreakPoint(fileName.mid(fileName.lastIndexOf('/') + 1), | - | ||||||||||||
140 | lineNumber)); | - | ||||||||||||
141 | m_haveBreakPoints = !m_breakPoints.isEmpty(); | - | ||||||||||||
142 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
143 | - | |||||||||||||
144 | void QV4Debugger::setBreakOnThrow(bool onoff) | - | ||||||||||||
145 | { | - | ||||||||||||
146 | QMutexLocker locker(&m_lock); | - | ||||||||||||
147 | - | |||||||||||||
148 | m_breakOnThrow = onoff; | - | ||||||||||||
149 | } executed 28 times by 3 tests: end of block Executed by:
| 28 | ||||||||||||
150 | - | |||||||||||||
151 | void QV4Debugger::clearPauseRequest() | - | ||||||||||||
152 | { | - | ||||||||||||
153 | QMutexLocker locker(&m_lock); | - | ||||||||||||
154 | m_pauseRequested = false; | - | ||||||||||||
155 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||
156 | - | |||||||||||||
157 | QV4Debugger::ExecutionState QV4Debugger::currentExecutionState() const | - | ||||||||||||
158 | { | - | ||||||||||||
159 | ExecutionState state; | - | ||||||||||||
160 | state.fileName = getFunction()->sourceFile(); | - | ||||||||||||
161 | state.lineNumber = engine()->currentStackFrame->lineNumber(); | - | ||||||||||||
162 | - | |||||||||||||
163 | return state; executed 464 times by 1 test: return state; Executed by:
| 464 | ||||||||||||
164 | } | - | ||||||||||||
165 | - | |||||||||||||
166 | bool QV4Debugger::pauseAtNextOpportunity() const { | - | ||||||||||||
167 | return m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver; executed 1208 times by 2 tests: return m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver; Executed by:
| 1208 | ||||||||||||
168 | } | - | ||||||||||||
169 | - | |||||||||||||
170 | QVector<QV4::StackFrame> QV4Debugger::stackTrace(int frameLimit) const | - | ||||||||||||
171 | { | - | ||||||||||||
172 | return m_engine->stackTrace(frameLimit); executed 464 times by 1 test: return m_engine->stackTrace(frameLimit); Executed by:
| 464 | ||||||||||||
173 | } | - | ||||||||||||
174 | - | |||||||||||||
175 | void QV4Debugger::maybeBreakAtInstruction() | - | ||||||||||||
176 | { | - | ||||||||||||
177 | if (m_runningJob) // do not re-enter when we're doing a job for the debugger.
| 100-1082 | ||||||||||||
178 | return; executed 100 times by 1 test: return; Executed by:
| 100 | ||||||||||||
179 | - | |||||||||||||
180 | QMutexLocker locker(&m_lock); | - | ||||||||||||
181 | - | |||||||||||||
182 | if (m_gatherSources) {
| 0-1082 | ||||||||||||
183 | m_gatherSources->run(); | - | ||||||||||||
184 | delete m_gatherSources; | - | ||||||||||||
185 | m_gatherSources = nullptr; | - | ||||||||||||
186 | } never executed: end of block | 0 | ||||||||||||
187 | - | |||||||||||||
188 | switch (m_stepping) { | - | ||||||||||||
189 | case StepOver: executed 376 times by 1 test: case StepOver: Executed by:
| 376 | ||||||||||||
190 | if (m_currentFrame != m_engine->currentStackFrame)
| 0-376 | ||||||||||||
191 | break; never executed: break; | 0 | ||||||||||||
192 | Q_FALLTHROUGH(); | - | ||||||||||||
193 | case StepIn: code before this statement executed 376 times by 1 test: case StepIn: Executed by:
never executed: case StepIn: | 0-376 | ||||||||||||
194 | pauseAndWait(Step); | - | ||||||||||||
195 | return; executed 376 times by 1 test: return; Executed by:
| 376 | ||||||||||||
196 | case StepOut: never executed: case StepOut: | 0 | ||||||||||||
197 | case NotStepping: executed 706 times by 2 tests: case NotStepping: Executed by:
| 706 | ||||||||||||
198 | break; executed 706 times by 2 tests: break; Executed by:
| 706 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | if (m_pauseRequested) { // Serve debugging requests from the agent
| 4-702 | ||||||||||||
202 | m_pauseRequested = false; | - | ||||||||||||
203 | pauseAndWait(PauseRequest); | - | ||||||||||||
204 | } else if (m_haveBreakPoints) { executed 4 times by 1 test: end of block Executed by:
| 0-702 | ||||||||||||
205 | if (QV4::Function *f = getFunction()) {
| 0-702 | ||||||||||||
206 | // lineNumber will be negative for Ret instructions, so those won't match | - | ||||||||||||
207 | const int lineNumber = engine()->currentStackFrame->lineNumber(); | - | ||||||||||||
208 | if (reallyHitTheBreakPoint(f->sourceFile(), lineNumber))
| 98-604 | ||||||||||||
209 | pauseAndWait(BreakPointHit); executed 98 times by 2 tests: pauseAndWait(BreakPointHit); Executed by:
| 98 | ||||||||||||
210 | } executed 702 times by 2 tests: end of block Executed by:
| 702 | ||||||||||||
211 | } executed 702 times by 2 tests: end of block Executed by:
| 702 | ||||||||||||
212 | } executed 706 times by 2 tests: end of block Executed by:
| 706 | ||||||||||||
213 | - | |||||||||||||
214 | void QV4Debugger::enteringFunction() | - | ||||||||||||
215 | { | - | ||||||||||||
216 | if (m_runningJob)
| 50-170 | ||||||||||||
217 | return; executed 50 times by 1 test: return; Executed by:
| 50 | ||||||||||||
218 | QMutexLocker locker(&m_lock); | - | ||||||||||||
219 | - | |||||||||||||
220 | if (m_stepping == StepIn)
| 0-170 | ||||||||||||
221 | m_currentFrame = m_engine->currentStackFrame; never executed: m_currentFrame = m_engine->currentStackFrame; | 0 | ||||||||||||
222 | } executed 170 times by 2 tests: end of block Executed by:
| 170 | ||||||||||||
223 | - | |||||||||||||
224 | void QV4Debugger::leavingFunction(const QV4::ReturnedValue &retVal) | - | ||||||||||||
225 | { | - | ||||||||||||
226 | if (m_runningJob)
| 50-170 | ||||||||||||
227 | return; executed 50 times by 1 test: return; Executed by:
| 50 | ||||||||||||
228 | Q_UNUSED(retVal); // TODO | - | ||||||||||||
229 | - | |||||||||||||
230 | QMutexLocker locker(&m_lock); | - | ||||||||||||
231 | - | |||||||||||||
232 | if (m_stepping != NotStepping && m_currentFrame == m_engine->currentStackFrame) {
| 0-134 | ||||||||||||
233 | m_currentFrame = m_currentFrame->parent; | - | ||||||||||||
234 | m_stepping = StepOver; | - | ||||||||||||
235 | m_returnedValue.set(m_engine, retVal); | - | ||||||||||||
236 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||
237 | } executed 170 times by 2 tests: end of block Executed by:
| 170 | ||||||||||||
238 | - | |||||||||||||
239 | void QV4Debugger::aboutToThrow() | - | ||||||||||||
240 | { | - | ||||||||||||
241 | if (!m_breakOnThrow)
| 2-6 | ||||||||||||
242 | return; executed 6 times by 1 test: return; Executed by:
| 6 | ||||||||||||
243 | - | |||||||||||||
244 | if (m_runningJob) // do not re-enter when we're doing a job for the debugger.
| 0-2 | ||||||||||||
245 | return; never executed: return; | 0 | ||||||||||||
246 | - | |||||||||||||
247 | QMutexLocker locker(&m_lock); | - | ||||||||||||
248 | pauseAndWait(Throwing); | - | ||||||||||||
249 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
250 | - | |||||||||||||
251 | QV4::Function *QV4Debugger::getFunction() const | - | ||||||||||||
252 | { | - | ||||||||||||
253 | if (m_engine->currentStackFrame)
| 0-1166 | ||||||||||||
254 | return m_engine->currentStackFrame->v4Function; executed 1166 times by 2 tests: return m_engine->currentStackFrame->v4Function; Executed by:
| 1166 | ||||||||||||
255 | else | - | ||||||||||||
256 | return m_engine->globalCode; never executed: return m_engine->globalCode; | 0 | ||||||||||||
257 | } | - | ||||||||||||
258 | - | |||||||||||||
259 | void QV4Debugger::runJobUnpaused() | - | ||||||||||||
260 | { | - | ||||||||||||
261 | QMutexLocker locker(&m_lock); | - | ||||||||||||
262 | if (m_runningJob)
| 0 | ||||||||||||
263 | m_runningJob->run(); never executed: m_runningJob->run(); | 0 | ||||||||||||
264 | m_jobIsRunning.wakeAll(); | - | ||||||||||||
265 | } never executed: end of block | 0 | ||||||||||||
266 | - | |||||||||||||
267 | void QV4Debugger::pauseAndWait(PauseReason reason) | - | ||||||||||||
268 | { | - | ||||||||||||
269 | if (m_runningJob)
| 0-480 | ||||||||||||
270 | return; never executed: return; | 0 | ||||||||||||
271 | - | |||||||||||||
272 | m_state = Paused; | - | ||||||||||||
273 | emit debuggerPaused(this, reason); | - | ||||||||||||
274 | - | |||||||||||||
275 | while (true) { | - | ||||||||||||
276 | m_runningCondition.wait(&m_lock); | - | ||||||||||||
277 | if (m_runningJob) {
| 192-480 | ||||||||||||
278 | m_runningJob->run(); | - | ||||||||||||
279 | m_jobIsRunning.wakeAll(); | - | ||||||||||||
280 | } else { executed 192 times by 1 test: end of block Executed by:
| 192 | ||||||||||||
281 | break; executed 480 times by 2 tests: break; Executed by:
| 480 | ||||||||||||
282 | } | - | ||||||||||||
283 | } | - | ||||||||||||
284 | - | |||||||||||||
285 | m_state = Running; | - | ||||||||||||
286 | } executed 480 times by 2 tests: end of block Executed by:
| 480 | ||||||||||||
287 | - | |||||||||||||
288 | bool QV4Debugger::reallyHitTheBreakPoint(const QString &filename, int linenr) | - | ||||||||||||
289 | { | - | ||||||||||||
290 | QHash<BreakPoint, QString>::iterator it = m_breakPoints.find( | - | ||||||||||||
291 | BreakPoint(filename.mid(filename.lastIndexOf('/') + 1), linenr)); | - | ||||||||||||
292 | if (it == m_breakPoints.end())
| 120-582 | ||||||||||||
293 | return false; executed 582 times by 2 tests: return false; Executed by:
| 582 | ||||||||||||
294 | QString condition = it.value(); | - | ||||||||||||
295 | if (condition.isEmpty())
| 32-88 | ||||||||||||
296 | return true; executed 88 times by 2 tests: return true; Executed by:
| 88 | ||||||||||||
297 | - | |||||||||||||
298 | Q_ASSERT(m_runningJob == nullptr); | - | ||||||||||||
299 | EvalJob evilJob(m_engine, condition); | - | ||||||||||||
300 | m_runningJob = &evilJob; | - | ||||||||||||
301 | m_runningJob->run(); | - | ||||||||||||
302 | m_runningJob = nullptr; | - | ||||||||||||
303 | - | |||||||||||||
304 | return evilJob.resultAsBoolean(); executed 32 times by 1 test: return evilJob.resultAsBoolean(); Executed by:
| 32 | ||||||||||||
305 | } | - | ||||||||||||
306 | - | |||||||||||||
307 | void QV4Debugger::runInEngine(QV4DebugJob *job) | - | ||||||||||||
308 | { | - | ||||||||||||
309 | QMutexLocker locker(&m_lock); | - | ||||||||||||
310 | runInEngine_havingLock(job); | - | ||||||||||||
311 | } executed 192 times by 1 test: end of block Executed by:
| 192 | ||||||||||||
312 | - | |||||||||||||
313 | void QV4Debugger::runInEngine_havingLock(QV4DebugJob *job) | - | ||||||||||||
314 | { | - | ||||||||||||
315 | Q_ASSERT(job); | - | ||||||||||||
316 | Q_ASSERT(m_runningJob == nullptr); | - | ||||||||||||
317 | - | |||||||||||||
318 | m_runningJob = job; | - | ||||||||||||
319 | if (state() == Paused)
| 0-192 | ||||||||||||
320 | m_runningCondition.wakeAll(); executed 192 times by 1 test: m_runningCondition.wakeAll(); Executed by:
| 192 | ||||||||||||
321 | else | - | ||||||||||||
322 | emit scheduleJob(); never executed: scheduleJob(); | 0 | ||||||||||||
323 | m_jobIsRunning.wait(&m_lock); | - | ||||||||||||
324 | m_runningJob = nullptr; | - | ||||||||||||
325 | } executed 192 times by 1 test: end of block Executed by:
| 192 | ||||||||||||
326 | - | |||||||||||||
327 | QT_END_NAMESPACE | - | ||||||||||||
328 | - | |||||||||||||
329 | #include "moc_qv4debugger.cpp" | - | ||||||||||||
Source code | Switch to Preprocessed file |