diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h index 9488b93a1b7..99cd156d5ab 100644 --- a/src/plugins/debugger/debuggerengine.h +++ b/src/plugins/debugger/debuggerengine.h @@ -462,8 +462,6 @@ private: QPointer m_engine; }; -ProjectExplorer::RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, ProjectExplorer::Kit *kit); - } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 926fb705b33..1bd2209cb3b 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1940,8 +1940,12 @@ void DebuggerPluginPrivate::startAndDebugApplication() { DebuggerRunParameters rp; Kit *kit; - if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) - createAndScheduleRun(rp, kit); + if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) { + auto debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); + } } void DebuggerPluginPrivate::attachCore() @@ -1976,7 +1980,11 @@ void DebuggerPluginPrivate::attachCore() rp.startMode = AttachCore; rp.closeMode = DetachAtClose; rp.overrideStartScript = dlg.overrideStartScript(); - createAndScheduleRun(rp, dlg.kit()); + + auto debugger = DebuggerRunTool::createFromKit(dlg.kit()); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); } void DebuggerPluginPrivate::startRemoteCdbSession() @@ -1996,7 +2004,11 @@ void DebuggerPluginPrivate::startRemoteCdbSession() return; rp.remoteChannel = dlg.connection(); setConfigValue(connectionKey, rp.remoteChannel); - createAndScheduleRun(rp, kit); + + auto debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); } void DebuggerPluginPrivate::attachToRemoteServer() @@ -2007,7 +2019,10 @@ void DebuggerPluginPrivate::attachToRemoteServer() rp.useContinueInsteadOfRun = true; if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) { rp.closeMode = KillAtClose; - createAndScheduleRun(rp, kit); + auto debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); } } @@ -2112,7 +2127,13 @@ RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit, rp.startMode = AttachExternal; rp.closeMode = DetachAtClose; rp.continueAfterAttach = contAfterAttach; - return createAndScheduleRun(rp, kit); + + auto debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return nullptr); + debugger->setRunParameters(rp); + debugger->startRunControl(); + + return debugger->runControl(); } void DebuggerPlugin::attachExternalApplication(RunControl *rc) @@ -2124,13 +2145,16 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc) rp.closeMode = DetachAtClose; rp.toolChainAbi = rc->abi(); rp.languages = CppLanguage; + DebuggerRunTool *debugger; if (RunConfiguration *runConfig = rc->runConfiguration()) { - auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); - (void) new DebuggerRunTool(runControl, rp); - ProjectExplorerPlugin::startRunControl(runControl); + debugger = DebuggerRunTool::createFromRunConfiguration(runConfig); } else { - createAndScheduleRun(rp, guessKitFromParameters(rp)); + Kit *kit = guessKitFromParameters(rp); + debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return); } + debugger->setRunParameters(rp); + debugger->startRunControl(); } void DebuggerPlugin::getEnginesState(QByteArray *json) const @@ -2210,7 +2234,11 @@ void DebuggerPluginPrivate::attachToQmlPort() rp.projectSourceDirectory = !projects.isEmpty() ? projects.first()->projectDirectory().toString() : QString(); rp.projectSourceFiles = sourceFiles; - createAndScheduleRun(rp, kit); + + auto debugger = DebuggerRunTool::createFromKit(kit); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); } void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &value) @@ -2223,8 +2251,12 @@ void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &valu void DebuggerPluginPrivate::runScheduled() { - for (const QPair pair : m_scheduledStarts) - createAndScheduleRun(pair.first, pair.second); + for (const QPair pair : m_scheduledStarts) { + auto debugger = DebuggerRunTool::createFromKit(pair.second); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(pair.first); + debugger->startRunControl(); + } } void DebuggerPluginPrivate::editorOpened(IEditor *editor) diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index b60f8b296fc..c525118fb89 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -831,6 +831,45 @@ DebuggerEngine *DebuggerRunTool::activeEngine() const return m_engine ? m_engine->activeEngine() : nullptr; } +class DummyProject : public Project +{ +public: + DummyProject() : Project(QString(""), FileName::fromString("")) {} +}; + +RunConfiguration *dummyRunConfigForKit(ProjectExplorer::Kit *kit) +{ + QTC_ASSERT(kit, return nullptr); // Caller needs to look for a suitable kit. + Project *project = SessionManager::startupProject(); + Target *target = project ? project->target(kit) : nullptr; + if (!target || !target->activeRunConfiguration()) { + project = new DummyProject; // FIXME: Leaks. + target = project->createTarget(kit); + } + QTC_ASSERT(target, return nullptr); + auto runConfig = target->activeRunConfiguration(); + return runConfig; +} + +DebuggerRunTool *DebuggerRunTool::createFromKit(Kit *kit) +{ + RunConfiguration *runConfig = dummyRunConfigForKit(kit); + return createFromRunConfiguration(runConfig); +} + +void DebuggerRunTool::startRunControl() +{ + ProjectExplorerPlugin::startRunControl(runControl()); +} + +DebuggerRunTool *DebuggerRunTool::createFromRunConfiguration(RunConfiguration *runConfig) +{ + QTC_ASSERT(runConfig, return nullptr); + auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); + auto debugger = new DebuggerRunTool(runControl); + return debugger; +} + void DebuggerRunTool::addSolibSearchDir(const QString &str) { QString path = str; @@ -876,44 +915,6 @@ void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout) // //////////////////////////////////////////////////////////////////////// -namespace Internal { - -/** - * Used for direct "special" starts from actions in the debugger plugin. - */ - -class DummyProject : public Project -{ -public: - DummyProject() : Project(QString(""), FileName::fromString("")) {} -}; - -RunConfiguration *dummyRunConfigForKit(ProjectExplorer::Kit *kit) -{ - QTC_ASSERT(kit, return nullptr); // Caller needs to look for a suitable kit. - Project *project = SessionManager::startupProject(); - Target *target = project ? project->target(kit) : nullptr; - if (!target || !target->activeRunConfiguration()) { - project = new DummyProject; - target = project->createTarget(kit); - } - QTC_ASSERT(target, return nullptr); - auto runConfig = target->activeRunConfiguration(); - return runConfig; -} - -RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, Kit *kit) -{ - RunConfiguration *runConfig = dummyRunConfigForKit(kit); - QTC_ASSERT(runConfig, return nullptr); - auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); - (void) new DebuggerRunTool(runControl, rp); - ProjectExplorerPlugin::startRunControl(runControl); - return runControl; -} - -} // Internal - // GdbServerPortGatherer GdbServerPortsGatherer::GdbServerPortsGatherer(RunControl *runControl) diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h index 979657b76a7..0db16785cd8 100644 --- a/src/plugins/debugger/debuggerruncontrol.h +++ b/src/plugins/debugger/debuggerruncontrol.h @@ -55,6 +55,10 @@ public: Internal::DebuggerEngine *engine() const { return m_engine; } Internal::DebuggerEngine *activeEngine() const; + static DebuggerRunTool *createFromRunConfiguration(ProjectExplorer::RunConfiguration *runConfig); + static DebuggerRunTool *createFromKit(ProjectExplorer::Kit *kit); + void startRunControl(); + void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1); void start() override; diff --git a/src/plugins/debugger/gdb/startgdbserverdialog.cpp b/src/plugins/debugger/gdb/startgdbserverdialog.cpp index 1a583f6f5c9..a865796a6a2 100644 --- a/src/plugins/debugger/gdb/startgdbserverdialog.cpp +++ b/src/plugins/debugger/gdb/startgdbserverdialog.cpp @@ -214,7 +214,11 @@ void GdbServerStarter::attach(int port) rp.inferior.executable = localExecutable; rp.startMode = AttachToRemoteServer; rp.closeMode = KillAtClose; - createAndScheduleRun(rp, d->kit); + + auto debugger = DebuggerRunTool::createFromKit(d->kit); + QTC_ASSERT(debugger, return); + debugger->setRunParameters(rp); + debugger->startRunControl(); } void GdbServerStarter::handleProcessClosed(int status)