Commit 02842c14 authored by Christian Kandeler's avatar Christian Kandeler

RemoteLinux/Madde: Do not do too much checking in run control factories.

Only check whether we are generally responsible for the given type of
run configuration. Delay the other checks to a point where we can give a
meaningful error message to the user.

Task-number: QTCREATORBUG-6330
Change-Id: I9c8419da7780ebe17ff853bcae3de14b9cb66b71
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent c0b6d1d3
......@@ -46,6 +46,7 @@
#include <qtsupport/customexecutablerunconfiguration.h>
#include <remotelinux/remotelinuxdebugsupport.h>
#include <remotelinux/remotelinuxruncontrol.h>
#include <utils/qtcassert.h>
using namespace Debugger;
using namespace ProjectExplorer;
......@@ -195,35 +196,58 @@ MaemoRunControlFactory::~MaemoRunControlFactory()
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
{
if (mode != NormalRunMode && mode != DebugRunMode && mode != DebugRunModeWithBreakOnMain)
return false;
const MaemoRunConfiguration * const maemoRunConfig
= qobject_cast<MaemoRunConfiguration *>(runConfiguration);
if (!maemoRunConfig || !maemoRunConfig->isEnabled())
return false;
return maemoRunConfig->hasEnoughFreePorts(mode);
return maemoRunConfig && maemoRunConfig->isEnabled();
}
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode, QString *errorMessage)
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode,
QString *errorMessage)
{
Q_ASSERT(canRun(runConfig, mode));
QTC_ASSERT(canRun(runConfig, mode), return 0);
MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
Q_ASSERT(rc);
if (mode == NormalRunMode) {
QTC_ASSERT(rc, return 0);
switch (mode) {
case NormalRunMode: {
RemoteLinuxRunControl * const runControl = new RemoteLinuxRunControl(rc);
setHelperActions(runControl, rc, runControl);
return runControl;
}
case DebugRunMode:
case DebugRunModeWithBreakOnMain: {
IDevice::ConstPtr dev = DeviceKitInformation::device(rc->target()->kit());
if (!dev) {
*errorMessage = tr("Cannot debug: Kit has no device.");
return 0;
}
if (rc->portsUsedByDebuggers() > dev->freePorts().count()) {
*errorMessage = tr("Cannot debug: Not enough free ports available.");
return 0;
}
DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
if (mode == ProjectExplorer::DebugRunModeWithBreakOnMain)
params.breakOnMain = true;
DebuggerRunControl * const runControl
= DebuggerPlugin::createDebugger(params, rc, errorMessage);
if (!runControl)
return 0;
LinuxDeviceDebugSupport * const debugSupport =
new LinuxDeviceDebugSupport(rc, runControl->engine());
setHelperActions(debugSupport, rc, runControl);
connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
return runControl;
}
case NoRunMode:
case QmlProfilerRunMode:
case CallgrindRunMode:
case MemcheckRunMode:
QTC_ASSERT(false, return 0);
}
const DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc, errorMessage);
if (!runControl)
return 0;
LinuxDeviceDebugSupport * const debugSupport
= new LinuxDeviceDebugSupport(rc, runControl->engine());
setHelperActions(debugSupport, rc, runControl);
connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
return runControl;
QTC_ASSERT(false, return 0);
}
QString MaemoRunControlFactory::displayName() const
......
......@@ -101,6 +101,7 @@ DebuggerStartParameters LinuxDeviceDebugSupport::startParameters(const RemoteLin
Target *target = runConfig->target();
Kit *k = target->kit();
const IDevice::ConstPtr device = DeviceKitInformation::device(k);
QTC_ASSERT(device, return params);
params.sysRoot = SysRootKitInformation::sysRoot(k).toString();
params.debuggerCommand = DebuggerKitInformation::debuggerCommand(k).toString();
......
......@@ -41,6 +41,7 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
using namespace Debugger;
using namespace ProjectExplorer;
......@@ -63,42 +64,50 @@ bool RemoteLinuxRunControlFactory::canRun(RunConfiguration *runConfiguration, Ru
return false;
const QByteArray idStr = runConfiguration->id().name();
if (!runConfiguration->isEnabled() || !idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix))
return false;
if (mode == NormalRunMode)
return true;
const RemoteLinuxRunConfiguration * const remoteRunConfig
= qobject_cast<RemoteLinuxRunConfiguration *>(runConfiguration);
if (mode == DebugRunMode) {
IDevice::ConstPtr dev = DeviceKitInformation::device(runConfiguration->target()->kit());
if (dev.isNull())
return false;
return remoteRunConfig->portsUsedByDebuggers() <= dev->freePorts().count();
}
return true;
return runConfiguration->isEnabled() && idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix);
}
RunControl *RemoteLinuxRunControlFactory::create(RunConfiguration *runConfig, RunMode mode, QString *errorMessage)
RunControl *RemoteLinuxRunControlFactory::create(RunConfiguration *runConfig, RunMode mode,
QString *errorMessage)
{
Q_ASSERT(canRun(runConfig, mode));
QTC_ASSERT(canRun(runConfig, mode), return 0);
RemoteLinuxRunConfiguration *rc = qobject_cast<RemoteLinuxRunConfiguration *>(runConfig);
Q_ASSERT(rc);
if (mode == ProjectExplorer::NormalRunMode)
QTC_ASSERT(rc, return 0);
switch (mode) {
case NormalRunMode:
return new RemoteLinuxRunControl(rc);
case DebugRunMode:
case DebugRunModeWithBreakOnMain: {
IDevice::ConstPtr dev = DeviceKitInformation::device(rc->target()->kit());
if (!dev) {
*errorMessage = tr("Cannot debug: Kit has no device.");
return 0;
}
if (rc->portsUsedByDebuggers() > dev->freePorts().count()) {
*errorMessage = tr("Cannot debug: Not enough free ports available.");
return 0;
}
DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
if (mode == ProjectExplorer::DebugRunModeWithBreakOnMain)
params.breakOnMain = true;
DebuggerRunControl * const runControl
= DebuggerPlugin::createDebugger(params, rc, errorMessage);
if (!runControl)
return 0;
LinuxDeviceDebugSupport * const debugSupport =
new LinuxDeviceDebugSupport(rc, runControl->engine());
connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
return runControl;
}
case NoRunMode:
case QmlProfilerRunMode:
case CallgrindRunMode:
case MemcheckRunMode:
QTC_ASSERT(false, return 0);
}
DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
if (mode == ProjectExplorer::DebugRunModeWithBreakOnMain)
params.breakOnMain = true;
DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc, errorMessage);
if (!runControl)
return 0;
LinuxDeviceDebugSupport * const debugSupport =
new LinuxDeviceDebugSupport(rc, runControl->engine());
connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
return runControl;
QTC_ASSERT(false, return 0);
}
QString RemoteLinuxRunControlFactory::displayName() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment