qmlcppengine.cpp 23.6 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12
** 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
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** 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 25 26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt 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
#include <debugger/debuggerruncontrol.h>
34 35 36
#include <debugger/debuggerstartparameters.h>
#include <debugger/stackhandler.h>
#include <debugger/watchhandler.h>
37

38
#include <utils/qtcassert.h>
39
#include <texteditor/texteditor.h>
40 41
#include <qmljseditor/qmljseditorconstants.h>
#include <cppeditor/cppeditorconstants.h>
42
#include <qmljs/consolemanagerinterface.h>
43

44
namespace Debugger {
45
namespace Internal {
46

47 48 49 50
enum { debug = 0 };

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

51 52
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &sp,
                                   QString *errorMessage)
53
{
hjk's avatar
hjk committed
54
    QmlCppEngine *newEngine = new QmlCppEngine(sp, errorMessage);
hjk's avatar
hjk committed
55
    if (newEngine->cppEngine())
56
        return newEngine;
hjk's avatar
hjk committed
57 58
    delete newEngine;
    return 0;
59
}
hjk's avatar
hjk committed
60

hjk's avatar
hjk committed
61 62 63 64 65 66 67

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

hjk's avatar
hjk committed
68
QmlCppEngine::QmlCppEngine(const DebuggerStartParameters &sp, QString *errorMessage)
69
    : DebuggerEngine(sp)
hjk's avatar
hjk committed
70
{
71
    setObjectName(QLatin1String("QmlCppEngine"));
hjk's avatar
hjk committed
72 73 74
    m_qmlEngine = new QmlEngine(sp, this);
    m_cppEngine = DebuggerRunControlFactory::createEngine(sp.firstSlaveEngineType, sp, errorMessage);
    if (!m_cppEngine) {
Friedemann Kleint's avatar
Friedemann Kleint committed
75
        *errorMessage = tr("The slave debugging engine required for combined QML/C++-Debugging could not be created: %1").arg(*errorMessage);
76 77
        return;
    }
hjk's avatar
hjk committed
78 79
    m_cppEngine->setMasterEngine(this);
    setActiveEngine(m_cppEngine);
80 81 82 83
}

QmlCppEngine::~QmlCppEngine()
{
hjk's avatar
hjk committed
84 85
    delete m_qmlEngine;
    delete m_cppEngine;
86 87
}

88 89
bool QmlCppEngine::canDisplayTooltip() const
{
hjk's avatar
hjk committed
90
    return m_cppEngine->canDisplayTooltip() || m_qmlEngine->canDisplayTooltip();
91 92
}

93
bool QmlCppEngine::setToolTipExpression(TextEditor::TextEditorWidget *editorWidget, const DebuggerToolTipContext &ctx)
94
{
95
    QTC_ASSERT(editorWidget, return false);
96
    bool success = false;
97 98 99 100 101
    Core::Id id = editorWidget->textDocument()->id();
    if (id == CppEditor::Constants::CPPEDITOR_ID)
        success = m_cppEngine->setToolTipExpression(editorWidget, ctx);
    else if (id == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
        success = m_qmlEngine->setToolTipExpression(editorWidget, ctx);
102
    return success;
103 104
}

hjk's avatar
hjk committed
105 106
void QmlCppEngine::updateWatchData(const WatchData &data,
    const WatchUpdateFlags &flags)
107
{
Aurindam Jana's avatar
Aurindam Jana committed
108
    if (data.isInspect())
hjk's avatar
hjk committed
109
        m_qmlEngine->updateWatchData(data, flags);
110
    else
hjk's avatar
hjk committed
111
        m_activeEngine->updateWatchData(data, flags);
112 113
}

114 115 116 117
void QmlCppEngine::watchDataSelected(const QByteArray &iname)
{
    const WatchData *wd = watchHandler()->findData(iname);
    if (wd && wd->isInspect())
hjk's avatar
hjk committed
118
        m_qmlEngine->watchDataSelected(iname);
119 120
}

121 122
void QmlCppEngine::watchPoint(const QPoint &point)
{
hjk's avatar
hjk committed
123
    m_cppEngine->watchPoint(point);
124 125
}

126
void QmlCppEngine::fetchMemory(MemoryAgent *ma, QObject *obj,
127 128
        quint64 addr, quint64 length)
{
hjk's avatar
hjk committed
129
    m_cppEngine->fetchMemory(ma, obj, addr, length);
130 131
}

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

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

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

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

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

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

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

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

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

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

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

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

void QmlCppEngine::setRegisterValue(int regnr, const QString &value)
{
hjk's avatar
hjk committed
189
    m_cppEngine->setRegisterValue(regnr, value);
190 191
}

192 193

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

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

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

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

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

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

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

247
bool QmlCppEngine::acceptsBreakpoint(BreakpointModelId id) const
248
{
hjk's avatar
hjk committed
249 250
    return m_cppEngine->acceptsBreakpoint(id)
        || m_qmlEngine->acceptsBreakpoint(id);
251 252
}

hjk's avatar
hjk committed
253
void QmlCppEngine::selectThread(ThreadId threadId)
254
{
hjk's avatar
hjk committed
255
    m_activeEngine->selectThread(threadId);
256 257
}

hjk's avatar
hjk committed
258 259
void QmlCppEngine::assignValueInDebugger(const WatchData *data,
    const QString &expr, const QVariant &value)
260
{
Christian Kandeler's avatar
Christian Kandeler committed
261
    if (data->isInspect())
hjk's avatar
hjk committed
262
        m_qmlEngine->assignValueInDebugger(data, expr, value);
Aurindam Jana's avatar
Aurindam Jana committed
263
    else
hjk's avatar
hjk committed
264
        m_activeEngine->assignValueInDebugger(data, expr, value);
265 266
}

267 268 269 270 271 272 273 274 275 276
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
277
    m_cppEngine->notifyInferiorIll();
278 279
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

371 372
/////////////////////////////////////////////////////////

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

380
    if (startParameters().remoteSetupNeeded)
381
        notifyEngineRequestRemoteSetup();
382
}
383

384 385
void QmlCppEngine::notifyEngineRunAndInferiorRunOk()
{
386
    EDEBUG("\nMASTER NOTIFY ENGINE RUN AND INFERIOR RUN OK");
387
    DebuggerEngine::notifyEngineRunAndInferiorRunOk();
388 389
}

390 391
void QmlCppEngine::notifyInferiorRunOk()
{
392
    EDEBUG("\nMASTER NOTIFY INFERIOR RUN OK");
393 394 395
    DebuggerEngine::notifyInferiorRunOk();
}

396
void QmlCppEngine::notifyInferiorSpontaneousStop()
397
{
398
    EDEBUG("\nMASTER SPONTANEOUS STOP OK");
399
    DebuggerEngine::notifyInferiorSpontaneousStop();
400 401
}

402
void QmlCppEngine::notifyInferiorShutdownOk()
403
{
404
    EDEBUG("\nMASTER INFERIOR SHUTDOWN OK");
405
    DebuggerEngine::notifyInferiorShutdownOk();
406 407
}

408 409 410 411 412 413 414 415 416
void QmlCppEngine::notifyInferiorSetupOk()
{
    EDEBUG("\nMASTER INFERIOR SETUP OK");
    emit aboutToNotifyInferiorSetupOk();
    DebuggerEngine::notifyInferiorSetupOk();
}

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

420
void QmlCppEngine::setupInferior()
421
{
422
    EDEBUG("\nMASTER SETUP INFERIOR");
hjk's avatar
hjk committed
423 424
    m_qmlEngine->setupSlaveInferior();
    m_cppEngine->setupSlaveInferior();
425 426
}

427
void QmlCppEngine::runEngine()
428
{
429
    EDEBUG("\nMASTER RUN ENGINE");
hjk's avatar
hjk committed
430 431
    m_qmlEngine->runSlaveEngine();
    m_cppEngine->runSlaveEngine();
432 433
}

434
void QmlCppEngine::shutdownInferior()
435
{
436
    EDEBUG("\nMASTER SHUTDOWN INFERIOR");
hjk's avatar
hjk committed
437
    m_cppEngine->shutdownInferior();
438 439
}

440
void QmlCppEngine::shutdownEngine()
441
{
442
    EDEBUG("\nMASTER SHUTDOWN ENGINE");
hjk's avatar
hjk committed
443
    m_cppEngine->shutdownSlaveEngine();
444 445 446
    QmlJS::ConsoleManagerInterface *consoleManager = QmlJS::ConsoleManagerInterface::instance();
    if (consoleManager)
        consoleManager->setScriptEvaluator(0);
447 448
}

449 450 451
void QmlCppEngine::quitDebugger()
{
    EDEBUG("\nMASTER QUIT DEBUGGER");
hjk's avatar
hjk committed
452
    m_cppEngine->quitDebugger();
453 454
}

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

461
void QmlCppEngine::setState(DebuggerState newState, bool forced)
462
{
463
    EDEBUG("SET MASTER STATE: " << newState);
hjk's avatar
hjk committed
464 465
    EDEBUG("  CPP STATE: " << m_cppEngine->state());
    EDEBUG("  QML STATE: " << m_qmlEngine->state());
466
    DebuggerEngine::setState(newState, forced);
467 468
}

469 470
void QmlCppEngine::slaveEngineStateChanged
    (DebuggerEngine *slaveEngine, const DebuggerState newState)
471
{
hjk's avatar
hjk committed
472 473
    DebuggerEngine *otherEngine = (slaveEngine == m_cppEngine)
         ? m_qmlEngine : m_cppEngine;
474 475

    QTC_CHECK(otherEngine != slaveEngine);
476

477
    if (debug) {
478 479 480 481
        EDEBUG("GOT SLAVE STATE: " << slaveEngine << newState);
        EDEBUG("  OTHER ENGINE: " << otherEngine << otherEngine->state());
        EDEBUG("  COMBINED ENGINE: " << this << state() << isDying());
    }
482 483 484 485 486 487 488

    // 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.
489

hjk's avatar
hjk committed
490
    if (slaveEngine == m_cppEngine) {
491
        switch (newState) {
492
        case DebuggerNotReady: {
493 494
            // Can this ever happen?
            break;
495 496 497 498
        }
        case EngineSetupRequested: {
            // set by queueSetupEngine()
            QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
499
            break;
500 501
        }
        case EngineSetupFailed: {
502 503 504
            qmlEngine()->quitDebugger();
            notifyEngineSetupFailed();
            break;
505 506
        }
        case EngineSetupOk: {
507
            notifyEngineSetupOk();
508
            break;
509 510 511 512
        }
        case InferiorSetupRequested: {
            // set by queueSetupInferior()
            QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
513
            break;
514 515
        }
        case InferiorSetupFailed: {
516
            qmlEngine()->quitDebugger();
517
            notifyInferiorSetupFailed();
518
            break;
519 520
        }
        case InferiorSetupOk: {
521
            notifyInferiorSetupOk();
522
            break;
523 524 525
        }
        case EngineRunRequested: {
            // set by queueRunEngine()
526
            break;
527 528
        }
        case EngineRunFailed: {
529
            qmlEngine()->quitDebugger();
530
            notifyEngineRunFailed();
531
            break;
532 533 534
        }
        case InferiorUnrunnable: {
            qmlEngine()->quitDebugger();
535 536
            notifyInferiorUnrunnable();
            break;
537 538 539 540 541 542 543
        }
        case InferiorRunRequested: {
            // might be set already by notifyInferiorRunRequested()
            QTC_ASSERT(state() == InferiorRunRequested
                       || state() == InferiorStopOk, qDebug() << state());
            if (state() != InferiorRunRequested)
                notifyInferiorRunRequested();
544
            break;
545 546 547 548
        }
        case InferiorRunOk: {
            QTC_ASSERT(state() == EngineRunRequested
                       || state() == InferiorRunRequested, qDebug() << state());
549
            if (state() == EngineRunRequested)
hjk's avatar
hjk committed
550
                notifyEngineRunAndInferiorRunOk();
551
            else if (state() == InferiorRunRequested)
hjk's avatar
hjk committed
552
                notifyInferiorRunOk();
553 554 555 556 557

            if (qmlEngine()->state() == InferiorStopOk) {
                // track qml engine again
                setState(InferiorStopRequested);
                notifyInferiorStopOk();
hjk's avatar
hjk committed
558
                setActiveEngine(m_qmlEngine);
559
            }
560
            break;
561 562
        }
        case InferiorRunFailed: {
563 564 565
            qmlEngine()->quitDebugger();
            notifyInferiorRunFailed();
            break;
566 567
        }
        case InferiorStopRequested: {
hjk's avatar
hjk committed
568
            if (m_activeEngine == cppEngine()) {
569 570 571 572 573 574
                // might be set by doInterruptInferior()
                QTC_ASSERT(state() == InferiorStopRequested
                           || state() == InferiorRunOk, qDebug() << state());
                if (state() == InferiorRunOk)
                    setState(InferiorStopRequested);
            } else {
575
                // we're debugging qml, but got an interrupt, or abort
576 577 578 579 580 581 582 583 584 585 586 587 588 589
                QTC_ASSERT(state() == InferiorRunOk
                          || state() == InferiorStopOk
                           || state() == InferiorRunRequested, qDebug() << state());

                if (state() == InferiorRunOk) {
                    setState(InferiorStopRequested);
                } else if (state() == InferiorStopOk) {
                    notifyInferiorRunRequested();
                    notifyInferiorRunOk();
                    setState(InferiorStopRequested);
                } else if (state() == InferiorRunRequested) {
                    notifyInferiorRunOk();
                    setState(InferiorStopRequested);
                }
590
                // now track cpp engine
hjk's avatar
hjk committed
591
                setActiveEngine(m_cppEngine);
592
            }
593
            break;
594 595
        }
        case InferiorStopOk: {
596 597
            if (isDying()) {
                EDEBUG("... CPP ENGINE STOPPED DURING SHUTDOWN ");
598 599 600 601 602
                QTC_ASSERT(state() == InferiorStopRequested
                           || state() == InferiorRunOk
                           || state() == InferiorStopOk, qDebug() << state());

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

605
                if (state() == InferiorStopRequested)
606 607
                    setState(InferiorStopOk);
                // otherwise we're probably inside notifyInferiorStopOk already
608
            } else {
hjk's avatar
hjk committed
609
                if (m_activeEngine != cppEngine()) {
Friedemann Kleint's avatar
Friedemann Kleint committed
610
                    showStatusMessage(tr("C++ debugger activated"));
hjk's avatar
hjk committed
611
                    setActiveEngine(m_cppEngine);
612
                }
613 614 615 616 617 618

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

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

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

                QTC_ASSERT(state() == InferiorRunOk
715 716
                           || state() == InferiorStopRequested
                           || state() == InferiorShutdownRequested, qDebug() << state());
717 718 719

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

724
        } else if (newState == InferiorRunOk) {
hjk's avatar
hjk committed
725
            if (m_activeEngine == qmlEngine()) {
726
                QTC_ASSERT(state() == InferiorRunRequested, qDebug() << state());
727
                notifyInferiorRunOk();
728
            }
729
        }
730 731 732
    }
}

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

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

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

751 752
void QmlCppEngine::resetLocation()
{
hjk's avatar
hjk committed
753 754 755 756
    if (m_qmlEngine)
        m_qmlEngine->resetLocation();
    if (m_cppEngine)
        m_cppEngine->resetLocation();
757 758

    DebuggerEngine::resetLocation();
759 760
}

761 762 763 764 765 766
void QmlCppEngine::reloadDebuggingHelpers()
{
    if (m_cppEngine)
        m_cppEngine->reloadDebuggingHelpers();
}

767 768