qmlcppengine.cpp 20.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
Tobias Hunger's avatar
Tobias Hunger committed
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Tobias Hunger's avatar
Tobias Hunger committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25

26
#include "qmlcppengine.h"
27
#include "qmlengine.h"
28

29
#include <debugger/debuggercore.h>
30
#include <debugger/debuggerruncontrol.h>
31
#include <debugger/debuggertooltipmanager.h>
32
#include <debugger/breakhandler.h>
33
#include <debugger/stackhandler.h>
Christian Kandeler's avatar
Christian Kandeler committed
34
#include <debugger/threaddata.h>
35
#include <debugger/watchhandler.h>
hjk's avatar
hjk committed
36
#include <debugger/console/console.h>
37

38
#include <utils/qtcassert.h>
39 40
#include <qmljseditor/qmljseditorconstants.h>
#include <cppeditor/cppeditorconstants.h>
41

42
namespace Debugger {
43
namespace Internal {
44

45 46 47 48
enum { debug = 0 };

#define EDEBUG(s) do { if (debug) qDebug() << s; } while (0)

49
#define CHECK_STATE(s) do { checkState(s, __FILE__, __LINE__); } while (0)
50

51
DebuggerEngine *createQmlCppEngine(DebuggerEngine *cppEngine)
52
{
53
    return new QmlCppEngine(cppEngine);
54
}
hjk's avatar
hjk committed
55

hjk's avatar
hjk committed
56 57 58 59 60 61 62

////////////////////////////////////////////////////////////////////////
//
// QmlCppEngine
//
////////////////////////////////////////////////////////////////////////

63
QmlCppEngine::QmlCppEngine(DebuggerEngine *cppEngine)
64 65
{
    setObjectName("QmlCppEngine");
66
    m_qmlEngine = new QmlEngine;
67 68
    m_qmlEngine->setMasterEngine(this);
    m_cppEngine = cppEngine;
hjk's avatar
hjk committed
69
    m_cppEngine->setMasterEngine(this);
hjk's avatar
hjk committed
70
    m_activeEngine = m_cppEngine;
71 72 73 74
}

QmlCppEngine::~QmlCppEngine()
{
hjk's avatar
hjk committed
75 76
    delete m_qmlEngine;
    delete m_cppEngine;
77 78
}

79 80
bool QmlCppEngine::canDisplayTooltip() const
{
hjk's avatar
hjk committed
81
    return m_cppEngine->canDisplayTooltip() || m_qmlEngine->canDisplayTooltip();
82 83
}

84
bool QmlCppEngine::canHandleToolTip(const DebuggerToolTipContext &ctx) const
85
{
86
    bool success = false;
87
    if (ctx.isCppEditor)
88
        success = m_cppEngine->canHandleToolTip(ctx);
89
    else
90
        success = m_qmlEngine->canHandleToolTip(ctx);
91
    return success;
92 93
}

hjk's avatar
hjk committed
94
void QmlCppEngine::updateItem(const QString &iname)
95
{
96
    if (iname.startsWith("inspect."))
hjk's avatar
hjk committed
97
        m_qmlEngine->updateItem(iname);
98
    else
hjk's avatar
hjk committed
99
        m_activeEngine->updateItem(iname);
100 101
}

hjk's avatar
hjk committed
102
void QmlCppEngine::expandItem(const QString &iname)
103 104 105 106 107 108 109
{
    if (iname.startsWith("inspect."))
        m_qmlEngine->expandItem(iname);
    else
        m_activeEngine->expandItem(iname);
}

hjk's avatar
hjk committed
110
void QmlCppEngine::selectWatchData(const QString &iname)
111
{
112 113
    if (iname.startsWith("inspect."))
        m_qmlEngine->selectWatchData(iname);
114 115
}

116 117
void QmlCppEngine::watchPoint(const QPoint &point)
{
hjk's avatar
hjk committed
118
    m_cppEngine->watchPoint(point);
119 120
}

121
void QmlCppEngine::fetchMemory(MemoryAgent *agent, quint64 addr, quint64 length)
122
{
123 124 125 126 127 128
    m_cppEngine->fetchMemory(agent, addr, length);
}

void QmlCppEngine::changeMemory(MemoryAgent *agent, quint64 addr, const QByteArray &data)
{
    m_cppEngine->changeMemory(agent, addr, data);
129 130
}

131
void QmlCppEngine::fetchDisassembler(DisassemblerAgent *da)
132
{
hjk's avatar
hjk committed
133
    m_cppEngine->fetchDisassembler(da);
134 135 136 137
}

void QmlCppEngine::activateFrame(int index)
{
138 139 140
    if (state() != InferiorStopOk && state() != InferiorUnrunnable)
        return;

hjk's avatar
hjk committed
141
    m_activeEngine->activateFrame(index);
Aurindam Jana's avatar
Aurindam Jana committed
142

143
    stackHandler()->setCurrentIndex(index);
144 145 146 147
}

void QmlCppEngine::reloadModules()
{
hjk's avatar
hjk committed
148
    m_cppEngine->reloadModules();
149 150 151 152
}

void QmlCppEngine::examineModules()
{
hjk's avatar
hjk committed
153
    m_cppEngine->examineModules();
154 155 156 157
}

void QmlCppEngine::loadSymbols(const QString &moduleName)
{
hjk's avatar
hjk committed
158
    m_cppEngine->loadSymbols(moduleName);
159 160 161 162
}

void QmlCppEngine::loadAllSymbols()
{
hjk's avatar
hjk committed
163
    m_cppEngine->loadAllSymbols();
164 165 166 167
}

void QmlCppEngine::requestModuleSymbols(const QString &moduleName)
{
hjk's avatar
hjk committed
168
    m_cppEngine->requestModuleSymbols(moduleName);
169 170 171 172
}

void QmlCppEngine::reloadRegisters()
{
hjk's avatar
hjk committed
173
    m_cppEngine->reloadRegisters();
174 175 176 177
}

void QmlCppEngine::reloadSourceFiles()
{
hjk's avatar
hjk committed
178
    m_cppEngine->reloadSourceFiles();
179 180 181 182
}

void QmlCppEngine::reloadFullStack()
{
hjk's avatar
hjk committed
183
    m_cppEngine->reloadFullStack();
184 185
}

hjk's avatar
hjk committed
186
void QmlCppEngine::setRegisterValue(const QString &name, const QString &value)
187
{
hjk's avatar
hjk committed
188
    m_cppEngine->setRegisterValue(name, value);
189 190
}

191 192

bool QmlCppEngine::hasCapability(unsigned cap) const
193 194
{
    // ### this could also be an OR of both engines' capabilities
hjk's avatar
hjk committed
195 196
    bool hasCap = m_cppEngine->hasCapability(cap);
    if (m_activeEngine != m_cppEngine) {
197 198
        //Some capabilities cannot be handled by QML Engine
        //Expand this list as and when required
199
        if (cap == AddWatcherWhileRunningCapability)
hjk's avatar
hjk committed
200
            hasCap = hasCap || m_qmlEngine->hasCapability(cap);
201 202 203 204
        if (cap == WatchWidgetsCapability ||
                cap == DisassemblerCapability ||
                cap == OperateByInstructionCapability ||
                cap == ReverseSteppingCapability)
hjk's avatar
hjk committed
205
            hasCap = hasCap && m_qmlEngine->hasCapability(cap);
206
    }
207
    return hasCap;
208 209
}

hjk's avatar
hjk committed
210
bool QmlCppEngine::isSynchronous() const
211
{
hjk's avatar
hjk committed
212
    return m_activeEngine->isSynchronous();
213 214
}

hjk's avatar
hjk committed
215
QString QmlCppEngine::qtNamespace() const
216
{
hjk's avatar
hjk committed
217
    return m_cppEngine->qtNamespace();
218 219 220 221
}

void QmlCppEngine::createSnapshot()
{
hjk's avatar
hjk committed
222
    m_cppEngine->createSnapshot();
223 224 225 226
}

void QmlCppEngine::updateAll()
{
hjk's avatar
hjk committed
227
    m_activeEngine->updateAll();
228 229 230 231
}

void QmlCppEngine::attemptBreakpointSynchronization()
{
hjk's avatar
hjk committed
232
    m_cppEngine->attemptBreakpointSynchronization();
233

hjk's avatar
hjk committed
234
    switch (m_qmlEngine->state()) {
235 236 237 238
    case InferiorRunOk:
    case InferiorRunRequested:
    case InferiorStopOk: // fall through
    case InferiorStopRequested:
hjk's avatar
hjk committed
239
        m_qmlEngine->attemptBreakpointSynchronization();
240 241 242
        break;
    default:
        break;
243
    }
244 245
}

246 247 248 249 250
void QmlCppEngine::doUpdateLocals(const UpdateParameters &up)
{
    m_activeEngine->doUpdateLocals(up);
}

251
bool QmlCppEngine::acceptsBreakpoint(Breakpoint bp) const
252
{
253 254
    return m_cppEngine->acceptsBreakpoint(bp)
        || m_qmlEngine->acceptsBreakpoint(bp);
255 256
}

hjk's avatar
hjk committed
257
void QmlCppEngine::selectThread(ThreadId threadId)
258
{
hjk's avatar
hjk committed
259
    m_activeEngine->selectThread(threadId);
260 261
}

262
void QmlCppEngine::assignValueInDebugger(WatchItem *item,
hjk's avatar
hjk committed
263
    const QString &expr, const QVariant &value)
264
{
265 266
    if (item->isInspect())
        m_qmlEngine->assignValueInDebugger(item, expr, value);
Aurindam Jana's avatar
Aurindam Jana committed
267
    else
268
        m_activeEngine->assignValueInDebugger(item, expr, value);
269 270
}

271 272 273 274 275
void QmlCppEngine::notifyInferiorIll()
{
    //Call notifyInferiorIll of cpp engine
    //as qml engine will follow state transitions
    //of cpp engine
hjk's avatar
hjk committed
276
    m_cppEngine->notifyInferiorIll();
277 278
}

279 280
void QmlCppEngine::detachDebugger()
{
hjk's avatar
hjk committed
281 282
    m_qmlEngine->detachDebugger();
    m_cppEngine->detachDebugger();
283 284 285
}

void QmlCppEngine::executeStep()
286
{
287
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
288
    m_activeEngine->executeStep();
289 290
}

291 292
void QmlCppEngine::executeStepOut()
{
293
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
294
    m_activeEngine->executeStepOut();
295 296 297 298
}

void QmlCppEngine::executeNext()
{
299
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
300
    m_activeEngine->executeNext();
301 302 303 304
}

void QmlCppEngine::executeStepI()
{
305
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
306
    m_activeEngine->executeStepI();
307 308 309 310
}

void QmlCppEngine::executeNextI()
{
311
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
312
    m_activeEngine->executeNextI();
313 314 315 316
}

void QmlCppEngine::executeReturn()
{
317
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
318
    m_activeEngine->executeReturn();
319 320 321 322
}

void QmlCppEngine::continueInferior()
{
323
    EDEBUG("\nMASTER CONTINUE INFERIOR"
hjk's avatar
hjk committed
324
        << state() << m_qmlEngine->state());
325
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
326 327 328 329
    if (m_cppEngine->state() == InferiorStopOk) {
        m_cppEngine->continueInferior();
    } else if (m_qmlEngine->state() == InferiorStopOk) {
        m_qmlEngine->continueInferior();
330
    } else {
331
        QTC_ASSERT(false, qDebug() << "MASTER CANNOT CONTINUE INFERIOR"
hjk's avatar
hjk committed
332
                << m_cppEngine->state() << m_qmlEngine->state());
333
        notifyEngineIll();
334
    }
335 336 337 338
}

void QmlCppEngine::interruptInferior()
{
339
    EDEBUG("\nMASTER INTERRUPT INFERIOR");
hjk's avatar
hjk committed
340
    m_cppEngine->requestInterruptInferior();
341 342 343 344
}

void QmlCppEngine::requestInterruptInferior()
{
345
    EDEBUG("\nMASTER REQUEST INTERRUPT INFERIOR");
346
    DebuggerEngine::requestInterruptInferior();
347 348
}

349
void QmlCppEngine::executeRunToLine(const ContextData &data)
350
{
hjk's avatar
hjk committed
351
    m_activeEngine->executeRunToLine(data);
352 353 354 355
}

void QmlCppEngine::executeRunToFunction(const QString &functionName)
{
hjk's avatar
hjk committed
356
    m_activeEngine->executeRunToFunction(functionName);
357 358
}

359
void QmlCppEngine::executeJumpToLine(const ContextData &data)
360
{
hjk's avatar
hjk committed
361
    m_activeEngine->executeJumpToLine(data);
362 363
}

364
void QmlCppEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
365
{
hjk's avatar
hjk committed
366 367
    m_qmlEngine->executeDebuggerCommand(command, languages);
    m_cppEngine->executeDebuggerCommand(command, languages);
368 369
}

370 371
/////////////////////////////////////////////////////////

372
void QmlCppEngine::setupEngine()
373
{
374
    EDEBUG("\nMASTER SETUP ENGINE");
hjk's avatar
hjk committed
375
    m_activeEngine = m_cppEngine;
hjk's avatar
hjk committed
376 377
    m_qmlEngine->setupSlaveEngine();
    m_cppEngine->setupSlaveEngine();
378
}
379

380
void QmlCppEngine::setupInferior()
381
{
382
    EDEBUG("\nMASTER SETUP INFERIOR");
383 384
    m_qmlEngine->setupInferior();
    m_cppEngine->setupInferior();
385 386
}

387
void QmlCppEngine::runEngine()
388
{
389
    EDEBUG("\nMASTER RUN ENGINE");
hjk's avatar
hjk committed
390 391
    m_qmlEngine->runSlaveEngine();
    m_cppEngine->runSlaveEngine();
392 393
}

394
void QmlCppEngine::shutdownInferior()
395
{
396
    EDEBUG("\nMASTER SHUTDOWN INFERIOR");
hjk's avatar
hjk committed
397
    m_cppEngine->shutdownInferior();
398 399
}

400
void QmlCppEngine::shutdownEngine()
401
{
402
    EDEBUG("\nMASTER SHUTDOWN ENGINE");
403
    m_qmlEngine->shutdownSlaveEngine();
hjk's avatar
hjk committed
404
    m_cppEngine->shutdownSlaveEngine();
405 406
}

407 408 409
void QmlCppEngine::quitDebugger()
{
    EDEBUG("\nMASTER QUIT DEBUGGER");
hjk's avatar
hjk committed
410
    m_cppEngine->quitDebugger();
411 412
}

hjk's avatar
hjk committed
413
void QmlCppEngine::abortDebuggerProcess()
414 415
{
    EDEBUG("\nMASTER ABORT DEBUGGER");
hjk's avatar
hjk committed
416
    m_cppEngine->abortDebuggerProcess();
417 418
}

419
void QmlCppEngine::setState(DebuggerState newState, bool forced)
420
{
421
    EDEBUG("SET MASTER STATE: " << newState);
hjk's avatar
hjk committed
422 423
    EDEBUG("  CPP STATE: " << m_cppEngine->state());
    EDEBUG("  QML STATE: " << m_qmlEngine->state());
424
    DebuggerEngine::setState(newState, forced);
425 426
}

427 428
void QmlCppEngine::slaveEngineStateChanged
    (DebuggerEngine *slaveEngine, const DebuggerState newState)
429
{
hjk's avatar
hjk committed
430
    DebuggerEngine *otherEngine = (slaveEngine == m_cppEngine)
431
         ? m_qmlEngine.data() : m_cppEngine.data();
432

hjk's avatar
hjk committed
433
    QTC_ASSERT(otherEngine, return);
434
    QTC_CHECK(otherEngine != slaveEngine);
435

436
    if (debug) {
437 438 439 440
        EDEBUG("GOT SLAVE STATE: " << slaveEngine << newState);
        EDEBUG("  OTHER ENGINE: " << otherEngine << otherEngine->state());
        EDEBUG("  COMBINED ENGINE: " << this << state() << isDying());
    }
441

442 443 444 445 446
    if (state() == DebuggerFinished) {
        // We are done and don't care about slave state changes anymore.
        return;
    }

447 448 449 450 451 452
    // Idea is to follow the state of the cpp engine, except where we are stepping in QML.
    // That is, when the QmlEngine moves between InferiorStopOk, and InferiorRunOk, InferiorStopOk ...
    //
    // Accordingly, the 'active engine' is the cpp engine until the qml engine enters the
    // InferiorStopOk state. The cpp engine becomes the active one again as soon as it itself enters
    // the InferiorStopOk state.
453

hjk's avatar
hjk committed
454
    if (slaveEngine == m_cppEngine) {
455
        switch (newState) {
456
        case DebuggerNotReady: {
457 458
            // Can this ever happen?
            break;
459 460
        }
        case EngineSetupRequested: {
461 462
            // Set by queueSetupEngine()
            CHECK_STATE(EngineSetupRequested);
463
            break;
464 465
        }
        case EngineSetupFailed: {
466 467 468
            qmlEngine()->quitDebugger();
            notifyEngineSetupFailed();
            break;
469 470
        }
        case EngineSetupOk: {
471
            notifyEngineSetupOk();
472
            break;
473 474
        }
        case InferiorSetupRequested: {
475 476
            // Set by queueSetupInferior()
            CHECK_STATE(InferiorSetupRequested);
477
            break;
478 479
        }
        case InferiorSetupFailed: {
480
            qmlEngine()->quitDebugger();
481
            notifyInferiorSetupFailed();
482
            break;
483 484
        }
        case InferiorSetupOk: {
485
            notifyInferiorSetupOk();
486
            break;
487 488 489
        }
        case EngineRunRequested: {
            // set by queueRunEngine()
490
            break;
491 492
        }
        case EngineRunFailed: {
493
            qmlEngine()->quitDebugger();
494
            notifyEngineRunFailed();
495
            break;
496 497 498
        }
        case InferiorUnrunnable: {
            qmlEngine()->quitDebugger();
hjk's avatar
hjk committed
499
            notifyEngineRunOkAndInferiorUnrunnable();
500
            break;
501 502
        }
        case InferiorRunRequested: {
503 504 505
            // Might be set already by notifyInferiorRunRequested()
            if (state() != InferiorRunRequested) {
                CHECK_STATE(InferiorStopOk);
506
                notifyInferiorRunRequested();
507
            }
508
            break;
509 510
        }
        case InferiorRunOk: {
511
            if (state() == EngineRunRequested)
hjk's avatar
hjk committed
512
                notifyEngineRunAndInferiorRunOk();
513
            else if (state() == InferiorRunRequested)
hjk's avatar
hjk committed
514
                notifyInferiorRunOk();
515 516
            else
                QTC_ASSERT(false, qDebug() << state());
517 518 519 520 521

            if (qmlEngine()->state() == InferiorStopOk) {
                // track qml engine again
                setState(InferiorStopRequested);
                notifyInferiorStopOk();
hjk's avatar
hjk committed
522
                setActiveEngine(m_qmlEngine);
523
            }
524
            break;
525 526
        }
        case InferiorRunFailed: {
527 528 529
            qmlEngine()->quitDebugger();
            notifyInferiorRunFailed();
            break;
530 531
        }
        case InferiorStopRequested: {
hjk's avatar
hjk committed
532
            if (m_activeEngine == cppEngine()) {
533
                if (state() == InferiorRunOk) {
534
                    setState(InferiorStopRequested);
535 536 537 538
                } else {
                    // Might be set by doInterruptInferior()
                    CHECK_STATE(InferiorStopRequested);
                }
539
            } else {
540
                // We're debugging qml, but got an interrupt, or abort
541 542 543
                if (state() == InferiorRunOk) {
                    setState(InferiorStopRequested);
                } else if (state() == InferiorStopOk) {
hjk's avatar
hjk committed
544 545 546 547 548
                    if (!isDying()) {
                        notifyInferiorRunRequested();
                        notifyInferiorRunOk();
                        setState(InferiorStopRequested);
                    }
549 550 551
                } else if (state() == InferiorRunRequested) {
                    notifyInferiorRunOk();
                    setState(InferiorStopRequested);
552 553
                } else {
                    QTC_ASSERT(false, qDebug() << state());
554
                }
555
                // now track cpp engine
hjk's avatar
hjk committed
556
                setActiveEngine(m_cppEngine);
557
            }
558
            break;
559 560
        }
        case InferiorStopOk: {
561 562
            if (isDying()) {
                EDEBUG("... CPP ENGINE STOPPED DURING SHUTDOWN ");
563 564 565 566 567
                QTC_ASSERT(state() == InferiorStopRequested
                           || state() == InferiorRunOk
                           || state() == InferiorStopOk, qDebug() << state());

                // Just to make sure, we're shutting down anyway ...
hjk's avatar
hjk committed
568
                m_activeEngine = m_cppEngine;
569

570
                if (state() == InferiorStopRequested)
571 572
                    setState(InferiorStopOk);
                // otherwise we're probably inside notifyInferiorStopOk already
573
            } else {
hjk's avatar
hjk committed
574
                if (m_activeEngine != cppEngine()) {
Friedemann Kleint's avatar
Friedemann Kleint committed
575
                    showStatusMessage(tr("C++ debugger activated"));
hjk's avatar
hjk committed
576
                    setActiveEngine(m_cppEngine);
577 578 579 580 581 582 583 584 585 586
                }
                switch (state()) {
                case InferiorStopRequested:
                    EDEBUG("... CPP ENGINE STOPPED EXPECTEDLY");
                    notifyInferiorStopOk();
                    break;
                case EngineRunRequested:
                    EDEBUG("... CPP ENGINE STOPPED ON STARTUP");
                    notifyEngineRunAndInferiorStopOk();
                    break;
587
                case InferiorRunOk:
588 589 590
                    EDEBUG("... CPP ENGINE STOPPED SPONTANEOUSLY");
                    notifyInferiorSpontaneousStop();
                    break;
591 592 593
                case InferiorRunRequested:
                    // can happen if qml engine was active
                    notifyInferiorRunFailed();
594
                    break;
595
                default:
596
                    CHECK_STATE(InferiorStopOk);
597
                    break;
598
                }
599
            }
600
            break;
601 602
        }
        case InferiorStopFailed: {
603
            CHECK_STATE(InferiorStopRequested);
604 605
            notifyInferiorStopFailed();
            break;
606 607
        }
        case InferiorShutdownRequested: {
608
            if (state() == InferiorStopOk) {
609
                setState(InferiorShutdownRequested);
610 611 612 613
            } else {
                // might be set by queueShutdownInferior() already
                CHECK_STATE(InferiorShutdownRequested);
            }
614
            qmlEngine()->quitDebugger();
615
            break;
616 617
        }
        case InferiorShutdownFailed: {
618
            CHECK_STATE(InferiorShutdownRequested);
619 620
            notifyInferiorShutdownFailed();
            break;
621 622
        }
        case InferiorShutdownOk: {
623
            if (state() == InferiorShutdownRequested) {
624
                notifyInferiorShutdownOk();
625
            } else {
626 627 628
                // we got InferiorExitOk before, but ignored it ...
                notifyInferiorExited();
            }
629
            break;
630 631 632
        }
        case EngineShutdownRequested: {
            // set by queueShutdownEngine()
633
            CHECK_STATE(EngineShutdownRequested);
634
            break;
635 636
        }
        case EngineShutdownFailed: {
637
            CHECK_STATE(EngineShutdownRequested);
638 639
            notifyEngineShutdownFailed();
            break;
640
        }
641
        case EngineShutdownOk: {
642
            CHECK_STATE(EngineShutdownRequested);
643
            notifyEngineShutdownOk();
644 645
            break;
        }
646 647
        case DebuggerFinished: {
            // set by queueFinishDebugger()
648
            CHECK_STATE(DebuggerFinished);
649 650
            break;
        }
651
        }
652 653 654
    } else {
        // QML engine state change
        if (newState == InferiorStopOk) {
655 656 657 658
            if (isDying()) {
                EDEBUG("... QML ENGINE STOPPED DURING SHUTDOWN ");

                // Just to make sure, we're shutting down anyway ...
hjk's avatar
hjk committed
659
                setActiveEngine(m_cppEngine);
660 661 662 663 664

                if (state() == InferiorStopRequested)
                    notifyInferiorStopOk();
                // otherwise we're probably inside notifyInferiorStopOk already
            } else {
hjk's avatar
hjk committed
665
                if (m_activeEngine != qmlEngine()) {
666
                    showStatusMessage(tr("QML debugger activated"));
hjk's avatar
hjk committed
667
                    setActiveEngine(m_qmlEngine);
668 669 670 671
                }

                if (state() == InferiorRunOk)
                    notifyInferiorSpontaneousStop();
672
                else if (state() == InferiorStopRequested)
673
                    notifyInferiorStopOk();
674 675
                else
                    CHECK_STATE(InferiorShutdownRequested);
676
            }
677

678
        } else if (newState == InferiorRunOk) {
hjk's avatar
hjk committed
679
            if (m_activeEngine == qmlEngine()) {
680
                CHECK_STATE(InferiorRunRequested);
681
                notifyInferiorRunOk();
682
            }
683
        }
684 685 686
    }
}

687 688
void QmlCppEngine::resetLocation()
{
hjk's avatar
hjk committed
689 690 691 692
    if (m_qmlEngine)
        m_qmlEngine->resetLocation();
    if (m_cppEngine)
        m_cppEngine->resetLocation();
693 694

    DebuggerEngine::resetLocation();
695 696
}

697 698 699 700 701 702
void QmlCppEngine::reloadDebuggingHelpers()
{
    if (m_cppEngine)
        m_cppEngine->reloadDebuggingHelpers();
}

703 704 705 706 707 708
void QmlCppEngine::debugLastCommand()
{
    if (m_cppEngine)
        m_cppEngine->debugLastCommand();
}

709 710
DebuggerEngine *QmlCppEngine::qmlEngine() const
{
hjk's avatar
hjk committed
711
    return m_qmlEngine;
712 713
}

714 715 716 717 718 719 720
void QmlCppEngine::setRunTool(DebuggerRunTool *runTool)
{
    DebuggerEngine::setRunTool(runTool);
    m_qmlEngine->setRunTool(runTool);
    m_cppEngine->setRunTool(runTool);
}

721 722
void QmlCppEngine::setActiveEngine(DebuggerEngine *engine)
{
hjk's avatar
hjk committed
723
    m_activeEngine = engine;
724 725 726
    updateViews();
}

727 728 729 730 731 732
void QmlCppEngine::loadAdditionalQmlStack()
{
    if (m_cppEngine)
        m_cppEngine->loadAdditionalQmlStack();
}

733
} // namespace Internal
734
} // namespace Debugger