From d1247d67968beb4bb40d75d4bc930febfa160f61 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 15 Jun 2017 08:48:24 +0200 Subject: [PATCH] BareMetal: Move closer to a RunWorker based setup Change-Id: I4160f2e14cdfca7183214a02f1406317291da6be Reviewed-by: Christian Stenger --- .../baremetal/baremetaldebugsupport.cpp | 91 +++++++++++++++++-- src/plugins/baremetal/baremetaldebugsupport.h | 4 +- .../baremetal/baremetalruncontrolfactory.cpp | 89 +----------------- .../baremetal/baremetalruncontrolfactory.h | 2 +- 4 files changed, 88 insertions(+), 98 deletions(-) diff --git a/src/plugins/baremetal/baremetaldebugsupport.cpp b/src/plugins/baremetal/baremetaldebugsupport.cpp index 8fea7dc399a..9ad7cb91050 100644 --- a/src/plugins/baremetal/baremetaldebugsupport.cpp +++ b/src/plugins/baremetal/baremetaldebugsupport.cpp @@ -26,37 +26,110 @@ #include "baremetaldebugsupport.h" #include "baremetalrunconfiguration.h" #include "baremetaldevice.h" +#include "baremetalgdbcommandsdeploystep.h" #include "gdbserverprovider.h" #include "gdbserverprovidermanager.h" #include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include #include +using namespace Debugger; using namespace ProjectExplorer; namespace BareMetal { namespace Internal { -BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl, const Debugger::DebuggerStartParameters &sp) - : Debugger::DebuggerRunTool(runControl, sp) +BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl) + : Debugger::DebuggerRunTool(runControl) , m_appLauncher(new ProjectExplorer::ApplicationLauncher(this)) -{ - connect(this, &Debugger::DebuggerRunTool::requestRemoteSetup, - this, &BareMetalDebugSupport::remoteSetupRequested); - connect(runControl, &RunControl::finished, - this, &BareMetalDebugSupport::debuggingFinished); -} +{} BareMetalDebugSupport::~BareMetalDebugSupport() { setFinished(); } +void BareMetalDebugSupport::start() +{ + const auto rc = qobject_cast(runControl()->runConfiguration()); + QTC_ASSERT(rc, reportFailure(); return); + + const QString bin = rc->localExecutableFilePath(); + if (bin.isEmpty()) { + reportFailure(tr("Cannot debug: Local executable is not set.")); + return; + } + if (!QFile::exists(bin)) { + reportFailure(tr("Cannot debug: Could not find executable for \"%1\".").arg(bin)); + return; + } + + const Target *target = rc->target(); + QTC_ASSERT(target, reportFailure(); return); + + const Kit *kit = target->kit(); + QTC_ASSERT(kit, reportFailure(); return); + + auto dev = qSharedPointerCast(DeviceKitInformation::device(kit)); + if (!dev) { + reportFailure(tr("Cannot debug: Kit has no device.")); + return; + } + + const GdbServerProvider *p = GdbServerProviderManager::findProvider(dev->gdbServerProviderId()); + if (!p) { + reportFailure(tr("Cannot debug: Device has no GDB server provider configuration.")); + return; + } + + Debugger::DebuggerStartParameters sp; + + if (const BuildConfiguration *bc = target->activeBuildConfiguration()) { + if (BuildStepList *bsl = bc->stepList(BareMetalGdbCommandsDeployStep::stepId())) { + foreach (const BareMetalGdbCommandsDeployStep *bs, bsl->allOfType()) { + if (!sp.commandsAfterConnect.endsWith("\n")) + sp.commandsAfterConnect.append("\n"); + sp.commandsAfterConnect.append(bs->gdbCommands()); + } + } + } + + sp.inferior.executable = bin; + sp.inferior.commandLineArguments = rc->arguments(); + sp.symbolFile = bin; + sp.startMode = AttachToRemoteServer; + sp.commandsAfterConnect = p->initCommands(); + sp.commandsForReset = p->resetCommands(); + sp.remoteChannel = p->channel(); + sp.useContinueInsteadOfRun = true; + + if (p->startupMode() == GdbServerProvider::StartupOnNetwork) + sp.remoteSetupNeeded = true; + setStartParameters(sp); + + connect(this, &Debugger::DebuggerRunTool::requestRemoteSetup, + this, &BareMetalDebugSupport::remoteSetupRequested); + connect(runControl(), &RunControl::finished, + this, &BareMetalDebugSupport::debuggingFinished); + + DebuggerRunTool::start(); +} + void BareMetalDebugSupport::remoteSetupRequested() { QTC_ASSERT(m_state == Inactive, return); diff --git a/src/plugins/baremetal/baremetaldebugsupport.h b/src/plugins/baremetal/baremetaldebugsupport.h index 3baef0f9abd..1a7da3645d8 100644 --- a/src/plugins/baremetal/baremetaldebugsupport.h +++ b/src/plugins/baremetal/baremetaldebugsupport.h @@ -37,12 +37,12 @@ class BareMetalDebugSupport : public Debugger::DebuggerRunTool Q_OBJECT public: - BareMetalDebugSupport(ProjectExplorer::RunControl *runControl, - const Debugger::DebuggerStartParameters &sp); + BareMetalDebugSupport(ProjectExplorer::RunControl *runControl); ~BareMetalDebugSupport(); private: enum State { Inactive, StartingRunner, Running }; + void start() override; void remoteSetupRequested(); void debuggingFinished(); diff --git a/src/plugins/baremetal/baremetalruncontrolfactory.cpp b/src/plugins/baremetal/baremetalruncontrolfactory.cpp index 3b419a493bd..07c3b8b66e9 100644 --- a/src/plugins/baremetal/baremetalruncontrolfactory.cpp +++ b/src/plugins/baremetal/baremetalruncontrolfactory.cpp @@ -25,33 +25,8 @@ ****************************************************************************/ #include "baremetalruncontrolfactory.h" -#include "baremetalgdbcommandsdeploystep.h" -#include "baremetalrunconfiguration.h" -#include "baremetaldevice.h" #include "baremetaldebugsupport.h" -#include "gdbserverprovider.h" -#include "gdbserverprovidermanager.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace Debugger; using namespace ProjectExplorer; namespace BareMetal { @@ -75,68 +50,10 @@ bool BareMetalRunControlFactory::canRun(RunConfiguration *runConfiguration, Core } RunControl *BareMetalRunControlFactory::create( - RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) + RunConfiguration *runConfiguration, Core::Id mode, QString *) { - QTC_ASSERT(canRun(runConfiguration, mode), return 0); - - const auto rc = qobject_cast(runConfiguration); - QTC_ASSERT(rc, return 0); - - const QString bin = rc->localExecutableFilePath(); - if (bin.isEmpty()) { - *errorMessage = tr("Cannot debug: Local executable is not set."); - return 0; - } else if (!QFile::exists(bin)) { - *errorMessage = tr("Cannot debug: Could not find executable for \"%1\".") - .arg(bin); - return 0; - } - - const Target *target = rc->target(); - QTC_ASSERT(target, return 0); - - const Kit *kit = target->kit(); - QTC_ASSERT(kit, return 0); - - auto dev = qSharedPointerCast(DeviceKitInformation::device(kit)); - if (!dev) { - *errorMessage = tr("Cannot debug: Kit has no device."); - return 0; - } - - const GdbServerProvider *p = GdbServerProviderManager::findProvider(dev->gdbServerProviderId()); - if (!p) { - *errorMessage = tr("Cannot debug: Device has no GDB server provider configuration."); - return 0; - } - - DebuggerStartParameters sp; - - if (const BuildConfiguration *bc = target->activeBuildConfiguration()) { - if (BuildStepList *bsl = bc->stepList(BareMetalGdbCommandsDeployStep::stepId())) { - foreach (const BareMetalGdbCommandsDeployStep *bs, bsl->allOfType()) { - if (!sp.commandsAfterConnect.endsWith("\n")) - sp.commandsAfterConnect.append("\n"); - sp.commandsAfterConnect.append(bs->gdbCommands()); - } - } - } - - sp.inferior.executable = bin; - sp.inferior.commandLineArguments = rc->arguments(); - sp.symbolFile = bin; - sp.startMode = AttachToRemoteServer; - sp.commandsAfterConnect = p->initCommands(); - sp.commandsForReset = p->resetCommands(); - sp.remoteChannel = p->channel(); - sp.useContinueInsteadOfRun = true; - - if (p->startupMode() == GdbServerProvider::StartupOnNetwork) - sp.remoteSetupNeeded = true; - - auto runControl = new RunControl(rc, mode); - new BareMetalDebugSupport(runControl, sp); - + auto runControl = new RunControl(runConfiguration, mode); + (void) new BareMetalDebugSupport(runControl); return runControl; } diff --git a/src/plugins/baremetal/baremetalruncontrolfactory.h b/src/plugins/baremetal/baremetalruncontrolfactory.h index 1cab1af9ee5..4e53d87518a 100644 --- a/src/plugins/baremetal/baremetalruncontrolfactory.h +++ b/src/plugins/baremetal/baremetalruncontrolfactory.h @@ -43,7 +43,7 @@ public: bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode) const override; ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id mode, QString *errorMessage) override; + Core::Id mode, QString *) override; }; } // namespace Internal