qmlcppengine.cpp 22.5 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Tobias Hunger's avatar
Tobias Hunger committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Tobias Hunger's avatar
Tobias Hunger committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30

31
#include "qmlcppengine.h"
32
#include "qmlengine.h"
33

34
#include <debugger/debuggerruncontrol.h>
35
#include <debugger/debuggertooltipmanager.h>
36
#include <debugger/debuggerstartparameters.h>
37
#include <debugger/breakhandler.h>
38
#include <debugger/stackhandler.h>
Christian Kandeler's avatar
Christian Kandeler committed
39
#include <debugger/threaddata.h>
40
#include <debugger/watchhandler.h>
41

42
#include <utils/qtcassert.h>
43 44
#include <qmljseditor/qmljseditorconstants.h>
#include <cppeditor/cppeditorconstants.h>
45
#include <qmljs/consolemanagerinterface.h>
46

47
namespace Debugger {
48
namespace Internal {
49

50 51 52 53
enum { debug = 0 };

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

54 55 56 57 58 59 60 61 62
#define CHECK_STATE(s) \
    do { \
        if (state() != s) { \
            showMessage(QString::fromLatin1("UNEXPECTED STATE: %1  WANTED: %2 IN %3:%4") \
                .arg(state()).arg(s).arg(QLatin1String(__FILE__)).arg(__LINE__), LogError); \
            QTC_ASSERT(false, qDebug() << state() << s); \
        } \
    } while (0)

63
DebuggerEngine *createQmlCppEngine(const DebuggerRunParameters &sp,
64
                                   QString *errorMessage)
65
{
hjk's avatar
hjk committed
66
    QmlCppEngine *newEngine = new QmlCppEngine(sp, errorMessage);
hjk's avatar
hjk committed
67
    if (newEngine->cppEngine())
68
        return newEngine;
hjk's avatar
hjk committed
69 70
    delete newEngine;
    return 0;
71
}
hjk's avatar
hjk committed
72

hjk's avatar
hjk committed
73 74 75 76 77 78 79

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

80 81
QmlCppEngine::QmlCppEngine(const DebuggerRunParameters &rp, QString *errorMessage)
    : DebuggerEngine(rp)
hjk's avatar
hjk committed
82
{
83
    setObjectName(QLatin1String("QmlCppEngine"));
84 85
    m_qmlEngine = new QmlEngine(rp, this);
    m_cppEngine = createEngine(rp.cppEngineType, rp, errorMessage);
hjk's avatar
hjk committed
86
    if (!m_cppEngine) {
Friedemann Kleint's avatar
Friedemann Kleint committed
87
        *errorMessage = tr("The slave debugging engine required for combined QML/C++-Debugging could not be created: %1").arg(*errorMessage);
88 89
        return;
    }
hjk's avatar
hjk committed
90 91
    m_cppEngine->setMasterEngine(this);
    setActiveEngine(m_cppEngine);
92 93 94 95
}

QmlCppEngine::~QmlCppEngine()
{
hjk's avatar
hjk committed
96 97
    delete m_qmlEngine;
    delete m_cppEngine;
98 99
}

100 101
bool QmlCppEngine::canDisplayTooltip() const
{
hjk's avatar
hjk committed
102
    return m_cppEngine->canDisplayTooltip() || m_qmlEngine->canDisplayTooltip();
103 104
}

105
bool QmlCppEngine::canHandleToolTip(const DebuggerToolTipContext &ctx) const
106
{
107
    bool success = false;
108
    if (ctx.isCppEditor)
109
        success = m_cppEngine->canHandleToolTip(ctx);
110
    else
111
        success = m_qmlEngine->canHandleToolTip(ctx);
112
    return success;
113 114
}

115
void QmlCppEngine::updateWatchData(const QByteArray &iname)
116
{
117 118
    if (iname.startsWith("inspect."))
        m_qmlEngine->updateWatchData(iname);
119
    else
120
        m_activeEngine->updateWatchData(iname);
121 122
}

123
void QmlCppEngine::selectWatchData(const QByteArray &iname)
124
{
125 126
    if (iname.startsWith("inspect."))
        m_qmlEngine->selectWatchData(iname);
127 128
}

129 130
void QmlCppEngine::watchPoint(const QPoint &point)
{
hjk's avatar
hjk committed
131
    m_cppEngine->watchPoint(point);
132 133
}

134
void QmlCppEngine::fetchMemory(MemoryAgent *ma, QObject *obj,
135 136
        quint64 addr, quint64 length)
{
hjk's avatar
hjk committed
137
    m_cppEngine->fetchMemory(ma, obj, addr, length);
138 139
}

140
void QmlCppEngine::fetchDisassembler(DisassemblerAgent *da)
141
{
hjk's avatar
hjk committed
142
    m_cppEngine->fetchDisassembler(da);
143 144 145 146
}

void QmlCppEngine::activateFrame(int index)
{
147 148 149
    if (state() != InferiorStopOk && state() != InferiorUnrunnable)
        return;

hjk's avatar
hjk committed
150
    m_activeEngine->activateFrame(index);
Aurindam Jana's avatar
Aurindam Jana committed
151

152
    stackHandler()->setCurrentIndex(index);
153 154 155 156
}

void QmlCppEngine::reloadModules()
{
hjk's avatar
hjk committed
157
    m_cppEngine->reloadModules();
158 159 160 161
}

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

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

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

void QmlCppEngine::requestModuleSymbols(const QString &moduleName)
{
hjk's avatar
hjk committed
177
    m_cppEngine->requestModuleSymbols(moduleName);
178 179 180 181
}

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

void QmlCppEngine::reloadSourceFiles()
{
hjk's avatar
hjk committed
187
    m_cppEngine->reloadSourceFiles();
188 189 190 191
}

void QmlCppEngine::reloadFullStack()
{
hjk's avatar
hjk committed
192
    m_cppEngine->reloadFullStack();
193 194
}

hjk's avatar
hjk committed
195
void QmlCppEngine::setRegisterValue(const QByteArray &name, const QString &value)
196
{
hjk's avatar
hjk committed
197
    m_cppEngine->setRegisterValue(name, value);
198 199
}

200 201

bool QmlCppEngine::hasCapability(unsigned cap) const
202 203
{
    // ### this could also be an OR of both engines' capabilities
hjk's avatar
hjk committed
204 205
    bool hasCap = m_cppEngine->hasCapability(cap);
    if (m_activeEngine != m_cppEngine) {
206 207
        //Some capabilities cannot be handled by QML Engine
        //Expand this list as and when required
208
        if (cap == AddWatcherWhileRunningCapability)
hjk's avatar
hjk committed
209
            hasCap = hasCap || m_qmlEngine->hasCapability(cap);
210 211 212 213
        if (cap == WatchWidgetsCapability ||
                cap == DisassemblerCapability ||
                cap == OperateByInstructionCapability ||
                cap == ReverseSteppingCapability)
hjk's avatar
hjk committed
214
            hasCap = hasCap && m_qmlEngine->hasCapability(cap);
215
    }
216
    return hasCap;
217 218
}

hjk's avatar
hjk committed
219
bool QmlCppEngine::isSynchronous() const
220
{
hjk's avatar
hjk committed
221
    return m_activeEngine->isSynchronous();
222 223
}

224
QByteArray QmlCppEngine::qtNamespace() const
225
{
hjk's avatar
hjk committed
226
    return m_cppEngine->qtNamespace();
227 228 229 230
}

void QmlCppEngine::createSnapshot()
{
hjk's avatar
hjk committed
231
    m_cppEngine->createSnapshot();
232 233 234 235
}

void QmlCppEngine::updateAll()
{
hjk's avatar
hjk committed
236
    m_activeEngine->updateAll();
237 238 239 240
}

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

hjk's avatar
hjk committed
243
    switch (m_qmlEngine->state()) {
244 245 246 247
    case InferiorRunOk:
    case InferiorRunRequested:
    case InferiorStopOk: // fall through
    case InferiorStopRequested:
hjk's avatar
hjk committed
248
        m_qmlEngine->attemptBreakpointSynchronization();
249 250 251
        break;
    default:
        break;
252
    }
253 254
}

255
bool QmlCppEngine::acceptsBreakpoint(Breakpoint bp) const
256
{
257 258
    return m_cppEngine->acceptsBreakpoint(bp)
        || m_qmlEngine->acceptsBreakpoint(bp);
259 260
}

hjk's avatar
hjk committed
261
void QmlCppEngine::selectThread(ThreadId threadId)
262
{
hjk's avatar
hjk committed
263
    m_activeEngine->selectThread(threadId);
264 265
}

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

275 276 277 278 279 280 281 282 283 284
void QmlCppEngine::notifyInferiorIll()
{
    //This will eventually shutdown the engine
    //Set final state to avoid quitDebugger() being called
    //after this call
    setTargetState(DebuggerFinished);

    //Call notifyInferiorIll of cpp engine
    //as qml engine will follow state transitions
    //of cpp engine
hjk's avatar
hjk committed
285
    m_cppEngine->notifyInferiorIll();
286 287
}

288 289
void QmlCppEngine::detachDebugger()
{
hjk's avatar
hjk committed
290 291
    m_qmlEngine->detachDebugger();
    m_cppEngine->detachDebugger();
292 293 294
}

void QmlCppEngine::executeStep()
295
{
296
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
297
    m_activeEngine->executeStep();
298 299
}

300 301
void QmlCppEngine::executeStepOut()
{
302
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
303
    m_activeEngine->executeStepOut();
304 305 306 307
}

void QmlCppEngine::executeNext()
{
308
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
309
    m_activeEngine->executeNext();
310 311 312 313
}

void QmlCppEngine::executeStepI()
{
314
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
315
    m_activeEngine->executeStepI();
316 317 318 319
}

void QmlCppEngine::executeNextI()
{
320
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
321
    m_activeEngine->executeNextI();
322 323 324 325
}

void QmlCppEngine::executeReturn()
{
326
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
327
    m_activeEngine->executeReturn();
328 329 330 331
}

void QmlCppEngine::continueInferior()
{
332
    EDEBUG("\nMASTER CONTINUE INFERIOR"
hjk's avatar
hjk committed
333
        << state() << m_qmlEngine->state());
334
    notifyInferiorRunRequested();
hjk's avatar
hjk committed
335 336 337 338
    if (m_cppEngine->state() == InferiorStopOk) {
        m_cppEngine->continueInferior();
    } else if (m_qmlEngine->state() == InferiorStopOk) {
        m_qmlEngine->continueInferior();
339
    } else {
340
        QTC_ASSERT(false, qDebug() << "MASTER CANNOT CONTINUE INFERIOR"
hjk's avatar
hjk committed
341
                << m_cppEngine->state() << m_qmlEngine->state());
342
        notifyEngineIll();
343
    }
344 345 346 347
}

void QmlCppEngine::interruptInferior()
{
348
    EDEBUG("\nMASTER INTERRUPT INFERIOR");
hjk's avatar
hjk committed
349
    m_cppEngine->requestInterruptInferior();
350 351 352 353
}

void QmlCppEngine::requestInterruptInferior()
{
354
    EDEBUG("\nMASTER REQUEST INTERRUPT INFERIOR");
355
    DebuggerEngine::requestInterruptInferior();
356 357
}

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

void QmlCppEngine::executeRunToFunction(const QString &functionName)
{
hjk's avatar
hjk committed
365
    m_activeEngine->executeRunToFunction(functionName);
366 367
}

368
void QmlCppEngine::executeJumpToLine(const ContextData &data)
369
{
hjk's avatar
hjk committed
370
    m_activeEngine->executeJumpToLine(data);
371 372
}

373
void QmlCppEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
374
{
hjk's avatar
hjk committed
375 376
    m_qmlEngine->executeDebuggerCommand(command, languages);
    m_cppEngine->executeDebuggerCommand(command, languages);
377 378
}

379 380
/////////////////////////////////////////////////////////

381
void QmlCppEngine::setupEngine()
382
{
383
    EDEBUG("\nMASTER SETUP ENGINE");
hjk's avatar
hjk committed
384 385 386
    setActiveEngine(m_cppEngine);
    m_qmlEngine->setupSlaveEngine();
    m_cppEngine->setupSlaveEngine();
387

388
    if (runParameters().remoteSetupNeeded)
389
        notifyEngineRequestRemoteSetup();
390
}
391

392 393
void QmlCppEngine::notifyEngineRunAndInferiorRunOk()
{
394
    EDEBUG("\nMASTER NOTIFY ENGINE RUN AND INFERIOR RUN OK");
395
    DebuggerEngine::notifyEngineRunAndInferiorRunOk();
396 397
}

398 399
void QmlCppEngine::notifyInferiorRunOk()
{
400
    EDEBUG("\nMASTER NOTIFY INFERIOR RUN OK");
401 402 403
    DebuggerEngine::notifyInferiorRunOk();
}

404
void QmlCppEngine::notifyInferiorSpontaneousStop()
405
{
406
    EDEBUG("\nMASTER SPONTANEOUS STOP OK");
407
    DebuggerEngine::notifyInferiorSpontaneousStop();
408 409
}

410
void QmlCppEngine::notifyInferiorShutdownOk()
411
{
412
    EDEBUG("\nMASTER INFERIOR SHUTDOWN OK");
413
    DebuggerEngine::notifyInferiorShutdownOk();
414 415
}

416 417 418 419 420 421 422 423
void QmlCppEngine::notifyInferiorSetupOk()
{
    EDEBUG("\nMASTER INFERIOR SETUP OK");
    DebuggerEngine::notifyInferiorSetupOk();
}

void QmlCppEngine::notifyEngineRemoteServerRunning(const QByteArray &serverChannel, int pid)
{
hjk's avatar
hjk committed
424
    m_cppEngine->notifyEngineRemoteServerRunning(serverChannel, pid);
425 426
}

427
void QmlCppEngine::setupInferior()
428
{
429
    EDEBUG("\nMASTER SETUP INFERIOR");
hjk's avatar
hjk committed
430 431
    m_qmlEngine->setupSlaveInferior();
    m_cppEngine->setupSlaveInferior();
432 433
}

434
void QmlCppEngine::runEngine()
435
{
436
    EDEBUG("\nMASTER RUN ENGINE");
hjk's avatar
hjk committed
437 438
    m_qmlEngine->runSlaveEngine();
    m_cppEngine->runSlaveEngine();
439 440
}

441
void QmlCppEngine::shutdownInferior()
442
{
443
    EDEBUG("\nMASTER SHUTDOWN INFERIOR");
hjk's avatar
hjk committed
444
    m_cppEngine->shutdownInferior();
445 446
}

447
void QmlCppEngine::shutdownEngine()
448
{
449
    EDEBUG("\nMASTER SHUTDOWN ENGINE");
hjk's avatar
hjk committed
450
    m_cppEngine->shutdownSlaveEngine();
451 452 453
    QmlJS::ConsoleManagerInterface *consoleManager = QmlJS::ConsoleManagerInterface::instance();
    if (consoleManager)
        consoleManager->setScriptEvaluator(0);
454 455
}

456 457 458
void QmlCppEngine::quitDebugger()
{
    EDEBUG("\nMASTER QUIT DEBUGGER");
hjk's avatar
hjk committed
459
    m_cppEngine->quitDebugger();
460 461
}

462 463 464
void QmlCppEngine::abortDebugger()
{
    EDEBUG("\nMASTER ABORT DEBUGGER");
hjk's avatar
hjk committed
465
    m_cppEngine->abortDebugger();
466 467
}

468
void QmlCppEngine::setState(DebuggerState newState, bool forced)
469
{
470
    EDEBUG("SET MASTER STATE: " << newState);
hjk's avatar
hjk committed
471 472
    EDEBUG("  CPP STATE: " << m_cppEngine->state());
    EDEBUG("  QML STATE: " << m_qmlEngine->state());
473
    DebuggerEngine::setState(newState, forced);
474 475
}

476 477
void QmlCppEngine::slaveEngineStateChanged
    (DebuggerEngine *slaveEngine, const DebuggerState newState)
478
{
hjk's avatar
hjk committed
479 480
    DebuggerEngine *otherEngine = (slaveEngine == m_cppEngine)
         ? m_qmlEngine : m_cppEngine;
481 482

    QTC_CHECK(otherEngine != slaveEngine);
483

484
    if (debug) {
485 486 487 488
        EDEBUG("GOT SLAVE STATE: " << slaveEngine << newState);
        EDEBUG("  OTHER ENGINE: " << otherEngine << otherEngine->state());
        EDEBUG("  COMBINED ENGINE: " << this << state() << isDying());
    }
489

490 491 492 493 494
    if (state() == DebuggerFinished) {
        // We are done and don't care about slave state changes anymore.
        return;
    }

495 496 497 498 499 500
    // 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.
501

hjk's avatar
hjk committed
502
    if (slaveEngine == m_cppEngine) {
503
        switch (newState) {
504
        case DebuggerNotReady: {
505 506
            // Can this ever happen?
            break;
507 508
        }
        case EngineSetupRequested: {
509 510
            // Set by queueSetupEngine()
            CHECK_STATE(EngineSetupRequested);
511
            break;
512 513
        }
        case EngineSetupFailed: {
514 515 516
            qmlEngine()->quitDebugger();
            notifyEngineSetupFailed();
            break;
517 518
        }
        case EngineSetupOk: {
519
            notifyEngineSetupOk();
520
            break;
521 522
        }
        case InferiorSetupRequested: {
523 524
            // Set by queueSetupInferior()
            CHECK_STATE(InferiorSetupRequested);
525
            break;
526 527
        }
        case InferiorSetupFailed: {
528
            qmlEngine()->quitDebugger();
529
            notifyInferiorSetupFailed();
530
            break;
531 532
        }
        case InferiorSetupOk: {
533
            notifyInferiorSetupOk();
534
            break;
535 536 537
        }
        case EngineRunRequested: {
            // set by queueRunEngine()
538
            break;
539 540
        }
        case EngineRunFailed: {
541
            qmlEngine()->quitDebugger();
542
            notifyEngineRunFailed();
543
            break;
544 545 546
        }
        case InferiorUnrunnable: {
            qmlEngine()->quitDebugger();
hjk's avatar
hjk committed
547
            notifyEngineRunOkAndInferiorUnrunnable();
548
            break;
549 550
        }
        case InferiorRunRequested: {
551 552 553
            // Might be set already by notifyInferiorRunRequested()
            if (state() != InferiorRunRequested) {
                CHECK_STATE(InferiorStopOk);
554
                notifyInferiorRunRequested();
555
            }
556
            break;
557 558
        }
        case InferiorRunOk: {
559
            if (state() == EngineRunRequested)
hjk's avatar
hjk committed
560
                notifyEngineRunAndInferiorRunOk();
561
            else if (state() == InferiorRunRequested)
hjk's avatar
hjk committed
562
                notifyInferiorRunOk();
563 564
            else
                QTC_ASSERT(false, qDebug() << state());
565 566 567 568 569

            if (qmlEngine()->state() == InferiorStopOk) {
                // track qml engine again
                setState(InferiorStopRequested);
                notifyInferiorStopOk();
hjk's avatar
hjk committed
570
                setActiveEngine(m_qmlEngine);
571
            }
572
            break;
573 574
        }
        case InferiorRunFailed: {
575 576 577
            qmlEngine()->quitDebugger();
            notifyInferiorRunFailed();
            break;
578 579
        }
        case InferiorStopRequested: {
hjk's avatar
hjk committed
580
            if (m_activeEngine == cppEngine()) {
581
                if (state() == InferiorRunOk) {
582
                    setState(InferiorStopRequested);
583 584 585 586
                } else {
                    // Might be set by doInterruptInferior()
                    CHECK_STATE(InferiorStopRequested);
                }
587
            } else {
588
                // We're debugging qml, but got an interrupt, or abort
589 590 591 592 593 594 595 596 597
                if (state() == InferiorRunOk) {
                    setState(InferiorStopRequested);
                } else if (state() == InferiorStopOk) {
                    notifyInferiorRunRequested();
                    notifyInferiorRunOk();
                    setState(InferiorStopRequested);
                } else if (state() == InferiorRunRequested) {
                    notifyInferiorRunOk();
                    setState(InferiorStopRequested);
598 599
                } else {
                    QTC_ASSERT(false, qDebug() << state());
600
                }
601
                // now track cpp engine
hjk's avatar
hjk committed
602
                setActiveEngine(m_cppEngine);
603
            }
604
            break;
605 606
        }
        case InferiorStopOk: {
607 608
            if (isDying()) {
                EDEBUG("... CPP ENGINE STOPPED DURING SHUTDOWN ");
609 610 611 612 613
                QTC_ASSERT(state() == InferiorStopRequested
                           || state() == InferiorRunOk
                           || state() == InferiorStopOk, qDebug() << state());

                // Just to make sure, we're shutting down anyway ...
hjk's avatar
hjk committed
614
                setActiveEngine(m_cppEngine);
615

616
                if (state() == InferiorStopRequested)
617 618
                    setState(InferiorStopOk);
                // otherwise we're probably inside notifyInferiorStopOk already
619
            } else {
hjk's avatar
hjk committed
620
                if (m_activeEngine != cppEngine()) {
Friedemann Kleint's avatar
Friedemann Kleint committed
621
                    showStatusMessage(tr("C++ debugger activated"));
hjk's avatar
hjk committed
622
                    setActiveEngine(m_cppEngine);
623 624 625 626 627 628 629 630 631 632
                }
                switch (state()) {
                case InferiorStopRequested:
                    EDEBUG("... CPP ENGINE STOPPED EXPECTEDLY");
                    notifyInferiorStopOk();
                    break;
                case EngineRunRequested:
                    EDEBUG("... CPP ENGINE STOPPED ON STARTUP");
                    notifyEngineRunAndInferiorStopOk();
                    break;
633
                case InferiorRunOk:
634 635 636
                    EDEBUG("... CPP ENGINE STOPPED SPONTANEOUSLY");
                    notifyInferiorSpontaneousStop();
                    break;
637 638 639 640
                case InferiorRunRequested:
                    // can happen if qml engine was active
                    notifyInferiorRunFailed();
                default:
641
                    CHECK_STATE(InferiorStopOk);
642
                    break;
643
                }
644
            }
645
            break;
646 647
        }
        case InferiorStopFailed: {
648
            CHECK_STATE(InferiorStopRequested);
649 650
            notifyInferiorStopFailed();
            break;
651 652
        }
        case InferiorShutdownRequested: {
653
            if (state() == InferiorStopOk) {
654
                setState(InferiorShutdownRequested);
655 656 657 658
            } else {
                // might be set by queueShutdownInferior() already
                CHECK_STATE(InferiorShutdownRequested);
            }
659
            qmlEngine()->quitDebugger();
660
            break;
661 662
        }
        case InferiorShutdownFailed: {
663
            CHECK_STATE(InferiorShutdownRequested);
664 665
            notifyInferiorShutdownFailed();
            break;
666 667
        }
        case InferiorShutdownOk: {
668
            if (state() == InferiorShutdownRequested) {
669
                notifyInferiorShutdownOk();
670
            } else {
671 672 673
                // we got InferiorExitOk before, but ignored it ...
                notifyInferiorExited();
            }
674
            break;
675 676 677
        }
        case EngineShutdownRequested: {
            // set by queueShutdownEngine()
678
            CHECK_STATE(EngineShutdownRequested);
679
            break;
680 681
        }
        case EngineShutdownFailed: {
682
            CHECK_STATE(EngineShutdownRequested);
683 684
            notifyEngineShutdownFailed();
            break;
685
        }
686
        case EngineShutdownOk: {
687
            CHECK_STATE(EngineShutdownRequested);
688
            notifyEngineShutdownOk();
689 690
            break;
        }
691 692
        case DebuggerFinished: {
            // set by queueFinishDebugger()
693
            CHECK_STATE(DebuggerFinished);
694 695
            break;
        }
696
        }
697 698 699
    } else {
        // QML engine state change
        if (newState == InferiorStopOk) {
700 701 702 703
            if (isDying()) {
                EDEBUG("... QML ENGINE STOPPED DURING SHUTDOWN ");

                // Just to make sure, we're shutting down anyway ...
hjk's avatar
hjk committed
704
                setActiveEngine(m_cppEngine);
705 706 707 708 709

                if (state() == InferiorStopRequested)
                    notifyInferiorStopOk();
                // otherwise we're probably inside notifyInferiorStopOk already
            } else {
hjk's avatar
hjk committed
710
                if (m_activeEngine != qmlEngine()) {
711
                    showStatusMessage(tr("QML debugger activated"));
hjk's avatar
hjk committed
712
                    setActiveEngine(m_qmlEngine);
713 714 715 716
                }

                if (state() == InferiorRunOk)
                    notifyInferiorSpontaneousStop();
717
                else if (state() == InferiorStopRequested)
718
                    notifyInferiorStopOk();
719 720
                else
                    CHECK_STATE(InferiorShutdownRequested);
721
            }
722

723
        } else if (newState == InferiorRunOk) {
hjk's avatar
hjk committed
724
            if (m_activeEngine == qmlEngine()) {
725
                CHECK_STATE(InferiorRunRequested);
726
                notifyInferiorRunOk();
727
            }
728
        }
729 730 731
    }
}

732
void QmlCppEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
733
{
734 735
    EDEBUG("MASTER REMOTE SETUP FINISHED");
    DebuggerEngine::notifyEngineRemoteSetupFinished(result);
736