diff --git a/src/plugins/madde/maemorunfactories.cpp b/src/plugins/madde/maemorunfactories.cpp index 43d1309e6eb..54ca2df1a5c 100644 --- a/src/plugins/madde/maemorunfactories.cpp +++ b/src/plugins/madde/maemorunfactories.cpp @@ -46,6 +46,7 @@ #include #include #include +#include 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(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(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 diff --git a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp index a8b7b2b39c2..545c0ed330b 100644 --- a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp +++ b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp @@ -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(); diff --git a/src/plugins/remotelinux/remotelinuxruncontrolfactory.cpp b/src/plugins/remotelinux/remotelinuxruncontrolfactory.cpp index 85aed49675b..742196ae2fd 100644 --- a/src/plugins/remotelinux/remotelinuxruncontrolfactory.cpp +++ b/src/plugins/remotelinux/remotelinuxruncontrolfactory.cpp @@ -41,6 +41,7 @@ #include #include #include +#include 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(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(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