| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | QV4Debugger::BreakPoint::BreakPoint(const QString &fileName, int line) | - | ||||||||||||
| 7 | : fileName(fileName), lineNumber(line) | - | ||||||||||||
| 8 | {} executed 810 times by 2 tests: end of blockExecuted by:
| 810 | ||||||||||||
| 9 | - | |||||||||||||
| 10 | inline uint qHash(const QV4Debugger::BreakPoint &b, uint seed = 0) noexcept | - | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | return executed 810 times by 2 tests: qHash(b.fileName, seed) ^ b.lineNumber;return qHash(b.fileName, seed) ^ b.lineNumber;Executed by:
executed 810 times by 2 tests: return qHash(b.fileName, seed) ^ b.lineNumber;Executed by:
| 810 | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | inline bool operator==(const QV4Debugger::BreakPoint &a, | - | ||||||||||||
| 16 | const QV4Debugger::BreakPoint &b) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | return executed 124 times by 2 tests: a.lineNumber == b.lineNumber && a.fileName == b.fileName;return a.lineNumber == b.lineNumber && a.fileName == b.fileName;Executed by:
executed 124 times by 2 tests: return a.lineNumber == b.lineNumber && a.fileName == b.fileName;Executed by:
| 124 | ||||||||||||
| 19 | } | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | QV4Debugger::QV4Debugger(QV4::ExecutionEngine *engine) | - | ||||||||||||
| 22 | : m_engine(engine) | - | ||||||||||||
| 23 | , m_state(Running) | - | ||||||||||||
| 24 | , m_stepping(NotStepping) | - | ||||||||||||
| 25 | , m_pauseRequested(false) | - | ||||||||||||
| 26 | , m_haveBreakPoints(false) | - | ||||||||||||
| 27 | , m_breakOnThrow(false) | - | ||||||||||||
| 28 | , m_returnedValue(engine, QV4::Primitive::undefinedValue()) | - | ||||||||||||
| 29 | , m_gatherSources(nullptr) | - | ||||||||||||
| 30 | , m_runningJob(nullptr) | - | ||||||||||||
| 31 | , m_collector(engine) | - | ||||||||||||
| 32 | { | - | ||||||||||||
| 33 | static int debuggerId = qRegisterMetaType<QV4Debugger*>(); | - | ||||||||||||
| 34 | static int pauseReasonId = qRegisterMetaType<QV4Debugger::PauseReason>(); | - | ||||||||||||
| 35 | (void)debuggerId;; | - | ||||||||||||
| 36 | (void)pauseReasonId;; | - | ||||||||||||
| 37 | connect(this, &QV4Debugger::scheduleJob, | - | ||||||||||||
| 38 | this, &QV4Debugger::runJobUnpaused, Qt::QueuedConnection); | - | ||||||||||||
| 39 | } executed 110 times by 3 tests: end of blockExecuted by:
| 110 | ||||||||||||
| 40 | - | |||||||||||||
| 41 | QV4::ExecutionEngine *QV4Debugger::engine() const | - | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | return executed 2128 times by 2 tests: m_engine;return m_engine;Executed by:
executed 2128 times by 2 tests: return m_engine;Executed by:
| 2128 | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | const QV4DataCollector *QV4Debugger::collector() const | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | return never executed: &m_collector;return &m_collector;never executed: return &m_collector; | 0 | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | QV4DataCollector *QV4Debugger::collector() | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | return executed 16 times by 1 test: &m_collector;return &m_collector;Executed by:
executed 16 times by 1 test: return &m_collector;Executed by:
| 16 | ||||||||||||
| 54 | } | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | void QV4Debugger::pause() | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 59 | if (m_state == Paused
| 0-4 | ||||||||||||
| 60 | return; never executed: return; | 0 | ||||||||||||
| 61 | m_pauseRequested = true; | - | ||||||||||||
| 62 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 63 | - | |||||||||||||
| 64 | void QV4Debugger::resume(Speed speed) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 67 | if (m_state != Paused
| 0-480 | ||||||||||||
| 68 | return; never executed: return; | 0 | ||||||||||||
| 69 | - | |||||||||||||
| 70 | if (!m_returnedValue.isUndefined()
| 0-480 | ||||||||||||
| 71 | m_returnedValue.set(m_engine, QV4::Encode::undefined()); never executed: m_returnedValue.set(m_engine, QV4::Encode::undefined()); | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | m_currentFrame = m_engine->currentStackFrame; | - | ||||||||||||
| 74 | m_stepping = speed; | - | ||||||||||||
| 75 | m_runningCondition.wakeAll(); | - | ||||||||||||
| 76 | } executed 480 times by 2 tests: end of blockExecuted by:
| 480 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | QV4Debugger::State QV4Debugger::state() const | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | return executed 722 times by 2 tests: m_state;return m_state;Executed by:
executed 722 times by 2 tests: return m_state;Executed by:
| 722 | ||||||||||||
| 81 | } | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | void QV4Debugger::addBreakPoint(const QString &fileName, int lineNumber, const QString &condition) | - | ||||||||||||
| 84 | { | - | ||||||||||||
| 85 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 86 | m_breakPoints.insert(BreakPoint(fileName.mid(fileName.lastIndexOf('/') + 1), | - | ||||||||||||
| 87 | lineNumber), condition); | - | ||||||||||||
| 88 | m_haveBreakPoints = true; | - | ||||||||||||
| 89 | } executed 104 times by 2 tests: end of blockExecuted by:
| 104 | ||||||||||||
| 90 | - | |||||||||||||
| 91 | void QV4Debugger::removeBreakPoint(const QString &fileName, int lineNumber) | - | ||||||||||||
| 92 | { | - | ||||||||||||
| 93 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 94 | m_breakPoints.remove(BreakPoint(fileName.mid(fileName.lastIndexOf('/') + 1), | - | ||||||||||||
| 95 | lineNumber)); | - | ||||||||||||
| 96 | m_haveBreakPoints = !m_breakPoints.isEmpty(); | - | ||||||||||||
| 97 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | void QV4Debugger::setBreakOnThrow(bool onoff) | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | m_breakOnThrow = onoff; | - | ||||||||||||
| 104 | } executed 28 times by 3 tests: end of blockExecuted by:
| 28 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | void QV4Debugger::clearPauseRequest() | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 109 | m_pauseRequested = false; | - | ||||||||||||
| 110 | } executed 24 times by 1 test: end of blockExecuted by:
| 24 | ||||||||||||
| 111 | - | |||||||||||||
| 112 | QV4Debugger::ExecutionState QV4Debugger::currentExecutionState() const | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | ExecutionState state; | - | ||||||||||||
| 115 | state.fileName = getFunction()->sourceFile(); | - | ||||||||||||
| 116 | state.lineNumber = engine()->currentStackFrame->lineNumber(); | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | return executed 464 times by 1 test: state;return state;Executed by:
executed 464 times by 1 test: return state;Executed by:
| 464 | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | bool QV4Debugger::pauseAtNextOpportunity() const { | - | ||||||||||||
| 122 | return executed 1208 times by 2 tests: m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver;return m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver;Executed by:
executed 1208 times by 2 tests: return m_pauseRequested || m_haveBreakPoints || m_gatherSources || m_stepping >= StepOver;Executed by:
| 1208 | ||||||||||||
| 123 | } | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | QVector<QV4::StackFrame> QV4Debugger::stackTrace(int frameLimit) const | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | return executed 464 times by 1 test: m_engine->stackTrace(frameLimit);return m_engine->stackTrace(frameLimit);Executed by:
executed 464 times by 1 test: return m_engine->stackTrace(frameLimit);Executed by:
| 464 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | void QV4Debugger::maybeBreakAtInstruction() | - | ||||||||||||
| 131 | { | - | ||||||||||||
| 132 | if (m_runningJob
| 100-1082 | ||||||||||||
| 133 | return; executed 100 times by 1 test: return;Executed by:
| 100 | ||||||||||||
| 134 | - | |||||||||||||
| 135 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | if (m_gatherSources
| 0-1082 | ||||||||||||
| 138 | m_gatherSources->run(); | - | ||||||||||||
| 139 | delete m_gatherSources; | - | ||||||||||||
| 140 | m_gatherSources = nullptr; | - | ||||||||||||
| 141 | } never executed: end of block | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | switch (m_stepping) { | - | ||||||||||||
| 144 | case executed 376 times by 1 test: StepOver:case StepOver:Executed by:
executed 376 times by 1 test: case StepOver:Executed by:
| 376 | ||||||||||||
| 145 | if (m_currentFrame != m_engine->currentStackFrame
| 0-376 | ||||||||||||
| 146 | break; never executed: break; | 0 | ||||||||||||
| 147 | (void)0; | - | ||||||||||||
| 148 | case never executed: case StepIn:code before this statement executed 376 times by 1 test: case StepIn:Executed by:
never executed: StepIn:case StepIn:code before this statement executed 376 times by 1 test: case StepIn:Executed by:
never executed: case StepIn: | 0-376 | ||||||||||||
| 149 | pauseAndWait(Step); | - | ||||||||||||
| 150 | return; executed 376 times by 1 test: return;Executed by:
| 376 | ||||||||||||
| 151 | case never executed: StepOut:case StepOut:never executed: case StepOut: | 0 | ||||||||||||
| 152 | case executed 706 times by 2 tests: NotStepping:case NotStepping:Executed by:
executed 706 times by 2 tests: case NotStepping:Executed by:
| 706 | ||||||||||||
| 153 | break; executed 706 times by 2 tests: break;Executed by:
| 706 | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | if (m_pauseRequested
| 4-702 | ||||||||||||
| 157 | m_pauseRequested = false; | - | ||||||||||||
| 158 | pauseAndWait(PauseRequest); | - | ||||||||||||
| 159 | } executed 4 times by 1 test: else if (m_haveBreakPointsend of blockExecuted by:
| 0-702 | ||||||||||||
| 160 | if (QV4::Function *f = getFunction()
| 0-702 | ||||||||||||
| 161 | - | |||||||||||||
| 162 | const int lineNumber = engine()->currentStackFrame->lineNumber(); | - | ||||||||||||
| 163 | if (reallyHitTheBreakPoint(f->sourceFile(), lineNumber)
| 98-604 | ||||||||||||
| 164 | pauseAndWait(BreakPointHit); executed 98 times by 2 tests: pauseAndWait(BreakPointHit);Executed by:
| 98 | ||||||||||||
| 165 | } executed 702 times by 2 tests: end of blockExecuted by:
| 702 | ||||||||||||
| 166 | } executed 702 times by 2 tests: end of blockExecuted by:
| 702 | ||||||||||||
| 167 | } executed 706 times by 2 tests: end of blockExecuted by:
| 706 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | void QV4Debugger::enteringFunction() | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | if (m_runningJob
| 50-170 | ||||||||||||
| 172 | return; executed 50 times by 1 test: return;Executed by:
| 50 | ||||||||||||
| 173 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | if (m_stepping == StepIn
| 0-170 | ||||||||||||
| 176 | m_currentFrame = m_engine->currentStackFrame; never executed: m_currentFrame = m_engine->currentStackFrame; | 0 | ||||||||||||
| 177 | } executed 170 times by 2 tests: end of blockExecuted by:
| 170 | ||||||||||||
| 178 | - | |||||||||||||
| 179 | void QV4Debugger::leavingFunction(const QV4::ReturnedValue &retVal) | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | if (m_runningJob
| 50-170 | ||||||||||||
| 182 | return; executed 50 times by 1 test: return;Executed by:
| 50 | ||||||||||||
| 183 | (void)retVal;; | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | if (m_stepping != NotStepping
| 0-134 | ||||||||||||
| 188 | m_currentFrame = m_currentFrame->parent; | - | ||||||||||||
| 189 | m_stepping = StepOver; | - | ||||||||||||
| 190 | m_returnedValue.set(m_engine, retVal); | - | ||||||||||||
| 191 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||
| 192 | } executed 170 times by 2 tests: end of blockExecuted by:
| 170 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | void QV4Debugger::aboutToThrow() | - | ||||||||||||
| 195 | { | - | ||||||||||||
| 196 | if (!m_breakOnThrow
| 2-6 | ||||||||||||
| 197 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | if (m_runningJob
| 0-2 | ||||||||||||
| 200 | return; never executed: return; | 0 | ||||||||||||
| 201 | - | |||||||||||||
| 202 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 203 | pauseAndWait(Throwing); | - | ||||||||||||
| 204 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 205 | - | |||||||||||||
| 206 | QV4::Function *QV4Debugger::getFunction() const | - | ||||||||||||
| 207 | { | - | ||||||||||||
| 208 | if (m_engine->currentStackFrame
| 0-1166 | ||||||||||||
| 209 | return executed 1166 times by 2 tests: m_engine->currentStackFrame->v4Function;return m_engine->currentStackFrame->v4Function;Executed by:
executed 1166 times by 2 tests: return m_engine->currentStackFrame->v4Function;Executed by:
| 1166 | ||||||||||||
| 210 | else | - | ||||||||||||
| 211 | return never executed: m_engine->globalCode;return m_engine->globalCode;never executed: return m_engine->globalCode; | 0 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | void QV4Debugger::runJobUnpaused() | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 217 | if (m_runningJob
| 0 | ||||||||||||
| 218 | m_runningJob->run(); never executed: m_runningJob->run(); | 0 | ||||||||||||
| 219 | m_jobIsRunning.wakeAll(); | - | ||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||
| 221 | - | |||||||||||||
| 222 | void QV4Debugger::pauseAndWait(PauseReason reason) | - | ||||||||||||
| 223 | { | - | ||||||||||||
| 224 | if (m_runningJob
| 0-480 | ||||||||||||
| 225 | return; never executed: return; | 0 | ||||||||||||
| 226 | - | |||||||||||||
| 227 | m_state = Paused; | - | ||||||||||||
| 228 | debuggerPaused(this, reason); | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | while (true) { | - | ||||||||||||
| 231 | m_runningCondition.wait(&m_lock); | - | ||||||||||||
| 232 | if (m_runningJob
| 192-480 | ||||||||||||
| 233 | m_runningJob->run(); | - | ||||||||||||
| 234 | m_jobIsRunning.wakeAll(); | - | ||||||||||||
| 235 | } executed 192 times by 1 test: else {end of blockExecuted by:
| 192 | ||||||||||||
| 236 | break; executed 480 times by 2 tests: break;Executed by:
| 480 | ||||||||||||
| 237 | } | - | ||||||||||||
| 238 | } | - | ||||||||||||
| 239 | - | |||||||||||||
| 240 | m_state = Running; | - | ||||||||||||
| 241 | } executed 480 times by 2 tests: end of blockExecuted by:
| 480 | ||||||||||||
| 242 | - | |||||||||||||
| 243 | bool QV4Debugger::reallyHitTheBreakPoint(const QString &filename, int linenr) | - | ||||||||||||
| 244 | { | - | ||||||||||||
| 245 | QHash<BreakPoint, QString>::iterator it = m_breakPoints.find( | - | ||||||||||||
| 246 | BreakPoint(filename.mid(filename.lastIndexOf('/') + 1), linenr)); | - | ||||||||||||
| 247 | if (it == m_breakPoints.end()
| 120-582 | ||||||||||||
| 248 | return executed 582 times by 2 tests: false;return false;Executed by:
executed 582 times by 2 tests: return false;Executed by:
| 582 | ||||||||||||
| 249 | QString condition = it.value(); | - | ||||||||||||
| 250 | if (condition.isEmpty()
| 32-88 | ||||||||||||
| 251 | return executed 88 times by 2 tests: true;return true;Executed by:
executed 88 times by 2 tests: return true;Executed by:
| 88 | ||||||||||||
| 252 | - | |||||||||||||
| 253 | ((m_runningJob == nullptr) ? static_cast<void>(0) : qt_assert("m_runningJob == nullptr", __FILE__, 298)); | - | ||||||||||||
| 254 | EvalJob evilJob(m_engine, condition); | - | ||||||||||||
| 255 | m_runningJob = &evilJob; | - | ||||||||||||
| 256 | m_runningJob->run(); | - | ||||||||||||
| 257 | m_runningJob = nullptr; | - | ||||||||||||
| 258 | - | |||||||||||||
| 259 | return executed 32 times by 1 test: evilJob.resultAsBoolean();return evilJob.resultAsBoolean();Executed by:
executed 32 times by 1 test: return evilJob.resultAsBoolean();Executed by:
| 32 | ||||||||||||
| 260 | } | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | void QV4Debugger::runInEngine(QV4DebugJob *job) | - | ||||||||||||
| 263 | { | - | ||||||||||||
| 264 | QMutexLocker locker(&m_lock); | - | ||||||||||||
| 265 | runInEngine_havingLock(job); | - | ||||||||||||
| 266 | } executed 192 times by 1 test: end of blockExecuted by:
| 192 | ||||||||||||
| 267 | - | |||||||||||||
| 268 | void QV4Debugger::runInEngine_havingLock(QV4DebugJob *job) | - | ||||||||||||
| 269 | { | - | ||||||||||||
| 270 | ((job) ? static_cast<void>(0) : qt_assert("job", __FILE__, 315)); | - | ||||||||||||
| 271 | ((m_runningJob == nullptr) ? static_cast<void>(0) : qt_assert("m_runningJob == nullptr", __FILE__, 316)); | - | ||||||||||||
| 272 | - | |||||||||||||
| 273 | m_runningJob = job; | - | ||||||||||||
| 274 | if (state() == Paused
| 0-192 | ||||||||||||
| 275 | m_runningCondition.wakeAll(); executed 192 times by 1 test: m_runningCondition.wakeAll();Executed by:
| 192 | ||||||||||||
| 276 | else | - | ||||||||||||
| 277 | scheduleJob(); never executed: scheduleJob(); | 0 | ||||||||||||
| 278 | m_jobIsRunning.wait(&m_lock); | - | ||||||||||||
| 279 | m_runningJob = nullptr; | - | ||||||||||||
| 280 | } executed 192 times by 1 test: end of blockExecuted by:
| 192 | ||||||||||||
| 281 | - | |||||||||||||
| 282 | - | |||||||||||||
| 283 | - | |||||||||||||
| Switch to Source code | Preprocessed file |