OpenCoverage

qv4debugger.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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-
49QT_BEGIN_NAMESPACE-
50-
51QV4Debugger::BreakPoint::BreakPoint(const QString &fileName, int line)-
52 : fileName(fileName), lineNumber(line)-
53{}
executed 810 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
810
54-
55inline 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:
  • tst_qqmldebugjs
  • tst_qv4debugger
810
58}-
59-
60inline 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:
  • tst_qqmldebugjs
  • tst_qv4debugger
124
64}-
65-
66QV4Debugger::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:
  • tst_qqmldebugjs
  • tst_qqmldebuglocal
  • tst_qv4debugger
110
85-
86QV4::ExecutionEngine *QV4Debugger::engine() const-
87{-
88 return m_engine;
executed 2128 times by 2 tests: return m_engine;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
2128
89}-
90-
91const QV4DataCollector *QV4Debugger::collector() const-
92{-
93 return &m_collector;
never executed: return &m_collector;
0
94}-
95-
96QV4DataCollector *QV4Debugger::collector()-
97{-
98 return &m_collector;
executed 16 times by 1 test: return &m_collector;
Executed by:
  • tst_qqmldebugjs
16
99}-
100-
101void QV4Debugger::pause()-
102{-
103 QMutexLocker locker(&m_lock);-
104 if (m_state == Paused)
m_state == PausedDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-4
105 return;
never executed: return;
0
106 m_pauseRequested = true;-
107}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
4
108-
109void QV4Debugger::resume(Speed speed)-
110{-
111 QMutexLocker locker(&m_lock);-
112 if (m_state != Paused)
m_state != PausedDescription
TRUEnever evaluated
FALSEevaluated 480 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
0-480
113 return;
never executed: return;
0
114-
115 if (!m_returnedValue.isUndefined())
!m_returnedValue.isUndefined()Description
TRUEnever evaluated
FALSEevaluated 480 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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:
  • tst_qqmldebugjs
  • tst_qv4debugger
480
122-
123QV4Debugger::State QV4Debugger::state() const-
124{-
125 return m_state;
executed 722 times by 2 tests: return m_state;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
722
126}-
127-
128void 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:
  • tst_qqmldebugjs
  • tst_qv4debugger
104
135-
136void 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:
  • tst_qv4debugger
4
143-
144void 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:
  • tst_qqmldebugjs
  • tst_qqmldebuglocal
  • tst_qv4debugger
28
150-
151void QV4Debugger::clearPauseRequest()-
152{-
153 QMutexLocker locker(&m_lock);-
154 m_pauseRequested = false;-
155}
executed 24 times by 1 test: end of block
Executed by:
  • tst_qqmldebugjs
24
156-
157QV4Debugger::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:
  • tst_qv4debugger
464
164}-
165-
166bool 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:
  • tst_qqmldebugjs
  • tst_qv4debugger
1208
168}-
169-
170QVector<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:
  • tst_qv4debugger
464
173}-
174-
175void QV4Debugger::maybeBreakAtInstruction()-
176{-
177 if (m_runningJob) // do not re-enter when we're doing a job for the debugger.
m_runningJobDescription
TRUEevaluated 100 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 1082 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
100-1082
178 return;
executed 100 times by 1 test: return;
Executed by:
  • tst_qv4debugger
100
179-
180 QMutexLocker locker(&m_lock);-
181-
182 if (m_gatherSources) {
m_gatherSourcesDescription
TRUEnever evaluated
FALSEevaluated 1082 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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:
  • tst_qv4debugger
376
190 if (m_currentFrame != m_engine->currentStackFrame)
m_currentFrame...rentStackFrameDescription
TRUEnever evaluated
FALSEevaluated 376 times by 1 test
Evaluated by:
  • tst_qv4debugger
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:
  • tst_qv4debugger
never executed: case StepIn:
0-376
194 pauseAndWait(Step);-
195 return;
executed 376 times by 1 test: return;
Executed by:
  • tst_qv4debugger
376
196 case StepOut:
never executed: case StepOut:
0
197 case NotStepping:
executed 706 times by 2 tests: case NotStepping:
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
706
198 break;
executed 706 times by 2 tests: break;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
706
199 }-
200-
201 if (m_pauseRequested) { // Serve debugging requests from the agent
m_pauseRequestedDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 702 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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:
  • tst_qv4debugger
m_haveBreakPointsDescription
TRUEevaluated 702 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEnever evaluated
0-702
205 if (QV4::Function *f = getFunction()) {
QV4::Function ... getFunction()Description
TRUEevaluated 702 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEnever evaluated
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))
reallyHitTheBr...), lineNumber)Description
TRUEevaluated 98 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEevaluated 604 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
98-604
209 pauseAndWait(BreakPointHit);
executed 98 times by 2 tests: pauseAndWait(BreakPointHit);
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
98
210 }
executed 702 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
702
211 }
executed 702 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
702
212}
executed 706 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
706
213-
214void QV4Debugger::enteringFunction()-
215{-
216 if (m_runningJob)
m_runningJobDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 170 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
50-170
217 return;
executed 50 times by 1 test: return;
Executed by:
  • tst_qv4debugger
50
218 QMutexLocker locker(&m_lock);-
219-
220 if (m_stepping == StepIn)
m_stepping == StepInDescription
TRUEnever evaluated
FALSEevaluated 170 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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:
  • tst_qqmldebugjs
  • tst_qv4debugger
170
223-
224void QV4Debugger::leavingFunction(const QV4::ReturnedValue &retVal)-
225{-
226 if (m_runningJob)
m_runningJobDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 170 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
50-170
227 return;
executed 50 times by 1 test: return;
Executed by:
  • tst_qv4debugger
50
228 Q_UNUSED(retVal); // TODO-
229-
230 QMutexLocker locker(&m_lock);-
231-
232 if (m_stepping != NotStepping && m_currentFrame == m_engine->currentStackFrame) {
m_stepping != NotSteppingDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 134 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
m_currentFrame...rentStackFrameDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
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:
  • tst_qv4debugger
36
237}
executed 170 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
170
238-
239void QV4Debugger::aboutToThrow()-
240{-
241 if (!m_breakOnThrow)
!m_breakOnThrowDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4debugger
2-6
242 return;
executed 6 times by 1 test: return;
Executed by:
  • tst_qv4debugger
6
243-
244 if (m_runningJob) // do not re-enter when we're doing a job for the debugger.
m_runningJobDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4debugger
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:
  • tst_qv4debugger
2
250-
251QV4::Function *QV4Debugger::getFunction() const-
252{-
253 if (m_engine->currentStackFrame)
m_engine->currentStackFrameDescription
TRUEevaluated 1166 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEnever evaluated
0-1166
254 return m_engine->currentStackFrame->v4Function;
executed 1166 times by 2 tests: return m_engine->currentStackFrame->v4Function;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
1166
255 else-
256 return m_engine->globalCode;
never executed: return m_engine->globalCode;
0
257}-
258-
259void QV4Debugger::runJobUnpaused()-
260{-
261 QMutexLocker locker(&m_lock);-
262 if (m_runningJob)
m_runningJobDescription
TRUEnever evaluated
FALSEnever evaluated
0
263 m_runningJob->run();
never executed: m_runningJob->run();
0
264 m_jobIsRunning.wakeAll();-
265}
never executed: end of block
0
266-
267void QV4Debugger::pauseAndWait(PauseReason reason)-
268{-
269 if (m_runningJob)
m_runningJobDescription
TRUEnever evaluated
FALSEevaluated 480 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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) {
m_runningJobDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 480 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
192-480
278 m_runningJob->run();-
279 m_jobIsRunning.wakeAll();-
280 } else {
executed 192 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
192
281 break;
executed 480 times by 2 tests: break;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
480
282 }-
283 }-
284-
285 m_state = Running;-
286}
executed 480 times by 2 tests: end of block
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
480
287-
288bool 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())
it == m_breakPoints.end()Description
TRUEevaluated 582 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEevaluated 120 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
120-582
293 return false;
executed 582 times by 2 tests: return false;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
582
294 QString condition = it.value();-
295 if (condition.isEmpty())
condition.isEmpty()Description
TRUEevaluated 88 times by 2 tests
Evaluated by:
  • tst_qqmldebugjs
  • tst_qv4debugger
FALSEevaluated 32 times by 1 test
Evaluated by:
  • tst_qv4debugger
32-88
296 return true;
executed 88 times by 2 tests: return true;
Executed by:
  • tst_qqmldebugjs
  • tst_qv4debugger
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:
  • tst_qv4debugger
32
305}-
306-
307void 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:
  • tst_qv4debugger
192
312-
313void 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)
state() == PausedDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-192
320 m_runningCondition.wakeAll();
executed 192 times by 1 test: m_runningCondition.wakeAll();
Executed by:
  • tst_qv4debugger
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:
  • tst_qv4debugger
192
326-
327QT_END_NAMESPACE-
328-
329#include "moc_qv4debugger.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0