diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp
index 33215cd7d930a05bc3edbf30555f79ee954599e8..0eaf4868f8a0fcc2f368ce1c1a365e9512577b13 100644
--- a/src/plugins/debugger/cdb/cdbengine.cpp
+++ b/src/plugins/debugger/cdb/cdbengine.cpp
@@ -200,11 +200,11 @@ static inline bool validMode(DebuggerStartMode sm)
 }
 
 // Accessed by RunControlFactory
-DebuggerEngine *createCdbEngine(const DebuggerRunParameters &rp, QStringList *errors)
+DebuggerEngine *createCdbEngine(QStringList *errors, DebuggerStartMode sm)
 {
     if (HostOsInfo::isWindowsHost()) {
-        if (validMode(rp.startMode))
-            return new CdbEngine(rp);
+        if (validMode(sm))
+            return new CdbEngine();
         errors->append(CdbEngine::tr("Internal error: Invalid start parameters passed for the CDB engine."));
     } else {
         errors->append(CdbEngine::tr("Unsupported CDB host system."));
@@ -222,8 +222,7 @@ void addCdbOptionPages(QList<Core::IOptionsPage *> *opts)
 
 #define QT_CREATOR_CDB_EXT "qtcreatorcdbext"
 
-CdbEngine::CdbEngine(const DebuggerRunParameters &sp) :
-    DebuggerEngine(sp),
+CdbEngine::CdbEngine() :
     m_tokenPrefix("<token>"),
     m_effectiveStartMode(NoStartMode),
     m_accessible(false),
diff --git a/src/plugins/debugger/cdb/cdbengine.h b/src/plugins/debugger/cdb/cdbengine.h
index ac2e0679d6db22e06644ea78dabe562a51a5a6e5..30bccb4a116a72586fd779335eee18df3e33aeab 100644
--- a/src/plugins/debugger/cdb/cdbengine.h
+++ b/src/plugins/debugger/cdb/cdbengine.h
@@ -56,7 +56,7 @@ public:
     typedef QSharedPointer<CdbCommand> CdbCommandPtr;
     typedef std::function<void(const DebuggerResponse &)> CommandHandler;
 
-    CdbEngine(const DebuggerRunParameters &sp);
+    explicit CdbEngine();
     ~CdbEngine() override;
 
     // Factory function that returns 0 if the debug engine library cannot be found.
diff --git a/src/plugins/debugger/debuggercore.h b/src/plugins/debugger/debuggercore.h
index c4e3e433e95c141857f1566b14d3fa3d06d04fd1..2bd9bc0a03d074be013885a7f33fc9f5c56c9a3e 100644
--- a/src/plugins/debugger/debuggercore.h
+++ b/src/plugins/debugger/debuggercore.h
@@ -47,6 +47,9 @@ namespace CPlusPlus { class Snapshot; }
 namespace Utils { class SavedAction; }
 
 namespace Debugger {
+
+class DebuggerRunTool;
+
 namespace Internal {
 
 class BreakHandler;
@@ -63,7 +66,7 @@ enum TestCases
 };
 
 // Some convenience.
-void updateState(DebuggerEngine *engine);
+void updateState(DebuggerRunTool *runTool);
 void updateWatchersWindow(bool showWatch, bool showReturn);
 const CPlusPlus::Snapshot &cppCodeModelSnapshot();
 bool hasSnapshots();
@@ -73,9 +76,9 @@ void openTextEditor(const QString &titlePattern, const QString &contents);
 void showMessage(const QString &msg, int channel, int timeout = -1);
 
 bool isReverseDebugging();
-void runControlStarted(DebuggerEngine *engine);
-void runControlFinished(DebuggerEngine *engine);
-void displayDebugger(DebuggerEngine *engine, bool updateEngine);
+void runControlStarted(DebuggerRunTool *runTool);
+void runControlFinished(DebuggerRunTool *runTool);
+void displayDebugger(DebuggerRunTool *runTool, bool updateEngine);
 void synchronizeBreakpoints();
 
 void saveModeToRestore();
diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 31a3997dd59fbbe2b9de5e3e043e32f208814423..ea8d59b33948272a97f779e6760fb4b6c6ca44ae 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -89,9 +89,6 @@ using namespace Utils;
 #include <valgrind/callgrind.h>
 #endif
 
-// VariableManager Prefix
-const char PrefixDebugExecutable[]  = "DebuggedExecutable";
-
 namespace Debugger {
 
 QDebug operator<<(QDebug d, DebuggerState state)
@@ -227,9 +224,8 @@ class DebuggerEnginePrivate : public QObject
     Q_OBJECT
 
 public:
-    DebuggerEnginePrivate(DebuggerEngine *engine, const DebuggerRunParameters &sp)
+    DebuggerEnginePrivate(DebuggerEngine *engine)
       : m_engine(engine),
-        m_runParameters(sp),
         m_modulesHandler(engine),
         m_registerHandler(engine),
         m_sourceFilesHandler(engine),
@@ -243,10 +239,6 @@ public:
                 this, &DebuggerEnginePrivate::resetLocation);
         connect(action(IntelFlavor), &Utils::SavedAction::valueChanged,
                 this, &DebuggerEnginePrivate::reloadDisassembly);
-
-        Utils::globalMacroExpander()->registerFileVariables(PrefixDebugExecutable,
-            tr("Debugged executable"),
-            [this] { return m_runParameters.inferior.executable; });
     }
 
     void doSetupEngine();
@@ -350,8 +342,6 @@ public:
     DebuggerEngine *m_masterEngine = nullptr; // Not owned
     QPointer<DebuggerRunTool> m_runTool;  // Not owned.
 
-    DebuggerRunParameters m_runParameters;
-
     // The current state.
     DebuggerState m_state = DebuggerNotReady;
 
@@ -397,9 +387,10 @@ public:
 //
 //////////////////////////////////////////////////////////////////////
 
-DebuggerEngine::DebuggerEngine(const DebuggerRunParameters &startParameters)
-  : d(new DebuggerEnginePrivate(this, startParameters))
-{}
+DebuggerEngine::DebuggerEngine()
+  : d(new DebuggerEnginePrivate(this))
+{
+}
 
 DebuggerEngine::~DebuggerEngine()
 {
@@ -572,13 +563,13 @@ void DebuggerEngine::start()
     fp->setKeepOnFinish(FutureProgress::HideOnFinish);
     d->m_progress.reportStarted();
 
-    d->m_inferiorPid = d->m_runParameters.attachPID.isValid()
-        ? d->m_runParameters.attachPID : ProcessHandle();
+    DebuggerRunParameters &rp = runParameters();
+    d->m_inferiorPid = rp.attachPID.isValid() ? rp.attachPID : ProcessHandle();
     if (d->m_inferiorPid.isValid())
         runControl()->setApplicationProcessHandle(d->m_inferiorPid);
 
     if (isNativeMixedActive())
-        d->m_runParameters.inferior.environment.set("QV4_FORCE_INTERPRETER", "1");
+        rp.inferior.environment.set("QV4_FORCE_INTERPRETER", "1");
 
     action(OperateByInstruction)->setEnabled(hasCapability(DisassemblerCapability));
 
@@ -669,12 +660,12 @@ void DebuggerEngine::handleFinished()
 
 const DebuggerRunParameters &DebuggerEngine::runParameters() const
 {
-    return d->m_runParameters;
+    return runTool()->runParameters();
 }
 
 DebuggerRunParameters &DebuggerEngine::runParameters()
 {
-    return d->m_runParameters;
+    return runTool()->runParameters();
 }
 
 DebuggerState DebuggerEngine::state() const
@@ -774,7 +765,7 @@ void DebuggerEnginePrivate::doSetupEngine()
 {
     m_engine->showMessage("CALL: SETUP ENGINE");
     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << m_engine << state());
-    m_engine->validateExecutable(&m_runParameters);
+    m_engine->validateExecutable();
     m_engine->setupEngine();
 }
 
@@ -805,7 +796,6 @@ void DebuggerEngine::notifyEngineSetupOk()
     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << this << state());
     setState(EngineSetupOk);
 
-    Internal::runControlStarted(this);
     d->queueSetupInferior();
 }
 
@@ -838,7 +828,7 @@ void DebuggerEngine::notifyInferiorSetupOk()
 #ifdef WITH_BENCHMARK
     CALLGRIND_START_INSTRUMENTATION;
 #endif
-    runTool()->aboutToNotifyInferiorSetupOk();
+    runTool()->aboutToNotifyInferiorSetupOk(); // FIXME: Remove, only used for Android.
     showMessage("NOTE: INFERIOR SETUP OK");
     QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << this << state());
     setState(InferiorSetupOk);
@@ -905,21 +895,22 @@ void DebuggerEngine::setRemoteParameters(const RemoteSetupResult &result)
     showMessage(QString("NOTE: REMOTE SETUP DONE: GDB SERVER PORT: %1  QML PORT %2")
                 .arg(result.gdbServerPort.number()).arg(result.qmlServerPort.number()));
 
+    DebuggerRunParameters &rp = runParameters();
     if (result.gdbServerPort.isValid()) {
-        QString &rc = d->m_runParameters.remoteChannel;
+        QString &rc = rp.remoteChannel;
         const int sepIndex = rc.lastIndexOf(':');
         if (sepIndex != -1) {
             rc.replace(sepIndex + 1, rc.count() - sepIndex - 1,
                        QString::number(result.gdbServerPort.number()));
         }
-    } else if (result.inferiorPid != InvalidPid && runParameters().startMode == AttachExternal) {
+    } else if (result.inferiorPid != InvalidPid && rp.startMode == AttachExternal) {
         // e.g. iOS Simulator
-        runParameters().attachPID = ProcessHandle(result.inferiorPid);
+        rp.attachPID = ProcessHandle(result.inferiorPid);
     }
 
     if (result.qmlServerPort.isValid()) {
-        d->m_runParameters.qmlServer.port = result.qmlServerPort;
-        d->m_runParameters.inferior.commandLineArguments.replace("%qml_port%",
+        rp.qmlServer.port = result.qmlServerPort;
+        rp.inferior.commandLineArguments.replace("%qml_port%",
                         QString::number(result.qmlServerPort.number()));
     }
 }
@@ -1298,7 +1289,8 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
     }
 
     if (state == InferiorUnrunnable || state == InferiorRunOk) {
-        if (isMasterEngine() && runTool())
+        // FIXME: Called again for combined engine.
+        if (isMasterEngine() && runTool() && !runTool()->runControl()->isRunning())
             runTool()->reportStarted();
     }
 
@@ -1325,8 +1317,7 @@ void DebuggerEngine::updateViews()
 {
     // The slave engines are not entitled to change the view. Their wishes
     // should be coordinated by their master engine.
-    if (isMasterEngine())
-        Internal::updateState(this);
+    Internal::updateState(runTool());
 }
 
 bool DebuggerEngine::isSlaveEngine() const
@@ -1373,7 +1364,7 @@ void DebuggerEngine::removeBreakpointMarker(const Breakpoint &bp)
 
 QString DebuggerEngine::expand(const QString &string) const
 {
-    return d->m_runParameters.macroExpander->expand(string);
+    return runParameters().macroExpander->expand(string);
 }
 
 QString DebuggerEngine::nativeStartupCommands() const
@@ -1456,10 +1447,9 @@ void DebuggerEngine::notifyInferiorPid(const ProcessHandle &pid)
     if (pid.isValid()) {
         runControl()->setApplicationProcessHandle(pid);
         showMessage(tr("Taking notice of pid %1").arg(pid.pid()));
-        if (d->m_runParameters.startMode == StartInternal
-            || d->m_runParameters.startMode == StartExternal
-            || d->m_runParameters.startMode == AttachExternal)
-        QTimer::singleShot(0, d, &DebuggerEnginePrivate::raiseApplication);
+        DebuggerStartMode sm = runParameters().startMode;
+        if (sm == StartInternal || sm == StartExternal || sm == AttachExternal)
+            QTimer::singleShot(0, d, &DebuggerEnginePrivate::raiseApplication);
     }
 }
 
@@ -1542,7 +1532,7 @@ RunControl *DebuggerEngine::runControl() const
 
 DebuggerRunTool *DebuggerEngine::runTool() const
 {
-    return d->m_masterEngine ? d->m_masterEngine->runTool() : d->m_runTool.data();
+    return d->m_runTool.data();
 }
 
 Terminal *DebuggerEngine::terminal() const
@@ -1919,8 +1909,9 @@ void DebuggerEngine::setStateDebugging(bool on)
     d->m_isStateDebugging = on;
 }
 
-void DebuggerEngine::validateExecutable(DebuggerRunParameters *sp)
+void DebuggerEngine::validateExecutable()
 {
+    DebuggerRunParameters *sp = &runParameters();
     if (sp->skipExecutableValidation)
         return;
     if (sp->languages == QmlLanguage)
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index aa927b89dd2bba94a24ebff129d2f994f782d82d..b8c068549db1bae2240a685ae64e596c657b8c80 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -194,7 +194,7 @@ class DebuggerEngine : public QObject
     Q_OBJECT
 
 public:
-    explicit DebuggerEngine(const DebuggerRunParameters &sp);
+    explicit DebuggerEngine();
     virtual ~DebuggerEngine();
 
     const DebuggerRunParameters &runParameters() const;
@@ -320,12 +320,14 @@ public:
     virtual void resetLocation();
     virtual void gotoLocation(const Internal::Location &location);
     Q_SLOT virtual void quitDebugger(); // called by DebuggerRunControl
+    virtual void exitDebugger(); // called by DebuggerRunControl
     virtual void abortDebugger(); // called by DebuggerPlugin
 
-    virtual void updateViews();
+    void updateViews();
     bool isSlaveEngine() const;
     bool isMasterEngine() const;
     DebuggerEngine *masterEngine() const;
+    virtual DebuggerEngine *activeEngine() { return this; }
     virtual DebuggerEngine *cppEngine() { return 0; }
 
     virtual bool canDisplayTooltip() const;
@@ -398,7 +400,6 @@ protected:
     virtual void resetInferior() {}
 
     virtual void detachDebugger();
-    virtual void exitDebugger();
     virtual void executeStep();
     virtual void executeStepOut();
     virtual void executeNext();
@@ -436,7 +437,7 @@ protected:
     bool isStateDebugging() const;
     void setStateDebugging(bool on);
 
-    static void validateExecutable(DebuggerRunParameters *sp);
+    void validateExecutable();
 
     virtual void setupSlaveInferior();
     virtual void setupSlaveEngine();
@@ -478,7 +479,6 @@ private:
     QPointer<DebuggerEngine> m_engine;
 };
 
-DebuggerEngine *createEngine(DebuggerEngineType et, const DebuggerRunParameters &rp, QStringList *errors);
 ProjectExplorer::RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, ProjectExplorer::Kit *kit);
 
 } // namespace Internal
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 5af6473faf98db831289ff461f003988ddc7385e..a5b23bb3bffcfbc15dd1eea630bebcc34f286e93 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -492,7 +492,7 @@ QAction *addCheckableAction(QMenu *menu, const QString &display, bool on, bool c
 class DummyEngine : public DebuggerEngine
 {
 public:
-    DummyEngine() : DebuggerEngine(DebuggerRunParameters()) {}
+    DummyEngine() {}
     ~DummyEngine() override {}
 
     void setupEngine() override {}
@@ -647,7 +647,7 @@ public:
     void extensionsInitialized();
     void aboutToShutdown();
 
-    void connectEngine(DebuggerEngine *engine);
+    void connectEngine(DebuggerRunTool *runTool);
     void disconnectEngine() { connectEngine(0); }
     DebuggerEngine *dummyEngine();
 
@@ -671,8 +671,11 @@ public:
 
     void selectThread(int index)
     {
-        ThreadId id = m_currentEngine->threadsHandler()->threadAt(index);
-        m_currentEngine->selectThread(id);
+        QTC_ASSERT(m_currentRunTool, return);
+        DebuggerEngine *engine = m_currentRunTool->activeEngine();
+        QTC_ASSERT(engine, return);
+        ThreadId id = engine->threadsHandler()->threadAt(index);
+        engine->selectThread(id);
     }
 
     void breakpointSetMarginActionTriggered(bool isMessageOnly, const ContextData &data)
@@ -715,14 +718,14 @@ public:
     {
         showMessage(QLatin1String("ATTEMPT SYNC"), LogDebug);
         for (int i = 0, n = m_snapshotHandler->size(); i != n; ++i) {
-            if (DebuggerEngine *engine = m_snapshotHandler->at(i))
+            if (DebuggerEngine *engine = m_snapshotHandler->at(i)->engine())
                 engine->attemptBreakpointSynchronization();
         }
     }
 
-    void reloadSourceFiles() { if (m_currentEngine) m_currentEngine->reloadSourceFiles(); }
-    void reloadRegisters() { if (m_currentEngine) m_currentEngine->reloadRegisters(); }
-    void reloadModules() { if (m_currentEngine) m_currentEngine->reloadModules(); }
+    void reloadSourceFiles() { if (m_currentRunTool) m_currentRunTool->engine()->reloadSourceFiles(); }
+    void reloadRegisters() { if (m_currentRunTool) m_currentRunTool->engine()->reloadRegisters(); }
+    void reloadModules() { if (m_currentRunTool) m_currentRunTool->engine()->reloadModules(); }
 
     void editorOpened(IEditor *editor);
     void updateBreakMenuItem(IEditor *editor);
@@ -752,11 +755,11 @@ public:
     void enableReverseDebuggingTriggered(const QVariant &value);
     void showStatusMessage(const QString &msg, int timeout = -1);
 
-    void runControlStarted(DebuggerEngine *engine);
-    void runControlFinished(DebuggerEngine *engine);
+    void runControlStarted(DebuggerRunTool *runTool);
+    void runControlFinished(DebuggerRunTool *runTool);
     void remoteCommand(const QStringList &options);
 
-    void displayDebugger(DebuggerEngine *engine, bool updateEngine = true);
+    void displayDebugger(DebuggerRunTool *runTool, bool updateEngine = true);
 
     void dumpLog();
     void cleanupViews();
@@ -764,7 +767,7 @@ public:
 
     void fontSettingsChanged(const FontSettings &settings);
 
-    void updateState(DebuggerEngine *engine);
+    void updateState(DebuggerRunTool *runTool);
     void onCurrentProjectChanged(Project *project);
 
     void sessionLoaded();
@@ -929,7 +932,9 @@ public:
 
     void handleExecExit()
     {
-        currentEngine()->exitDebugger();
+        QTC_ASSERT(dd->m_currentRunTool, return);
+        return dd->m_currentRunTool->runControl()->initiateStop();
+        //currentEngine()->exitDebugger();
     }
 
     void handleFrameDown()
@@ -1060,7 +1065,8 @@ public:
 
     SnapshotHandler *m_snapshotHandler = 0;
     bool m_shuttingDown = false;
-    QPointer<DebuggerEngine> m_currentEngine;
+    QPointer<DebuggerEngine> m_previouslyActiveEngine;
+    QPointer<DebuggerRunTool> m_currentRunTool;
     DebuggerSettings *m_debuggerSettings = 0;
     QStringList m_arguments;
     DebuggerToolTipManager m_toolTipManager;
@@ -1912,12 +1918,12 @@ void DebuggerPluginPrivate::onCurrentProjectChanged(Project *project)
     }
     for (int i = 0, n = m_snapshotHandler->size(); i != n; ++i) {
         // Run controls might be deleted during exit.
-        if (DebuggerEngine *engine = m_snapshotHandler->at(i)) {
-            if (RunControl *runControl = engine->runControl()) {
+        if (DebuggerRunTool *runTool = m_snapshotHandler->at(i)) {
+            if (RunControl *runControl = runTool->runControl()) {
                 RunConfiguration *rc = runControl->runConfiguration();
                 if (rc == activeRc) {
                     m_snapshotHandler->setCurrentIndex(i);
-                    updateState(engine);
+                    updateState(runTool);
                     return;
                 }
             }
@@ -2143,7 +2149,7 @@ void DebuggerPlugin::getEnginesState(QByteArray *json) const
     QVariantMap states;
 
     for (int i = 0; i < dd->m_snapshotHandler->size(); ++i) {
-        const DebuggerEngine *engine = dd->m_snapshotHandler->at(i);
+        const DebuggerEngine *engine = dd->m_snapshotHandler->at(i)->engine();
         states[QString::number(i)] = QVariantMap({
                    {"current", dd->m_snapshotHandler->currentIndex() == i},
                    {"pid", engine->inferiorPid()},
@@ -2401,30 +2407,35 @@ void DebuggerPluginPrivate::requestMark(TextEditorWidget *widget, int lineNumber
 }
 
 // If updateEngine is set, the engine will update its threads/modules and so forth.
-void DebuggerPluginPrivate::displayDebugger(DebuggerEngine *engine, bool updateEngine)
+void DebuggerPluginPrivate::displayDebugger(DebuggerRunTool *runTool, bool updateEngine)
 {
+    QTC_ASSERT(runTool, return);
+    DebuggerEngine *engine = runTool ? runTool->engine() : dummyEngine();
     QTC_ASSERT(engine, return);
+
     disconnectEngine();
-    connectEngine(engine);
+    connectEngine(runTool);
     if (updateEngine)
         engine->updateAll();
     engine->updateViews();
 }
 
-void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
+void DebuggerPluginPrivate::connectEngine(DebuggerRunTool *runTool)
 {
-    if (!engine)
-        engine = dummyEngine();
-
-    if (m_currentEngine == engine)
+    if (m_shuttingDown)
         return;
 
-    if (m_shuttingDown)
+    m_currentRunTool = runTool;
+    DebuggerEngine *engine = currentEngine();
+    QTC_ASSERT(engine, return);
+
+    if (m_previouslyActiveEngine == engine)
         return;
 
-    if (m_currentEngine)
-        m_currentEngine->resetLocation();
-    m_currentEngine = engine;
+    if (m_previouslyActiveEngine)
+        m_previouslyActiveEngine->resetLocation();
+
+    m_previouslyActiveEngine = engine;
 
     m_localsView->setModel(engine->watchModel());
     m_modulesView->setModel(engine->modulesModel());
@@ -2560,10 +2571,12 @@ void DebuggerPluginPrivate::setInitialState()
     m_threadLabel->setEnabled(false);
 }
 
-void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
+void DebuggerPluginPrivate::updateState(DebuggerRunTool *runTool)
 {
     if (m_shuttingDown)
         return;
+    QTC_ASSERT(runTool, return);
+    DebuggerEngine *engine = runTool->engine();
     QTC_ASSERT(engine, return);
     QTC_ASSERT(m_watchersView->model(), return);
     QTC_ASSERT(m_returnView->model(), return);
@@ -2657,7 +2670,7 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
     m_threadBox->setEnabled(state == InferiorStopOk || state == InferiorUnrunnable);
     m_threadLabel->setEnabled(m_threadBox->isEnabled());
 
-    const bool isCore = engine->runParameters().startMode == AttachCore;
+    const bool isCore = runTool->runParameters().startMode == AttachCore;
     const bool stopped = state == InferiorStopOk;
     const bool detachable = stopped && !isCore;
     m_detachAction->setEnabled(detachable);
@@ -2712,7 +2725,7 @@ void DebuggerPluginPrivate::updateDebugActions()
     if (m_shuttingDown)
         return;
     //if we're currently debugging the actions are controlled by engine
-    if (m_currentEngine && m_currentEngine->state() != DebuggerNotReady)
+    if (m_currentRunTool && m_currentRunTool->engine()->state() != DebuggerNotReady)
         return;
 
     QString whyNot;
@@ -2941,27 +2954,27 @@ static QString formatStartParameters(DebuggerRunParameters &sp)
     return rc;
 }
 
-void DebuggerPluginPrivate::runControlStarted(DebuggerEngine *engine)
+void DebuggerPluginPrivate::runControlStarted(DebuggerRunTool *runTool)
 {
     activateDebugMode();
     const QString message = tr("Starting debugger \"%1\" for ABI \"%2\"...")
-            .arg(engine->objectName())
-            .arg(engine->runParameters().toolChainAbi.toString());
+            .arg(runTool->objectName())
+            .arg(runTool->runParameters().toolChainAbi.toString());
     showStatusMessage(message);
-    showMessage(formatStartParameters(engine->runParameters()), LogDebug);
+    showMessage(formatStartParameters(runTool->runParameters()), LogDebug);
     showMessage(m_debuggerSettings->dump(), LogDebug);
-    m_snapshotHandler->appendSnapshot(engine);
-    connectEngine(engine);
+    m_snapshotHandler->appendSnapshot(runTool);
+    connectEngine(runTool);
 }
 
-void DebuggerPluginPrivate::runControlFinished(DebuggerEngine *engine)
+void DebuggerPluginPrivate::runControlFinished(DebuggerRunTool *runTool)
 {
-    if (engine)
-        engine->handleFinished();
+    if (runTool && runTool->engine())
+        runTool->engine()->handleFinished();
     if (m_shuttingDown)
         return;
     showStatusMessage(tr("Debugger finished."));
-    m_snapshotHandler->removeSnapshot(engine);
+    m_snapshotHandler->removeSnapshot(runTool);
     if (m_snapshotHandler->size() == 0) {
         // Last engine quits.
         disconnectEngine();
@@ -3031,7 +3044,9 @@ void DebuggerPluginPrivate::extensionsInitialized()
 
 DebuggerEngine *currentEngine()
 {
-    return dd->m_currentEngine;
+    QTC_ASSERT(dd->m_currentRunTool, return dd->dummyEngine());
+    DebuggerEngine *engine = dd->m_currentRunTool->activeEngine();
+    return engine ? engine : dd->dummyEngine();
 }
 
 SavedAction *action(int code)
@@ -3139,9 +3154,9 @@ void DebuggerPluginPrivate::aboutToShutdown()
     m_mode = 0;
 }
 
-void updateState(DebuggerEngine *engine)
+void updateState(DebuggerRunTool *runTool)
 {
-    dd->updateState(engine);
+    dd->updateState(runTool);
 }
 
 void updateWatchersWindow(bool showWatch, bool showReturn)
@@ -3179,19 +3194,19 @@ void showMessage(const QString &msg, int channel, int timeout)
     dd->showMessage(msg, channel, timeout);
 }
 
-void runControlStarted(DebuggerEngine *engine)
+void runControlStarted(DebuggerRunTool *runTool)
 {
-    dd->runControlStarted(engine);
+    dd->runControlStarted(runTool);
 }
 
-void runControlFinished(DebuggerEngine *engine)
+void runControlFinished(DebuggerRunTool *runTool)
 {
-    dd->runControlFinished(engine);
+    dd->runControlFinished(runTool);
 }
 
-void displayDebugger(DebuggerEngine *engine, bool updateEngine)
+void displayDebugger(DebuggerRunTool *runTool, bool updateEngine)
 {
-    dd->displayDebugger(engine, updateEngine);
+    dd->displayDebugger(runTool, updateEngine);
 }
 
 void synchronizeBreakpoints()
@@ -3354,8 +3369,8 @@ void DebuggerPluginPrivate::updateUiForTarget(Target *target)
 
 void DebuggerPluginPrivate::updateActiveLanguages()
 {
-    QTC_ASSERT(dd->m_currentEngine, return);
-    const DebuggerLanguages languages = dd->m_currentEngine->runParameters().languages;
+    QTC_ASSERT(dd->m_currentRunTool, return);
+    const DebuggerLanguages languages = dd->m_currentRunTool->runParameters().languages;
 //    Id perspective = (languages & QmlLanguage) && !(languages & CppLanguage)
 //            ? QmlPerspectiveId : CppPerspectiveId;
 //    m_mainWindow->restorePerspective(perspective);
@@ -3676,13 +3691,14 @@ void DebuggerUnitTests::testStateMachine()
     rp.testCase = TestNoBoundsOfCurrentFunction;
 
     auto runControl = new RunControl(rc, ProjectExplorer::Constants::DEBUG_RUN_MODE);
-    (void) new DebuggerRunTool(runControl, rp);
-    ProjectExplorerPlugin::startRunControl(runControl);
+    auto runTool = new DebuggerRunTool(runControl, rp);
 
-    connect(runControl, &RunControl::finished, this, [this] {
+    connect(runTool, &DebuggerRunTool::stopped, this, [this] {
         QTestEventLoop::instance().exitLoop();
     });
 
+    ProjectExplorerPlugin::startRunControl(runControl);
+
     QTestEventLoop::instance().enterLoop(5);
 }
 
diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp
index 2e5f42db98c68a7af3332fb357fafa4132fb3e14..be1e107842e9a8717c5413543c5e1359f3aada53 100644
--- a/src/plugins/debugger/debuggerruncontrol.cpp
+++ b/src/plugins/debugger/debuggerruncontrol.cpp
@@ -73,15 +73,15 @@ enum { debug = 0 };
 namespace Debugger {
 namespace Internal {
 
-DebuggerEngine *createCdbEngine(const DebuggerRunParameters &rp, QStringList *error);
 const auto DebugRunMode = ProjectExplorer::Constants::DEBUG_RUN_MODE;
 const auto DebugRunModeWithBreakOnMain = ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN;
 
-DebuggerEngine *createGdbEngine(const DebuggerRunParameters &rp);
-DebuggerEngine *createPdbEngine(const DebuggerRunParameters &rp);
-DebuggerEngine *createQmlEngine(const DebuggerRunParameters &rp);
-DebuggerEngine *createQmlCppEngine(const DebuggerRunParameters &rp, QStringList *error);
-DebuggerEngine *createLldbEngine(const DebuggerRunParameters &rp);
+DebuggerEngine *createCdbEngine(QStringList *error, DebuggerStartMode sm);
+DebuggerEngine *createGdbEngine(bool useTerminal, DebuggerStartMode sm);
+DebuggerEngine *createPdbEngine();
+DebuggerEngine *createQmlEngine(bool useTerminal);
+DebuggerEngine *createQmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal);
+DebuggerEngine *createLldbEngine();
 
 } // namespace Internal
 
@@ -154,6 +154,7 @@ void DebuggerRunTool::start()
     }
 
     appendMessage(tr("Debugging starts") + QLatin1Char('\n'), NormalMessageFormat);
+    Internal::runControlStarted(this);
     engine->start();
 }
 
@@ -175,7 +176,7 @@ void DebuggerRunTool::notifyEngineRemoteSetupFinished(const RemoteSetupResult &r
 
 void DebuggerRunTool::stop()
 {
-    m_engine->quitDebugger();
+    m_engine->exitDebugger();
 }
 
 void DebuggerRunTool::onTargetFailure()
@@ -190,12 +191,19 @@ void DebuggerRunTool::onTargetFailure()
 
 void DebuggerRunTool::debuggingFinished()
 {
+    Internal::runControlFinished(this);
+    appendMessage(tr("Debugging has finished"), NormalMessageFormat);
     reportStopped();
 }
 
-DebuggerStartParameters &DebuggerRunTool::startParameters()
+DebuggerRunParameters &DebuggerRunTool::runParameters()
+{
+    return m_runParameters;
+}
+
+const DebuggerRunParameters &DebuggerRunTool::runParameters() const
 {
-    return m_engine->runParameters();
+    return m_runParameters;
 }
 
 int DebuggerRunTool::portsUsedByDebugger() const
@@ -232,35 +240,46 @@ void DebuggerRunTool::abortDebugger()
 namespace Internal {
 
 // Re-used for Combined C++/QML engine.
-DebuggerEngine *createEngine(DebuggerEngineType et, const DebuggerRunParameters &rp, QStringList *errors)
+DebuggerEngine *createEngine(DebuggerEngineType cppEngineType,
+                             DebuggerEngineType et,
+                             DebuggerStartMode sm,
+                             bool useTerminal,
+                             QStringList *errors)
 {
     DebuggerEngine *engine = nullptr;
     switch (et) {
     case GdbEngineType:
-        engine = createGdbEngine(rp);
+        engine = createGdbEngine(useTerminal, sm);
         break;
     case CdbEngineType:
-        engine = createCdbEngine(rp, errors);
+        engine = createCdbEngine(errors, sm);
         break;
     case PdbEngineType:
-        engine = createPdbEngine(rp);
+        engine = createPdbEngine();
         break;
     case QmlEngineType:
-        engine = createQmlEngine(rp);
+        engine = createQmlEngine(useTerminal);
         break;
     case LldbEngineType:
-        engine = createLldbEngine(rp);
+        engine = createLldbEngine();
         break;
-    case QmlCppEngineType:
-        engine = createQmlCppEngine(rp, errors);
+    case QmlCppEngineType: {
+        DebuggerEngine *cppEngine = createEngine(cppEngineType, cppEngineType, sm, useTerminal, errors);
+        if (cppEngine) {
+            engine = createQmlCppEngine(cppEngine, useTerminal);
+        } else {
+            errors->append(DebuggerPlugin::tr("The slave debugging engine required for combined "
+                              "QML/C++-Debugging could not be created: %1"));
+        }
         break;
+    }
     default:
         errors->append(DebuggerPlugin::tr("Unknown debugger type \"%1\"")
                        .arg(engineTypeName(et)));
     }
     if (!engine)
         errors->append(DebuggerPlugin::tr("Unable to create a debugger engine of the type \"%1\"").
-                       arg(engineTypeName(rp.masterEngineType)));
+                       arg(engineTypeName(et)));
     return engine;
 }
 
@@ -518,11 +537,10 @@ void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString
         return;
     }
 
-    DebuggerRunParameters m_rp = rp;
+    m_runParameters = rp;
 
-    runControl()->setDisplayName(m_rp.displayName);
     // QML and/or mixed are not prepared for it.
-    runControl()->setSupportsReRunning(!(m_rp.languages & QmlLanguage));
+    runControl()->setSupportsReRunning(!(rp.languages & QmlLanguage));
 
     runControl()->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
     runControl()->setPromptToStop([](bool *optionalPrompt) {
@@ -535,25 +553,40 @@ void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString
                 QString(), QString(), optionalPrompt);
     });
 
-    if (Internal::fixupParameters(m_rp, runControl(), m_errors)) {
-        m_engine = createEngine(m_rp.masterEngineType, m_rp, &m_errors);
+    if (Internal::fixupParameters(m_runParameters, runControl(), m_errors)) {
+        m_engine = createEngine(m_runParameters.cppEngineType,
+                                m_runParameters.masterEngineType,
+                                m_runParameters.startMode,
+                                m_runParameters.useTerminal,
+                                &m_errors);
         if (!m_engine) {
             QString msg = m_errors.join('\n');
             if (errorMessage)
                 *errorMessage = msg;
             return;
         }
+
+        Utils::globalMacroExpander()->registerFileVariables(
+            "DebuggedExecutable", tr("Debugged executable"),
+            [this] { return m_runParameters.inferior.executable; }
+        );
     }
 
+    runControl()->setDisplayName(m_runParameters.displayName);
+
     m_engine->setRunTool(this);
 }
 
+DebuggerEngine *DebuggerRunTool::activeEngine() const
+{
+    return m_engine ? m_engine->activeEngine() : nullptr;
+}
+
 void DebuggerRunTool::appendSolibSearchPath(const QString &str)
 {
     QString path = str;
-    DebuggerStartParameters &sp = startParameters();
-    path.replace("%{sysroot}", sp.sysRoot);
-    sp.solibSearchPath.append(path);
+    path.replace("%{sysroot}", m_runParameters.sysRoot);
+    m_runParameters.solibSearchPath.append(path);
 }
 
 DebuggerRunTool::~DebuggerRunTool()
@@ -567,12 +600,6 @@ DebuggerRunTool::~DebuggerRunTool()
     }
 }
 
-void DebuggerRunTool::onFinished()
-{
-    appendMessage(tr("Debugging has finished"), NormalMessageFormat);
-    runControlFinished(m_engine);
-}
-
 void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout)
 {
     if (channel == ConsoleOutput)
@@ -783,7 +810,7 @@ void GdbServerRunner::start()
     m_gdbServer.start(r, device());
 }
 
-void GdbServerRunner::onFinished()
+void GdbServerRunner::stop()
 {
     m_gdbServer.stop();
 }
diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h
index 29c5a7e545e165892a6be5ca25d0b6145dc502bf..1817e9767c8a779622f942dce85b22566cce912c 100644
--- a/src/plugins/debugger/debuggerruncontrol.h
+++ b/src/plugins/debugger/debuggerruncontrol.h
@@ -58,12 +58,12 @@ public:
                           QString *errorMessage = nullptr); // FIXME: Don't use.
 
     Internal::DebuggerEngine *engine() const { return m_engine; }
+    Internal::DebuggerEngine *activeEngine() const;
 
     void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1);
 
     void start() override;
     void stop() override;
-    void onFinished() override;
 
     void startFailed();
     void onTargetFailure();
@@ -75,7 +75,8 @@ public:
     void abortDebugger();
     void debuggingFinished();
 
-    DebuggerStartParameters &startParameters(); // Used in Boot2Qt.
+    Internal::DebuggerRunParameters &runParameters();
+    const Internal::DebuggerRunParameters &runParameters() const;
 
     bool isCppDebugging() const { return m_isCppDebugging; }
     bool isQmlDebugging() const { return m_isQmlDebugging; }
@@ -91,6 +92,7 @@ signals:
 
 private:
     Internal::DebuggerEngine *m_engine = nullptr; // Master engine
+    Internal::DebuggerRunParameters m_runParameters;
     QStringList m_errors;
     const bool m_isCppDebugging;
     const bool m_isQmlDebugging;
@@ -132,7 +134,7 @@ public:
 
 private:
     void start() override;
-    void onFinished() override;
+    void stop() override;
 
     ProjectExplorer::ApplicationLauncher m_gdbServer;
 };
diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp
index 0f0f0b0374a821dbeea6ebbdb13f219d6efbcecc..11566a51be52774407797704e15f74b4e099d6f8 100644
--- a/src/plugins/debugger/gdb/attachgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp
@@ -35,8 +35,8 @@
 namespace Debugger {
 namespace Internal {
 
-GdbAttachEngine::GdbAttachEngine(const DebuggerRunParameters &startParameters)
-    : GdbEngine(startParameters)
+GdbAttachEngine::GdbAttachEngine(bool useTerminal)
+    : GdbEngine(useTerminal)
 {
 }
 
diff --git a/src/plugins/debugger/gdb/attachgdbadapter.h b/src/plugins/debugger/gdb/attachgdbadapter.h
index c90f1e2ab0d2bdc34f7df5769af12d3fb5b9cd21..cabf4688061091440c7692870657b155a56aab6c 100644
--- a/src/plugins/debugger/gdb/attachgdbadapter.h
+++ b/src/plugins/debugger/gdb/attachgdbadapter.h
@@ -41,7 +41,7 @@ class GdbAttachEngine : public GdbEngine
     Q_OBJECT
 
 public:
-    explicit GdbAttachEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbAttachEngine(bool useTerminal);
 
 private:
     void setupEngine() override;
diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp
index f21e3dbd67c899913aa8f6ce96ca4149c3849382..df6d040ccdd8d5dbe806026d72d6d8d5d08539d5 100644
--- a/src/plugins/debugger/gdb/coregdbadapter.cpp
+++ b/src/plugins/debugger/gdb/coregdbadapter.cpp
@@ -54,9 +54,8 @@ namespace Internal {
 //
 ///////////////////////////////////////////////////////////////////////
 
-GdbCoreEngine::GdbCoreEngine(const DebuggerRunParameters &startParameters)
-    : GdbEngine(startParameters),
-      m_coreUnpackProcess(0)
+GdbCoreEngine::GdbCoreEngine(bool useTerminal)
+    : GdbEngine(useTerminal)
 {}
 
 GdbCoreEngine::~GdbCoreEngine()
diff --git a/src/plugins/debugger/gdb/coregdbadapter.h b/src/plugins/debugger/gdb/coregdbadapter.h
index 0067200e5b089e791d38c0ccc27ce19610f96596..b4b708145503f249c419810e5aca9997f2395d7b 100644
--- a/src/plugins/debugger/gdb/coregdbadapter.h
+++ b/src/plugins/debugger/gdb/coregdbadapter.h
@@ -37,7 +37,7 @@ class GdbCoreEngine : public GdbEngine
     Q_OBJECT
 
 public:
-    explicit GdbCoreEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbCoreEngine(bool useTerminal);
     ~GdbCoreEngine() override;
 
     struct CoreInfo
@@ -70,7 +70,7 @@ private:
     QString m_executable;
     QString m_coreName;
     QString m_tempCoreName;
-    QProcess *m_coreUnpackProcess;
+    QProcess *m_coreUnpackProcess = nullptr;
     QFile m_tempCoreFile;
 };
 
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index f2497823419b1585b05a9e556a9912cde5763c51..3ff75994a457eee8b4472a95f17a7faa66ce481f 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -204,8 +204,7 @@ private:
 //
 ///////////////////////////////////////////////////////////////////////
 
-GdbEngine::GdbEngine(const DebuggerRunParameters &startParameters)
-  : DebuggerEngine(startParameters)
+GdbEngine::GdbEngine(bool useTerminal)
 {
     setObjectName("GdbEngine");
 
@@ -222,7 +221,7 @@ GdbEngine::GdbEngine(const DebuggerRunParameters &startParameters)
     m_pendingBreakpointRequests = 0;
     m_commandsDoneCallback = 0;
     m_stackNeeded = false;
-    m_terminalTrap = startParameters.useTerminal;
+    m_terminalTrap = useTerminal;
     m_systemDumpersLoaded = false;
     m_rerunPending = false;
     m_inUpdateLocals = false;
@@ -4355,20 +4354,20 @@ void GdbEngine::debugLastCommand()
 // Factory
 //
 
-DebuggerEngine *createGdbEngine(const DebuggerRunParameters &rp)
+DebuggerEngine *createGdbEngine(bool useTerminal, DebuggerStartMode sm)
 {
-    switch (rp.startMode) {
+    switch (sm) {
     case AttachCore:
-        return new GdbCoreEngine(rp);
+        return new GdbCoreEngine(useTerminal);
     case StartRemoteProcess:
     case AttachToRemoteServer:
-        return new GdbRemoteServerEngine(rp);
+        return new GdbRemoteServerEngine(useTerminal);
     case AttachExternal:
-        return new GdbAttachEngine(rp);
+        return new GdbAttachEngine(useTerminal);
     default:
-        if (rp.useTerminal)
-            return new GdbTermEngine(rp);
-        return new GdbPlainEngine(rp);
+        if (useTerminal)
+            return new GdbTermEngine(useTerminal);
+        return new GdbPlainEngine(useTerminal);
     }
 }
 
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index 45b99ec398d5033e0c9bbae32b7a91e7c3943df3..73f930f4f21784dbd5ec908408deba8b19624bf7 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -66,7 +66,7 @@ class GdbEngine : public DebuggerEngine
     Q_OBJECT
 
 public:
-    explicit GdbEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbEngine(bool useTerminal);
     ~GdbEngine() override;
 
 private: ////////// General Interface //////////
diff --git a/src/plugins/debugger/gdb/gdbplainengine.cpp b/src/plugins/debugger/gdb/gdbplainengine.cpp
index 09accd0bb6150eac67a15a084e985b38a676acec..d957336891ad243d062ff08250fb2a1be398d8ee 100644
--- a/src/plugins/debugger/gdb/gdbplainengine.cpp
+++ b/src/plugins/debugger/gdb/gdbplainengine.cpp
@@ -40,8 +40,8 @@ namespace Internal {
 
 #define CB(callback) [this](const DebuggerResponse &r) { callback(r); }
 
-GdbPlainEngine::GdbPlainEngine(const DebuggerRunParameters &startParameters)
-    : GdbEngine(startParameters)
+GdbPlainEngine::GdbPlainEngine(bool useTerminal)
+    : GdbEngine(useTerminal)
 {
     // Output
     connect(&m_outputCollector, &OutputCollector::byteDelivery,
diff --git a/src/plugins/debugger/gdb/gdbplainengine.h b/src/plugins/debugger/gdb/gdbplainengine.h
index 445f80ca02f87d64e379c54da2119aba17844158..a2f6e04a6b6c1f7765e1b6b897d6243459c1fbd7 100644
--- a/src/plugins/debugger/gdb/gdbplainengine.h
+++ b/src/plugins/debugger/gdb/gdbplainengine.h
@@ -37,7 +37,7 @@ class GdbPlainEngine : public GdbEngine
     Q_OBJECT
 
 public:
-    explicit GdbPlainEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbPlainEngine(bool useTerminal);
 
 private:
     void handleExecRun(const DebuggerResponse &response);
diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
index 4b18434308c943ea82d120c461a237b0fe6c00ee..4f508601344b00d98d3dd00374fc39c4a55f626e 100644
--- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
+++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
@@ -54,12 +54,9 @@ namespace Internal {
 //
 ///////////////////////////////////////////////////////////////////////
 
-GdbRemoteServerEngine::GdbRemoteServerEngine(const DebuggerRunParameters &runParameters)
-    : GdbEngine(runParameters), m_startAttempted(false)
+GdbRemoteServerEngine::GdbRemoteServerEngine(bool useTerminal)
+    : GdbEngine(useTerminal)
 {
-    if (HostOsInfo::isWindowsHost())
-        m_gdbProc.setUseCtrlCStub(runParameters.useCtrlCStub); // This is only set for QNX
-
     connect(&m_uploadProc, &QProcess::errorOccurred, this, &GdbRemoteServerEngine::uploadProcError);
     connect(&m_uploadProc, &QProcess::readyReadStandardOutput,
             this, &GdbRemoteServerEngine::readUploadStandardOutput);
@@ -71,6 +68,9 @@ GdbRemoteServerEngine::GdbRemoteServerEngine(const DebuggerRunParameters &runPar
 
 void GdbRemoteServerEngine::setupEngine()
 {
+    if (HostOsInfo::isWindowsHost())
+        m_gdbProc.setUseCtrlCStub(runParameters().useCtrlCStub); // This is only set for QNX
+
     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
     showMessage("TRYING TO START ADAPTER");
     QString serverStartScript = runParameters().serverStartScript;
@@ -170,8 +170,7 @@ void GdbRemoteServerEngine::setupInferior()
 
     //const QByteArray sysroot = sp.sysroot.toLocal8Bit();
     //const QByteArray remoteArch = sp.remoteArchitecture.toLatin1();
-    const QString args = isMasterEngine() ? runParameters().inferior.commandLineArguments
-                          : masterEngine()->runParameters().inferior.commandLineArguments;
+    const QString args = runParameters().inferior.commandLineArguments;
 
 //    if (!remoteArch.isEmpty())
 //        postCommand("set architecture " + remoteArch);
diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.h b/src/plugins/debugger/gdb/remotegdbserveradapter.h
index 039028e17c487bd55dea3ff2c2dcf51c771c85dc..6887a44988098a7dccb2d9a1a482ac813a941e58 100644
--- a/src/plugins/debugger/gdb/remotegdbserveradapter.h
+++ b/src/plugins/debugger/gdb/remotegdbserveradapter.h
@@ -35,7 +35,7 @@ class GdbRemoteServerEngine : public GdbEngine
     Q_OBJECT
 
 public:
-    explicit GdbRemoteServerEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbRemoteServerEngine(bool useTerminal);
 
 private:
     void setupEngine() override;
@@ -65,7 +65,7 @@ private:
     void handleExecRun(const DebuggerResponse &response);
 
     QProcess m_uploadProc;
-    bool m_startAttempted;
+    bool m_startAttempted = false;
 };
 
 } // namespace Internal
diff --git a/src/plugins/debugger/gdb/termgdbadapter.cpp b/src/plugins/debugger/gdb/termgdbadapter.cpp
index e1ace5fca83297196d71a12fe887deb755778695..60a66cb9f7a3ccd6dd2bf708dafc85912b3fbfee 100644
--- a/src/plugins/debugger/gdb/termgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/termgdbadapter.cpp
@@ -46,8 +46,8 @@ namespace Internal {
 //
 ///////////////////////////////////////////////////////////////////////
 
-GdbTermEngine::GdbTermEngine(const DebuggerRunParameters &startParameters)
-    : GdbEngine(startParameters)
+GdbTermEngine::GdbTermEngine(bool useTerminal)
+    : GdbEngine(useTerminal)
 {
     if (HostOsInfo::isWindowsHost()) {
         // Windows up to xp needs a workaround for attaching to freshly started processes. see proc_stub_win
diff --git a/src/plugins/debugger/gdb/termgdbadapter.h b/src/plugins/debugger/gdb/termgdbadapter.h
index eede958b23b122c282dbd27b62b77756a073ac35..73a2413637b868b4da993ea91213ceb675d595a4 100644
--- a/src/plugins/debugger/gdb/termgdbadapter.h
+++ b/src/plugins/debugger/gdb/termgdbadapter.h
@@ -43,7 +43,7 @@ class GdbTermEngine : public GdbEngine
     Q_OBJECT
 
 public:
-    explicit GdbTermEngine(const DebuggerRunParameters &runParameters);
+    explicit GdbTermEngine(bool useTerminal);
     ~GdbTermEngine() override;
 
 private:
diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp
index 9a7c57753dd952b046bcc33a77aa140e568565b0..65a716332dc0cbaa5e6e3ca8d42c9bb91b788c11 100644
--- a/src/plugins/debugger/lldb/lldbengine.cpp
+++ b/src/plugins/debugger/lldb/lldbengine.cpp
@@ -81,11 +81,9 @@ static int &currentToken()
 //
 ///////////////////////////////////////////////////////////////////////
 
-LldbEngine::LldbEngine(const DebuggerRunParameters &startParameters)
-    : DebuggerEngine(startParameters), m_continueAtNextSpontaneousStop(false)
+LldbEngine::LldbEngine()
 {
-    m_lastAgentId = 0;
-    setObjectName(QLatin1String("LldbEngine"));
+    setObjectName("LldbEngine");
 
     connect(action(AutoDerefPointers), &SavedAction::valueChanged,
             this, &LldbEngine::updateLocals);
@@ -1116,9 +1114,9 @@ bool LldbEngine::hasCapability(unsigned cap) const
     return false;
 }
 
-DebuggerEngine *createLldbEngine(const DebuggerRunParameters &startParameters)
+DebuggerEngine *createLldbEngine()
 {
-    return new LldbEngine(startParameters);
+    return new LldbEngine;
 }
 
 void LldbEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
diff --git a/src/plugins/debugger/lldb/lldbengine.h b/src/plugins/debugger/lldb/lldbengine.h
index 2b5d7b0b619eae79cf0950c497811d8ca17b451c..4c9b5fc97806c032ba60152f27f2bfe87ae9c5b1 100644
--- a/src/plugins/debugger/lldb/lldbengine.h
+++ b/src/plugins/debugger/lldb/lldbengine.h
@@ -58,7 +58,7 @@ class LldbEngine : public DebuggerEngine
     Q_OBJECT
 
 public:
-    explicit LldbEngine(const DebuggerRunParameters &runParameters);
+    LldbEngine();
     ~LldbEngine() override;
 
 signals:
@@ -152,8 +152,8 @@ private:
     Utils::QtcProcess m_lldbProc;
 
     // FIXME: Make generic.
-    int m_lastAgentId;
-    int m_continueAtNextSpontaneousStop;
+    int m_lastAgentId = 0;
+    int m_continueAtNextSpontaneousStop = false;
     QMap<QPointer<DisassemblerAgent>, int> m_disassemblerAgents;
 
     QHash<int, DebuggerCommand> m_commandForToken;
diff --git a/src/plugins/debugger/pdb/pdbengine.cpp b/src/plugins/debugger/pdb/pdbengine.cpp
index f74345fd04cc2f1003bf563c5612f638b8ee35a5..6334f18a3a4647ba375e3d716d25a16bc96b7b06 100644
--- a/src/plugins/debugger/pdb/pdbengine.cpp
+++ b/src/plugins/debugger/pdb/pdbengine.cpp
@@ -63,10 +63,9 @@ using namespace Core;
 namespace Debugger {
 namespace Internal {
 
-PdbEngine::PdbEngine(const DebuggerRunParameters &startParameters)
-    : DebuggerEngine(startParameters)
+PdbEngine::PdbEngine()
 {
-    setObjectName(QLatin1String("PdbEngine"));
+    setObjectName("PdbEngine");
 }
 
 void PdbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
@@ -579,9 +578,9 @@ bool PdbEngine::hasCapability(unsigned cap) const
               | ShowModuleSymbolsCapability);
 }
 
-DebuggerEngine *createPdbEngine(const DebuggerRunParameters &startParameters)
+DebuggerEngine *createPdbEngine()
 {
-    return new PdbEngine(startParameters);
+    return new PdbEngine;
 }
 
 } // namespace Internal
diff --git a/src/plugins/debugger/pdb/pdbengine.h b/src/plugins/debugger/pdb/pdbengine.h
index a0a944c5d401bf73424e4198684643651147d0ca..2927137eaaef7ae5865c703049d650cbfa0383fb 100644
--- a/src/plugins/debugger/pdb/pdbengine.h
+++ b/src/plugins/debugger/pdb/pdbengine.h
@@ -44,7 +44,7 @@ class PdbEngine : public DebuggerEngine
     Q_OBJECT
 
 public:
-    explicit PdbEngine(const DebuggerRunParameters &runParameters);
+    PdbEngine();
 
 private:
     // DebuggerEngine implementation
diff --git a/src/plugins/debugger/qml/qmlcppengine.cpp b/src/plugins/debugger/qml/qmlcppengine.cpp
index 95241ee9b592239ee6f29bc1d3c94e028ae70ed0..11d04e219bb32b5f4ab97a4703fda87070098e12 100644
--- a/src/plugins/debugger/qml/qmlcppengine.cpp
+++ b/src/plugins/debugger/qml/qmlcppengine.cpp
@@ -26,6 +26,7 @@
 #include "qmlcppengine.h"
 #include "qmlengine.h"
 
+#include <debugger/debuggercore.h>
 #include <debugger/debuggerruncontrol.h>
 #include <debugger/debuggertooltipmanager.h>
 #include <debugger/debuggerstartparameters.h>
@@ -48,13 +49,9 @@ enum { debug = 0 };
 
 #define CHECK_STATE(s) do { checkState(s, __FILE__, __LINE__); } while (0)
 
-DebuggerEngine *createQmlCppEngine(const DebuggerRunParameters &sp, QStringList *errors)
+DebuggerEngine *createQmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal)
 {
-    QmlCppEngine *newEngine = new QmlCppEngine(sp, errors);
-    if (newEngine->cppEngine())
-        return newEngine;
-    delete newEngine;
-    return 0;
+    return new QmlCppEngine(cppEngine, useTerminal);
 }
 
 
@@ -64,19 +61,12 @@ DebuggerEngine *createQmlCppEngine(const DebuggerRunParameters &sp, QStringList
 //
 ////////////////////////////////////////////////////////////////////////
 
-QmlCppEngine::QmlCppEngine(const DebuggerRunParameters &rp, QStringList *errors)
-    : DebuggerEngine(rp)
-{
-    setObjectName(QLatin1String("QmlCppEngine"));
-    m_qmlEngine = new QmlEngine(rp, this);
-    QStringList innerErrors;
-    m_cppEngine = createEngine(rp.cppEngineType, rp, &innerErrors);
-    if (!m_cppEngine) {
-        errors->append(tr("The slave debugging engine required for combined "
-                          "QML/C++-Debugging could not be created: %1")
-                       .arg(innerErrors.join(QLatin1Char('\n'))));
-        return;
-    }
+QmlCppEngine::QmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal)
+{
+    setObjectName("QmlCppEngine");
+    m_qmlEngine = new QmlEngine(useTerminal);
+    m_qmlEngine->setMasterEngine(this);
+    m_cppEngine = cppEngine;
     m_cppEngine->setMasterEngine(this);
     setActiveEngine(m_cppEngine);
 }
@@ -770,6 +760,13 @@ DebuggerEngine *QmlCppEngine::qmlEngine() const
     return m_qmlEngine;
 }
 
+void QmlCppEngine::setRunTool(DebuggerRunTool *runTool)
+{
+    DebuggerEngine::setRunTool(runTool);
+    m_qmlEngine->setRunTool(runTool);
+    m_cppEngine->setRunTool(runTool);
+}
+
 void QmlCppEngine::setActiveEngine(DebuggerEngine *engine)
 {
     m_activeEngine = engine;
diff --git a/src/plugins/debugger/qml/qmlcppengine.h b/src/plugins/debugger/qml/qmlcppengine.h
index 9847af3e5af6380c3d328b6e562bde8f5470c732..9f670a32a02e96fb7de29310a1350c7f8dcb88c2 100644
--- a/src/plugins/debugger/qml/qmlcppengine.h
+++ b/src/plugins/debugger/qml/qmlcppengine.h
@@ -37,7 +37,7 @@ class QmlCppEngine : public DebuggerEngine
     Q_OBJECT
 
 public:
-    QmlCppEngine(const DebuggerRunParameters &sp, QStringList *errors);
+    QmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal);
     ~QmlCppEngine() override;
 
     bool canDisplayTooltip() const override;
@@ -80,6 +80,8 @@ public:
 
     DebuggerEngine *cppEngine() override { return m_cppEngine; }
     DebuggerEngine *qmlEngine() const;
+    DebuggerEngine *activeEngine() override { return m_activeEngine; }
+    void setRunTool(DebuggerRunTool *runTool) override;
 
     void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result) override;
     void resetLocation() override;
diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index e86973962febcd9d4964c0da6ff4d7f2f0c049e0..1b72f5afe4bcbd9fe8ee970d0b0b11f5d3ae3a8b 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -257,15 +257,11 @@ static void updateDocument(IDocument *document, const QTextDocument *textDocumen
 //
 ///////////////////////////////////////////////////////////////////////
 
-QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngine *masterEngine)
-  : DebuggerEngine(startParameters),
-    d(new QmlEnginePrivate(this, new QmlDebugConnection(this)))
+QmlEngine::QmlEngine(bool useTerminal)
+  :  d(new QmlEnginePrivate(this, new QmlDebugConnection(this)))
 {
     setObjectName("QmlEngine");
 
-    if (masterEngine)
-        setMasterEngine(masterEngine);
-
     connect(stackHandler(), &StackHandler::stackChanged,
             this, &QmlEngine::updateCurrentContext);
     connect(stackHandler(), &StackHandler::currentIndexChanged,
@@ -276,7 +272,7 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
     connect(&d->applicationLauncher, &ApplicationLauncher::processExited,
             this, &QmlEngine::disconnected);
     connect(&d->applicationLauncher, &ApplicationLauncher::appendMessage,
-            this, &QmlEngine::appendMessage);
+            this, &QmlEngine::appMessage);
     connect(&d->applicationLauncher, &ApplicationLauncher::processStarted,
             this, &QmlEngine::handleLauncherStarted);
 
@@ -296,7 +292,7 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
             this, [this] { tryToConnect(); });
 
     // we won't get any debug output
-    if (startParameters.useTerminal) {
+    if (useTerminal) {
         d->noDebugOutputTimer.setInterval(0);
         d->retryOnConnectFail = true;
         d->automaticConnect = true;
@@ -380,7 +376,7 @@ void QmlEngine::handleLauncherStarted()
     d->noDebugOutputTimer.start();
 }
 
-void QmlEngine::appendMessage(const QString &msg, Utils::OutputFormat /* format */)
+void QmlEngine::appMessage(const QString &msg, Utils::OutputFormat /* format */)
 {
     showMessage(msg, AppOutput); // FIXME: Redirect to RunControl
 }
@@ -576,10 +572,10 @@ void QmlEngine::startApplicationLauncher()
 {
     if (!d->applicationLauncher.isRunning()) {
         StandardRunnable runnable = runParameters().inferior;
-        appendMessage(tr("Starting %1 %2").arg(
-                          QDir::toNativeSeparators(runnable.executable),
-                          runnable.commandLineArguments) + '\n',
-                      Utils::NormalMessageFormat);
+        runTool()->appendMessage(tr("Starting %1 %2").arg(
+                                     QDir::toNativeSeparators(runnable.executable),
+                                     runnable.commandLineArguments),
+                                 Utils::NormalMessageFormat);
         d->applicationLauncher.start(runnable);
     }
 }
@@ -2579,9 +2575,9 @@ void QmlEnginePrivate::flushSendBuffer()
     sendBuffer.clear();
 }
 
-DebuggerEngine *createQmlEngine(const DebuggerRunParameters &sp)
+DebuggerEngine *createQmlEngine(bool useTerminal)
 {
-    return new QmlEngine(sp);
+    return new QmlEngine(useTerminal);
 }
 
 } // Internal
diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h
index 728383e78c3173daf64622015118961ddb050ce2..2154f8dcc12d567a924318882eddb8abf2e69d83 100644
--- a/src/plugins/debugger/qml/qmlengine.h
+++ b/src/plugins/debugger/qml/qmlengine.h
@@ -43,8 +43,7 @@ class QmlEngine : public DebuggerEngine
     Q_OBJECT
 
 public:
-    explicit QmlEngine(const DebuggerRunParameters &runParameters,
-                       DebuggerEngine *masterEngine = nullptr);
+    explicit QmlEngine(bool useTerminal);
     ~QmlEngine() override;
 
     void setRunTool(DebuggerRunTool *runTool) override;
@@ -66,7 +65,7 @@ private:
     void connectionEstablished();
     void connectionStartupFailed();
     void appStartupFailed(const QString &errorMessage);
-    void appendMessage(const QString &msg, Utils::OutputFormat);
+    void appMessage(const QString &msg, Utils::OutputFormat);
 
     void notifyEngineRemoteServerRunning(const QString &, int pid) override;
     void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result) override;
diff --git a/src/plugins/debugger/snapshothandler.cpp b/src/plugins/debugger/snapshothandler.cpp
index d5b161582b9d5d2d6e5b0a951c704908efc079a4..61e5d4e181f84d914619ad9db6a7558ec92be00e 100644
--- a/src/plugins/debugger/snapshothandler.cpp
+++ b/src/plugins/debugger/snapshothandler.cpp
@@ -28,12 +28,10 @@
 #include "debuggerinternalconstants.h"
 #include "debuggericons.h"
 #include "debuggercore.h"
-#include "debuggerengine.h"
-#include "debuggerstartparameters.h"
+#include "debuggerruncontrol.h"
 
 #include <utils/qtcassert.h>
 
-#include <QIcon>
 #include <QDebug>
 #include <QFile>
 
@@ -126,8 +124,8 @@ SnapshotHandler::SnapshotHandler()
 SnapshotHandler::~SnapshotHandler()
 {
     for (int i = m_snapshots.size(); --i >= 0; ) {
-        if (DebuggerEngine *engine = at(i)) {
-            const DebuggerRunParameters &rp = engine->runParameters();
+        if (DebuggerRunTool *runTool = at(i)) {
+            const DebuggerRunParameters &rp = runTool->runParameters();
             if (rp.isSnapshot && !rp.coreFile.isEmpty())
                 QFile::remove(rp.coreFile);
         }
@@ -150,15 +148,15 @@ QVariant SnapshotHandler::data(const QModelIndex &index, int role) const
     if (!index.isValid() || index.row() >= m_snapshots.size())
         return QVariant();
 
-    const DebuggerEngine *engine = at(index.row());
+    const DebuggerRunTool *runTool = at(index.row());
 
     if (role == SnapshotCapabilityRole)
-        return engine && engine->hasCapability(SnapshotCapability);
+        return runTool && runTool->activeEngine()->hasCapability(SnapshotCapability);
 
-    if (!engine)
+    if (!runTool)
         return QLatin1String("<finished>");
 
-    const DebuggerRunParameters &rp = engine->runParameters();
+    const DebuggerRunParameters &rp = runTool->runParameters();
 
     switch (role) {
     case Qt::DisplayRole:
@@ -215,22 +213,22 @@ void SnapshotHandler::activateSnapshot(int index)
 
 void SnapshotHandler::createSnapshot(int index)
 {
-    DebuggerEngine *engine = at(index);
-    QTC_ASSERT(engine, return);
-    engine->createSnapshot();
+    DebuggerRunTool *runTool = at(index);
+    QTC_ASSERT(runTool, return);
+    runTool->engine()->createSnapshot();
 }
 
 void SnapshotHandler::removeSnapshot(int index)
 {
-    DebuggerEngine *engine = at(index);
-    //qDebug() << "REMOVING " << engine;
-    QTC_ASSERT(engine, return);
+    DebuggerRunTool *runTool = at(index);
+    //qDebug() << "REMOVING " << runTool;
+    QTC_ASSERT(runTool, return);
 #if 0
     // See http://sourceware.org/bugzilla/show_bug.cgi?id=11241.
     setState(EngineSetupRequested);
     postCommand("set stack-cache off");
 #endif
-    //QString fileName = engine->startParameters().coreFile;
+    //QString fileName = runTool->startParameters().coreFile;
     //if (!fileName.isEmpty())
     //    QFile::remove(fileName);
     beginResetModel();
@@ -239,7 +237,7 @@ void SnapshotHandler::removeSnapshot(int index)
         m_currentIndex = -1;
     else if (index < m_currentIndex)
         --m_currentIndex;
-    //engine->quitDebugger();
+    //runTool->quitDebugger();
     endResetModel();
 }
 
@@ -252,18 +250,18 @@ void SnapshotHandler::removeAll()
     endResetModel();
 }
 
-void SnapshotHandler::appendSnapshot(DebuggerEngine *engine)
+void SnapshotHandler::appendSnapshot(DebuggerRunTool *runTool)
 {
     beginResetModel();
-    m_snapshots.append(engine);
+    m_snapshots.append(runTool);
     m_currentIndex = size() - 1;
     endResetModel();
 }
 
-void SnapshotHandler::removeSnapshot(DebuggerEngine *engine)
+void SnapshotHandler::removeSnapshot(DebuggerRunTool *runTool)
 {
     // Could be that the run controls died before it was appended.
-    int index = m_snapshots.indexOf(engine);
+    int index = m_snapshots.indexOf(runTool);
     if (index != -1)
         removeSnapshot(index);
 }
@@ -275,7 +273,7 @@ void SnapshotHandler::setCurrentIndex(int index)
     endResetModel();
 }
 
-DebuggerEngine *SnapshotHandler::at(int i) const
+DebuggerRunTool *SnapshotHandler::at(int i) const
 {
     return m_snapshots.at(i).data();
 }
diff --git a/src/plugins/debugger/snapshothandler.h b/src/plugins/debugger/snapshothandler.h
index acecb0531d69e8e367e6a20d8e311ef996cd05ab..5f43668d1921807ad1682c175342b530be817f13 100644
--- a/src/plugins/debugger/snapshothandler.h
+++ b/src/plugins/debugger/snapshothandler.h
@@ -29,9 +29,10 @@
 #include <QPointer>
 
 namespace Debugger {
-namespace Internal {
 
-class DebuggerEngine;
+class DebuggerRunTool;
+
+namespace Internal {
 
 class SnapshotHandler : public QAbstractTableModel
 {
@@ -45,11 +46,11 @@ public:
     void removeAll();
     QAbstractItemModel *model() { return this; }
     int currentIndex() const { return m_currentIndex; }
-    void appendSnapshot(DebuggerEngine *engine);
-    void removeSnapshot(DebuggerEngine *engine);
+    void appendSnapshot(DebuggerRunTool *runTool);
+    void removeSnapshot(DebuggerRunTool *runTool);
     void setCurrentIndex(int index);
     int size() const { return m_snapshots.size(); }
-    DebuggerEngine *at(int index) const;
+    DebuggerRunTool *at(int index) const;
 
     void createSnapshot(int index);
     void activateSnapshot(int index);
@@ -64,7 +65,7 @@ private:
     Qt::ItemFlags flags(const QModelIndex &index) const;
 
     int m_currentIndex;
-    QList< QPointer<DebuggerEngine> > m_snapshots;
+    QList< QPointer<DebuggerRunTool> > m_snapshots;
 };
 
 } // namespace Internal
diff --git a/src/plugins/debugger/snapshotwindow.cpp b/src/plugins/debugger/snapshotwindow.cpp
index 242704e880764c7abd758f70e7bcafc74d3114db..777d152e47e93a3ff8d7c67bc456295238f79902 100644
--- a/src/plugins/debugger/snapshotwindow.cpp
+++ b/src/plugins/debugger/snapshotwindow.cpp
@@ -29,7 +29,7 @@
 #include "debuggeractions.h"
 #include "debuggerinternalconstants.h"
 #include "debuggercore.h"
-#include "debuggerengine.h"
+#include "debuggerruncontrol.h"
 
 #include <utils/qtcassert.h>
 #include <utils/savedaction.h>