Commit e57bcafc authored by dt's avatar dt
Browse files

Fix startExternal, attachExternal &more to not use a RunConfiguration

Removes around 50 lines of code, one completly unecessary class and
makes the code paths easier to understand.
parent 64c23b27
......@@ -1179,15 +1179,6 @@ void DebuggerPlugin::showSettingsDialog()
QLatin1String(Debugger::Constants::DEBUGGER_COMMON_SETTINGS_PAGE));
}
static RunConfigurationPtr activeRunConfiguration()
{
ProjectExplorer::Project *project =
ProjectExplorerPlugin::instance()->currentProject();
if (project)
return project->activeRunConfiguration();
return RunConfigurationPtr();
}
void DebuggerPlugin::startExternalApplication()
{
const DebuggerStartParametersPtr sp(new DebuggerStartParameters);
......@@ -1211,13 +1202,8 @@ void DebuggerPlugin::startExternalApplication()
if (dlg.breakAtMain())
m_manager->breakByFunctionMain();
RunConfigurationPtr rc = activeRunConfiguration();
if (rc.isNull())
rc = DebuggerRunControlFactory::createDefaultRunConfiguration(sp->executable);
if (RunControl *runControl = m_debuggerRunControlFactory
->create(rc, ProjectExplorer::Constants::DEBUGMODE, sp))
runControl->start();
if (RunControl *runControl = m_debuggerRunControlFactory->create(sp, ProjectExplorer::Constants::DEBUGMODE))
ProjectExplorerPlugin::instance()->startRunControl(runControl, ProjectExplorer::Constants::DEBUGMODE);
}
void DebuggerPlugin::attachExternalApplication()
......@@ -1237,12 +1223,8 @@ void DebuggerPlugin::attachExternalApplication(qint64 pid, const QString &crashP
sp->attachPID = pid;
sp->crashParameter = crashParameter;
sp->startMode = crashParameter.isEmpty() ? AttachExternal : AttachCrashedExternal;
RunConfigurationPtr rc = activeRunConfiguration();
if (rc.isNull())
rc = DebuggerRunControlFactory::createDefaultRunConfiguration();
if (RunControl *runControl = m_debuggerRunControlFactory
->create(rc, ProjectExplorer::Constants::DEBUGMODE, sp))
runControl->start();
if (RunControl *runControl = m_debuggerRunControlFactory->create(sp, ProjectExplorer::Constants::DEBUGMODE))
ProjectExplorerPlugin::instance()->startRunControl(runControl, ProjectExplorer::Constants::DEBUGMODE);
}
void DebuggerPlugin::attachCmdLineCore()
......@@ -1273,12 +1255,9 @@ void DebuggerPlugin::attachCore(const QString &core, const QString &exe)
sp->executable = exe;
sp->coreFile = core;
sp->startMode = AttachCore;
RunConfigurationPtr rc = activeRunConfiguration();
if (rc.isNull())
rc = DebuggerRunControlFactory::createDefaultRunConfiguration();
if (RunControl *runControl = m_debuggerRunControlFactory
->create(rc, ProjectExplorer::Constants::DEBUGMODE, sp))
runControl->start();
->create(sp, ProjectExplorer::Constants::DEBUGMODE))
ProjectExplorerPlugin::instance()->startRunControl(runControl, ProjectExplorer::Constants::DEBUGMODE);
}
void DebuggerPlugin::startRemoteApplication()
......@@ -1312,12 +1291,8 @@ void DebuggerPlugin::startRemoteApplication()
sp->serverStartScript = dlg.serverStartScript();
sp->sysRoot = dlg.sysroot();
RunConfigurationPtr rc = activeRunConfiguration();
if (rc.isNull())
rc = DebuggerRunControlFactory::createDefaultRunConfiguration();
if (RunControl *runControl = m_debuggerRunControlFactory
->create(rc, ProjectExplorer::Constants::DEBUGMODE, sp))
runControl->start();
if (RunControl *runControl = m_debuggerRunControlFactory->create(sp, ProjectExplorer::Constants::DEBUGMODE))
ProjectExplorerPlugin::instance()->startRunControl(runControl, ProjectExplorer::Constants::DEBUGMODE);
}
#include "debuggerplugin.moc"
......
......@@ -51,12 +51,6 @@ using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunControl;
using ProjectExplorer::LocalApplicationRunConfiguration;
DefaultLocalApplicationRunConfiguration::DefaultLocalApplicationRunConfiguration(const QString &executable) :
ProjectExplorer::LocalApplicationRunConfiguration(0),
m_executable(executable)
{
}
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlFactory
......@@ -79,28 +73,19 @@ QString DebuggerRunControlFactory::displayName() const
return tr("Debug");
}
RunConfigurationPtr DebuggerRunControlFactory::createDefaultRunConfiguration(const QString &executable)
RunControl *DebuggerRunControlFactory::create(const DebuggerStartParametersPtr &sp, const QString &mode)
{
return RunConfigurationPtr(new DefaultLocalApplicationRunConfiguration(executable));
return new DebuggerRunControl(m_manager, sp);
}
RunControl *DebuggerRunControlFactory::create(const RunConfigurationPtr &runConfiguration,
const QString &mode,
const DebuggerStartParametersPtr &sp)
const QString &mode)
{
QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
LocalApplicationRunConfigurationPtr rc =
runConfiguration.objectCast<LocalApplicationRunConfiguration>();
QTC_ASSERT(!rc.isNull(), return 0);
return new DebuggerRunControl(m_manager, sp, rc);
}
RunControl *DebuggerRunControlFactory::create(const RunConfigurationPtr &runConfiguration,
const QString &mode)
{
const DebuggerStartParametersPtr sp(new DebuggerStartParameters);
sp->startMode = StartInternal;
return create(runConfiguration, mode, sp);
return new DebuggerRunControl(m_manager, rc);
}
QWidget *DebuggerRunControlFactory::configurationWidget(const RunConfigurationPtr &runConfiguration)
......@@ -120,38 +105,22 @@ QWidget *DebuggerRunControlFactory::configurationWidget(const RunConfigurationPt
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
const DebuggerStartParametersPtr &startParameters,
QSharedPointer<LocalApplicationRunConfiguration> runConfiguration)
: RunControl(runConfiguration),
m_startParameters(startParameters),
m_startParameters(new DebuggerStartParameters()),
m_manager(manager),
m_running(false)
{
connect(m_manager, SIGNAL(debuggingFinished()),
this, SLOT(debuggingFinished()),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
this, SLOT(slotAddToOutputWindowInline(QString)),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
this, SLOT(bringApplicationToForeground(qint64)),
Qt::QueuedConnection);
connect(this, SIGNAL(stopRequested()),
m_manager, SLOT(exitDebugger()));
init();
if (!runConfiguration)
return;
// Enhance parameters by info from the project, but do not clobber
// arguments given in the dialogs
if (m_startParameters->executable.isEmpty())
m_startParameters->executable = runConfiguration->executable();
if (m_startParameters->environment.empty())
m_startParameters->environment = runConfiguration->environment().toStringList();
if (m_startParameters->workingDir.isEmpty())
m_startParameters->workingDir = runConfiguration->workingDirectory();
if (m_startParameters->startMode != StartExternal)
m_startParameters->processArgs = runConfiguration->commandLineArguments();
m_startParameters->startMode = StartInternal;
m_startParameters->executable = runConfiguration->executable();
m_startParameters->environment = runConfiguration->environment().toStringList();
m_startParameters->workingDir = runConfiguration->workingDirectory();
m_startParameters->processArgs = runConfiguration->commandLineArguments();
switch (m_startParameters->toolChainType) {
case ProjectExplorer::ToolChain::UNKNOWN:
case ProjectExplorer::ToolChain::INVALID:
......@@ -172,6 +141,34 @@ DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
runConfiguration->dumperLibraryLocations();
}
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager, const DebuggerStartParametersPtr &startParameters)
: RunControl(RunConfigurationPtr(0)),
m_startParameters(startParameters),
m_manager(manager),
m_running(false)
{
init();
if (m_startParameters->environment.empty())
m_startParameters->environment = ProjectExplorer::Environment::Environment().toStringList();
m_startParameters->useTerminal = false;
}
void DebuggerRunControl::init()
{
connect(m_manager, SIGNAL(debuggingFinished()),
this, SLOT(debuggingFinished()),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
this, SLOT(slotAddToOutputWindowInline(QString)),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
this, SLOT(bringApplicationToForeground(qint64)),
Qt::QueuedConnection);
connect(this, SIGNAL(stopRequested()),
m_manager, SLOT(exitDebugger()));
}
void DebuggerRunControl::start()
{
m_running = true;
......
......@@ -67,11 +67,7 @@ public:
virtual QWidget *configurationWidget(const RunConfigurationPtr &runConfiguration);
virtual ProjectExplorer::RunControl *create(const RunConfigurationPtr &runConfiguration,
const QString &mode,
const DebuggerStartParametersPtr &sp);
static RunConfigurationPtr createDefaultRunConfiguration(const QString &executable = QString());
ProjectExplorer::RunControl *create(const DebuggerStartParametersPtr &sp, const QString &mode);
private:
DebuggerStartParametersPtr m_startParameters;
......@@ -86,8 +82,8 @@ class DebuggerRunControl
public:
DebuggerRunControl(DebuggerManager *manager,
const DebuggerStartParametersPtr &startParamters,
LocalApplicationRunConfigurationPtr runConfiguration);
DebuggerRunControl(DebuggerManager *manager, const DebuggerStartParametersPtr &startParameters);
// ProjectExplorer::RunControl
virtual void start();
......@@ -104,36 +100,12 @@ private slots:
void slotAddToOutputWindowInline(const QString &output);
private:
void init();
DebuggerStartParametersPtr m_startParameters;
DebuggerManager *m_manager;
bool m_running;
};
// A default run configuration for external executables or attaching to
// running processes by id.
class DefaultLocalApplicationRunConfiguration
: public ProjectExplorer::LocalApplicationRunConfiguration
{
Q_OBJECT
public:
explicit DefaultLocalApplicationRunConfiguration(const QString &executable = QString());
virtual QString executable() const { return m_executable; }
virtual RunMode runMode() const { return Gui; }
virtual QString workingDirectory() const { return QString(); }
virtual QStringList commandLineArguments() const { return QStringList(); }
virtual ProjectExplorer::Environment environment() const
{ return ProjectExplorer::Environment(); }
virtual QString dumperLibrary() const { return QString(); }
virtual QStringList dumperLibraryLocations() const { return QStringList(); }
virtual ProjectExplorer::ToolChain::ToolChainType toolChainType() const
{ return ProjectExplorer::ToolChain::UNKNOWN; }
virtual QWidget *configurationWidget() { return 0; }
private:
const QString m_executable;
};
} // namespace Internal
} // namespace Debugger
......
......@@ -212,7 +212,11 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
agg->add(ow);
agg->add(new Find::BaseTextFind(ow));
m_outputWindows.insert(rc, ow);
m_tabWidget->addTab(ow, rc->runConfiguration()->name());
// TODO add a displayName to RunControl, can't rely on there always beeing a runconfiguration
QString name = "External Application";
if (rc->runConfiguration())
name = rc->runConfiguration()->name();
m_tabWidget->addTab(ow, name);
}
}
......@@ -244,7 +248,7 @@ void OutputPane::insertLine()
void OutputPane::reRunRunControl()
{
RunControl *rc = runControlForTab(m_tabWidget->currentIndex());
if (rc->runConfiguration()->project() != 0)
if (rc->runConfiguration() && rc->runConfiguration()->project() != 0)
rc->start();
}
......@@ -283,7 +287,7 @@ void OutputPane::tabChanged(int i)
} else {
RunControl *rc = runControlForTab(i);
m_stopAction->setEnabled(rc->isRunning());
m_reRunButton->setEnabled(!rc->isRunning() && rc->runConfiguration()->project());
m_reRunButton->setEnabled(!rc->isRunning() && rc->runConfiguration() && rc->runConfiguration()->project());
}
}
......@@ -300,7 +304,7 @@ void OutputPane::runControlFinished()
{
RunControl *rc = runControlForTab(m_tabWidget->currentIndex());
if (rc == qobject_cast<RunControl *>(sender())) {
m_reRunButton->setEnabled(rc->runConfiguration()->project());
m_reRunButton->setEnabled(rc->runConfiguration() && rc->runConfiguration()->project());
m_stopAction->setEnabled(false);
}
}
......
......@@ -106,6 +106,8 @@ public:
void setProjectExplorerSettings(const Internal::ProjectExplorerSettings &pes);
Internal::ProjectExplorerSettings projectExplorerSettings() const;
void ProjectExplorerPlugin::startRunControl(RunControl *runControl, const QString &mode);
signals:
void aboutToShowContextMenu(ProjectExplorer::Project *project,
ProjectExplorer::Node *node);
......@@ -184,8 +186,6 @@ private slots:
void loadProject(const QString &project) { openProject(project); }
void currentModeChanged(Core::IMode *mode);
void ProjectExplorerPlugin::startRunControl(RunControl *runControl, const QString &mode);
private:
void runProjectImpl(Project *pro);
void executeRunConfiguration(const QSharedPointer<RunConfiguration> &, const QString &mode);
......
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