BareMetal: Move closer to a RunWorker based setup

Change-Id: I4160f2e14cdfca7183214a02f1406317291da6be
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-06-15 08:48:24 +02:00
parent a55a376b1d
commit d1247d6796
4 changed files with 88 additions and 98 deletions

View File

@@ -26,37 +26,110 @@
#include "baremetaldebugsupport.h" #include "baremetaldebugsupport.h"
#include "baremetalrunconfiguration.h" #include "baremetalrunconfiguration.h"
#include "baremetaldevice.h" #include "baremetaldevice.h"
#include "baremetalgdbcommandsdeploystep.h"
#include "gdbserverprovider.h" #include "gdbserverprovider.h"
#include "gdbserverprovidermanager.h" #include "gdbserverprovidermanager.h"
#include <debugger/debuggerruncontrol.h> #include <debugger/debuggerruncontrol.h>
#include <debugger/debuggerstartparameters.h> #include <debugger/debuggerkitinformation.h>
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
using namespace Debugger;
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace BareMetal { namespace BareMetal {
namespace Internal { namespace Internal {
BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl, const Debugger::DebuggerStartParameters &sp) BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl)
: Debugger::DebuggerRunTool(runControl, sp) : Debugger::DebuggerRunTool(runControl)
, m_appLauncher(new ProjectExplorer::ApplicationLauncher(this)) , m_appLauncher(new ProjectExplorer::ApplicationLauncher(this))
{ {}
connect(this, &Debugger::DebuggerRunTool::requestRemoteSetup,
this, &BareMetalDebugSupport::remoteSetupRequested);
connect(runControl, &RunControl::finished,
this, &BareMetalDebugSupport::debuggingFinished);
}
BareMetalDebugSupport::~BareMetalDebugSupport() BareMetalDebugSupport::~BareMetalDebugSupport()
{ {
setFinished(); setFinished();
} }
void BareMetalDebugSupport::start()
{
const auto rc = qobject_cast<BareMetalRunConfiguration *>(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<const BareMetalDevice>(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<BareMetalGdbCommandsDeployStep>()) {
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() void BareMetalDebugSupport::remoteSetupRequested()
{ {
QTC_ASSERT(m_state == Inactive, return); QTC_ASSERT(m_state == Inactive, return);

View File

@@ -37,12 +37,12 @@ class BareMetalDebugSupport : public Debugger::DebuggerRunTool
Q_OBJECT Q_OBJECT
public: public:
BareMetalDebugSupport(ProjectExplorer::RunControl *runControl, BareMetalDebugSupport(ProjectExplorer::RunControl *runControl);
const Debugger::DebuggerStartParameters &sp);
~BareMetalDebugSupport(); ~BareMetalDebugSupport();
private: private:
enum State { Inactive, StartingRunner, Running }; enum State { Inactive, StartingRunner, Running };
void start() override;
void remoteSetupRequested(); void remoteSetupRequested();
void debuggingFinished(); void debuggingFinished();

View File

@@ -25,33 +25,8 @@
****************************************************************************/ ****************************************************************************/
#include "baremetalruncontrolfactory.h" #include "baremetalruncontrolfactory.h"
#include "baremetalgdbcommandsdeploystep.h"
#include "baremetalrunconfiguration.h"
#include "baremetaldevice.h"
#include "baremetaldebugsupport.h" #include "baremetaldebugsupport.h"
#include "gdbserverprovider.h"
#include "gdbserverprovidermanager.h"
#include <debugger/debuggerruncontrol.h>
#include <debugger/debuggerstartparameters.h>
#include <debugger/debuggerkitinformation.h>
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
#include <QApplication>
using namespace Debugger;
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace BareMetal { namespace BareMetal {
@@ -75,68 +50,10 @@ bool BareMetalRunControlFactory::canRun(RunConfiguration *runConfiguration, Core
} }
RunControl *BareMetalRunControlFactory::create( RunControl *BareMetalRunControlFactory::create(
RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) RunConfiguration *runConfiguration, Core::Id mode, QString *)
{ {
QTC_ASSERT(canRun(runConfiguration, mode), return 0); auto runControl = new RunControl(runConfiguration, mode);
(void) new BareMetalDebugSupport(runControl);
const auto rc = qobject_cast<BareMetalRunConfiguration *>(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<const BareMetalDevice>(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<BareMetalGdbCommandsDeployStep>()) {
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);
return runControl; return runControl;
} }

View File

@@ -43,7 +43,7 @@ public:
bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode) const override; bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode) const override;
ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id mode, QString *errorMessage) override; Core::Id mode, QString *) override;
}; };
} // namespace Internal } // namespace Internal