qmlcppengine.cpp 21.8 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/debuggerstartparameters.h>
33
#include <debugger/breakhandler.h>
34
#include <debugger/stackhandler.h>
Christian Kandeler's avatar
Christian Kandeler committed
35
#include <debugger/threaddata.h>
36
#include <debugger/watchhandler.h>
hjk's avatar
hjk committed
37
#include <debugger/console/console.h>
38

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

43
namespace Debugger {
44
namespace Internal {
45

46
47
48
49
enum { debug = 0 };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void QmlCppEngine::changeMemory(MemoryAgent *agent, quint64 addr, const QByteArray &data)
{
    m_cppEngine->changeMemory(agent, addr, data);
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
}

hjk's avatar
hjk committed
187
void QmlCppEngine::setRegisterValue(const QString &name, const QString &value)
188
{
hjk's avatar
hjk committed
189
    m_cppEngine->setRegisterValue(name, 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
}

hjk's avatar
hjk committed
216
QString 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
248
249
250
251
void QmlCppEngine::doUpdateLocals(const UpdateParameters &up)
{
    m_activeEngine->doUpdateLocals(up);
}

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

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

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

272
273
274
275
276
void QmlCppEngine::notifyInferiorIll()
{
    //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
    m_activeEngine = m_cppEngine;
hjk's avatar
hjk committed
377
378
    m_qmlEngine->setupSlaveEngine();
    m_cppEngine->setupSlaveEngine();
379

380
    if (runParameters().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
void QmlCppEngine::notifyInferiorSetupOk()
{
    EDEBUG("\nMASTER INFERIOR SETUP OK");
    DebuggerEngine::notifyInferiorSetupOk();
}

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

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

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

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

439
void QmlCppEngine::shutdownEngine()
440
{
441
    EDEBUG("\nMASTER SHUTDOWN ENGINE");
442
    m_qmlEngine->shutdownSlaveEngine();
hjk's avatar
hjk committed
443
    m_cppEngine->shutdownSlaveEngine();
444
445
}

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

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

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

466
467
void QmlCppEngine::slaveEngineStateChanged
    (DebuggerEngine *slaveEngine, const DebuggerState newState)
468
{
hjk's avatar
hjk committed
469
    DebuggerEngine *otherEngine = (slaveEngine == m_cppEngine)
470
         ? m_qmlEngine.data() : m_cppEngine.data();
471

hjk's avatar
hjk committed
472
    QTC_ASSERT(otherEngine, return);
473
    QTC_CHECK(otherEngine != slaveEngine);
474

475
    if (debug) {
476
477
478
479
        EDEBUG("GOT SLAVE STATE: " << slaveEngine << newState);
        EDEBUG("  OTHER ENGINE: " << otherEngine << otherEngine->state());
        EDEBUG("  COMBINED ENGINE: " << this << state() << isDying());
    }
480

481
482
483
484
485
    if (state() == DebuggerFinished) {
        // We are done and don't care about slave state changes anymore.
        return;
    }

486
487
488
489
490
491
    // 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.
492

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

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

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

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

                // Just to make sure, we're shutting down anyway ...
hjk's avatar
hjk committed
698
                setActiveEngine(m_cppEngine);
699
700
701
702
703

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

                if (state() == InferiorRunOk)
                    notifyInferiorSpontaneousStop();
711
                else if (state() == InferiorStopRequested)
712
                    notifyInferiorStopOk();
713
714
                else
                    CHECK_STATE(InferiorShutdownRequested);
715
            }
716

717
        } else if (newState == InferiorRunOk) {
hjk's avatar
hjk committed
718
            if (m_activeEngine == qmlEngine()) {
719
                CHECK_STATE(InferiorRunRequested);
720
                notifyInferiorRunOk();
721
            }
722
        }
723
724
725
    }
}

726
void QmlCppEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
727
{
728
729
    EDEBUG("MASTER REMOTE SETUP FINISHED");
    DebuggerEngine::notifyEngineRemoteSetupFinished(result);
730

731
732
    cppEngine()->notifyEngineRemoteSetupFinished(result);
    qmlEngine()->notifyEngineRemoteSetupFinished(result);
733
734
}

735
736
void QmlCppEngine::resetLocation()
{
hjk's avatar
hjk committed
737
738
739
740
    if (m_qmlEngine)
        m_qmlEngine->resetLocation();
    if (m_cppEngine)
        m_cppEngine->resetLocation();
741
742

    DebuggerEngine::resetLocation();
743
744
}

745
746
747
748
749
750
void QmlCppEngine::reloadDebuggingHelpers()
{
    if (m_cppEngine)
        m_cppEngine->reloadDebuggingHelpers();
}

751
752
753
754
755
756
void QmlCppEngine::debugLastCommand()
{
    if (m_cppEngine)
        m_cppEngine->debugLastCommand();
}

757
758
DebuggerEngine *QmlCppEngine::qmlEngine() const
{
hjk's avatar
hjk committed
759
    return m_qmlEngine;
760
761
}

762
763
764
765
766
767
768
void QmlCppEngine::setRunTool(DebuggerRunTool *runTool)
{
    DebuggerEngine::setRunTool(runTool);
    m_qmlEngine->setRunTool(runTool);
    m_cppEngine->setRunTool(runTool);
}

769
770
void QmlCppEngine::setActiveEngine(DebuggerEngine *engine)
{
hjk's avatar
hjk committed
771
    m_activeEngine = engine;
772
773
774
    updateViews();
}

775
776
777
778
779
780
void QmlCppEngine::loadAdditionalQmlStack()
{
    if (m_cppEngine)
        m_cppEngine->loadAdditionalQmlStack();
}

781
} // namespace Internal
782
} // namespace Debugger