qmlcppengine.cpp 22.6 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, QStringList *errors)
64
{
65
    QmlCppEngine *newEngine = new QmlCppEngine(sp, errors);
hjk's avatar
hjk committed
66
    if (newEngine->cppEngine())
67
        return newEngine;
hjk's avatar
hjk committed
68 69
    delete newEngine;
    return 0;
70
}
hjk's avatar
hjk committed
71

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

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

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

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

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

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

hjk's avatar
hjk committed
117
void QmlCppEngine::updateItem(const QByteArray &iname)
118
{
119
    if (iname.startsWith("inspect."))
hjk's avatar
hjk committed
120
        m_qmlEngine->updateItem(iname);
121
    else
hjk's avatar
hjk committed
122
        m_activeEngine->updateItem(iname);
123 124
}

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

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

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

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

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

hjk's avatar
hjk committed
152
    m_activeEngine->activateFrame(index);
Aurindam Jana's avatar
Aurindam Jana committed
153

154
    stackHandler()->setCurrentIndex(index);
155 156 157 158
}

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

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

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

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

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

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

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

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

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

202 203

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

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

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

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

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

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

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

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

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

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

277 278 279 280 281 282 283 284 285 286
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
287
    m_cppEngine->notifyInferiorIll();
288 289
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

381 382
/////////////////////////////////////////////////////////

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

390
    if (runParameters().remoteSetupNeeded)
391
        notifyEngineRequestRemoteSetup();
392
}
393

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    QTC_CHECK(otherEngine != slaveEngine);
485

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

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

497 498 499 500 501 502
    // 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.
503

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

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

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

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

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

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

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

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

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

739 740
    cppEngine()->notifyEngineRemoteSetupFinished(result);
    qmlEngine()->notifyEngineRemoteSetupFinished(result);
741 742
}

743 744
void QmlCppEngine::showMessage(const QString &msg, int channel, int timeout) const
{
745
    if (channel == AppOutput || channel == AppError || channel == AppStuff) {
746
        // message is from CppEngine, allow qml engine to process
hjk's avatar
hjk committed
747
        m_qmlEngine->filterApplicationMessage(msg, channel);
748 749 750 751
    }
    DebuggerEngine::showMessage(msg, channel, timeout);
}

752 753
void QmlCppEngine::resetLocation()
{
hjk's avatar
hjk committed
754 755