Debugger: Dissolve createAndScheduleRun()

... into DebuggerRunTool creation and explicit RunParameter bulk setting,
which later is to be replaced by setting individual parameters.

Change-Id: Ic4d2c6d10d659287ae61fdb4db735e658e3a68ce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-08-24 18:40:37 +02:00
parent 13a1f8686c
commit 5e871ddb65
5 changed files with 93 additions and 54 deletions

View File

@@ -462,8 +462,6 @@ private:
QPointer<DebuggerEngine> m_engine; QPointer<DebuggerEngine> m_engine;
}; };
ProjectExplorer::RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, ProjectExplorer::Kit *kit);
} // namespace Internal } // namespace Internal
} // namespace Debugger } // namespace Debugger

View File

@@ -1940,8 +1940,12 @@ void DebuggerPluginPrivate::startAndDebugApplication()
{ {
DebuggerRunParameters rp; DebuggerRunParameters rp;
Kit *kit; Kit *kit;
if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) {
createAndScheduleRun(rp, kit); auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
}
} }
void DebuggerPluginPrivate::attachCore() void DebuggerPluginPrivate::attachCore()
@@ -1976,7 +1980,11 @@ void DebuggerPluginPrivate::attachCore()
rp.startMode = AttachCore; rp.startMode = AttachCore;
rp.closeMode = DetachAtClose; rp.closeMode = DetachAtClose;
rp.overrideStartScript = dlg.overrideStartScript(); rp.overrideStartScript = dlg.overrideStartScript();
createAndScheduleRun(rp, dlg.kit());
auto debugger = DebuggerRunTool::createFromKit(dlg.kit());
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
void DebuggerPluginPrivate::startRemoteCdbSession() void DebuggerPluginPrivate::startRemoteCdbSession()
@@ -1996,7 +2004,11 @@ void DebuggerPluginPrivate::startRemoteCdbSession()
return; return;
rp.remoteChannel = dlg.connection(); rp.remoteChannel = dlg.connection();
setConfigValue(connectionKey, rp.remoteChannel); setConfigValue(connectionKey, rp.remoteChannel);
createAndScheduleRun(rp, kit);
auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
void DebuggerPluginPrivate::attachToRemoteServer() void DebuggerPluginPrivate::attachToRemoteServer()
@@ -2007,7 +2019,10 @@ void DebuggerPluginPrivate::attachToRemoteServer()
rp.useContinueInsteadOfRun = true; rp.useContinueInsteadOfRun = true;
if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) { if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) {
rp.closeMode = KillAtClose; rp.closeMode = KillAtClose;
createAndScheduleRun(rp, kit); auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
} }
@@ -2112,7 +2127,13 @@ RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
rp.startMode = AttachExternal; rp.startMode = AttachExternal;
rp.closeMode = DetachAtClose; rp.closeMode = DetachAtClose;
rp.continueAfterAttach = contAfterAttach; rp.continueAfterAttach = contAfterAttach;
return createAndScheduleRun(rp, kit);
auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return nullptr);
debugger->setRunParameters(rp);
debugger->startRunControl();
return debugger->runControl();
} }
void DebuggerPlugin::attachExternalApplication(RunControl *rc) void DebuggerPlugin::attachExternalApplication(RunControl *rc)
@@ -2124,13 +2145,16 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
rp.closeMode = DetachAtClose; rp.closeMode = DetachAtClose;
rp.toolChainAbi = rc->abi(); rp.toolChainAbi = rc->abi();
rp.languages = CppLanguage; rp.languages = CppLanguage;
DebuggerRunTool *debugger;
if (RunConfiguration *runConfig = rc->runConfiguration()) { if (RunConfiguration *runConfig = rc->runConfiguration()) {
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); debugger = DebuggerRunTool::createFromRunConfiguration(runConfig);
(void) new DebuggerRunTool(runControl, rp);
ProjectExplorerPlugin::startRunControl(runControl);
} else { } else {
createAndScheduleRun(rp, guessKitFromParameters(rp)); Kit *kit = guessKitFromParameters(rp);
debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
} }
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
void DebuggerPlugin::getEnginesState(QByteArray *json) const void DebuggerPlugin::getEnginesState(QByteArray *json) const
@@ -2210,7 +2234,11 @@ void DebuggerPluginPrivate::attachToQmlPort()
rp.projectSourceDirectory = rp.projectSourceDirectory =
!projects.isEmpty() ? projects.first()->projectDirectory().toString() : QString(); !projects.isEmpty() ? projects.first()->projectDirectory().toString() : QString();
rp.projectSourceFiles = sourceFiles; rp.projectSourceFiles = sourceFiles;
createAndScheduleRun(rp, kit);
auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &value) void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &value)
@@ -2223,8 +2251,12 @@ void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &valu
void DebuggerPluginPrivate::runScheduled() void DebuggerPluginPrivate::runScheduled()
{ {
for (const QPair<DebuggerRunParameters, Kit *> pair : m_scheduledStarts) for (const QPair<DebuggerRunParameters, Kit *> pair : m_scheduledStarts) {
createAndScheduleRun(pair.first, pair.second); auto debugger = DebuggerRunTool::createFromKit(pair.second);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(pair.first);
debugger->startRunControl();
}
} }
void DebuggerPluginPrivate::editorOpened(IEditor *editor) void DebuggerPluginPrivate::editorOpened(IEditor *editor)

View File

@@ -831,6 +831,45 @@ DebuggerEngine *DebuggerRunTool::activeEngine() const
return m_engine ? m_engine->activeEngine() : nullptr; return m_engine ? m_engine->activeEngine() : nullptr;
} }
class DummyProject : public Project
{
public:
DummyProject() : Project(QString(""), FileName::fromString("")) {}
};
RunConfiguration *dummyRunConfigForKit(ProjectExplorer::Kit *kit)
{
QTC_ASSERT(kit, return nullptr); // Caller needs to look for a suitable kit.
Project *project = SessionManager::startupProject();
Target *target = project ? project->target(kit) : nullptr;
if (!target || !target->activeRunConfiguration()) {
project = new DummyProject; // FIXME: Leaks.
target = project->createTarget(kit);
}
QTC_ASSERT(target, return nullptr);
auto runConfig = target->activeRunConfiguration();
return runConfig;
}
DebuggerRunTool *DebuggerRunTool::createFromKit(Kit *kit)
{
RunConfiguration *runConfig = dummyRunConfigForKit(kit);
return createFromRunConfiguration(runConfig);
}
void DebuggerRunTool::startRunControl()
{
ProjectExplorerPlugin::startRunControl(runControl());
}
DebuggerRunTool *DebuggerRunTool::createFromRunConfiguration(RunConfiguration *runConfig)
{
QTC_ASSERT(runConfig, return nullptr);
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl);
return debugger;
}
void DebuggerRunTool::addSolibSearchDir(const QString &str) void DebuggerRunTool::addSolibSearchDir(const QString &str)
{ {
QString path = str; QString path = str;
@@ -876,44 +915,6 @@ void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout)
// //
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
namespace Internal {
/**
* Used for direct "special" starts from actions in the debugger plugin.
*/
class DummyProject : public Project
{
public:
DummyProject() : Project(QString(""), FileName::fromString("")) {}
};
RunConfiguration *dummyRunConfigForKit(ProjectExplorer::Kit *kit)
{
QTC_ASSERT(kit, return nullptr); // Caller needs to look for a suitable kit.
Project *project = SessionManager::startupProject();
Target *target = project ? project->target(kit) : nullptr;
if (!target || !target->activeRunConfiguration()) {
project = new DummyProject;
target = project->createTarget(kit);
}
QTC_ASSERT(target, return nullptr);
auto runConfig = target->activeRunConfiguration();
return runConfig;
}
RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, Kit *kit)
{
RunConfiguration *runConfig = dummyRunConfigForKit(kit);
QTC_ASSERT(runConfig, return nullptr);
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new DebuggerRunTool(runControl, rp);
ProjectExplorerPlugin::startRunControl(runControl);
return runControl;
}
} // Internal
// GdbServerPortGatherer // GdbServerPortGatherer
GdbServerPortsGatherer::GdbServerPortsGatherer(RunControl *runControl) GdbServerPortsGatherer::GdbServerPortsGatherer(RunControl *runControl)

View File

@@ -55,6 +55,10 @@ public:
Internal::DebuggerEngine *engine() const { return m_engine; } Internal::DebuggerEngine *engine() const { return m_engine; }
Internal::DebuggerEngine *activeEngine() const; Internal::DebuggerEngine *activeEngine() const;
static DebuggerRunTool *createFromRunConfiguration(ProjectExplorer::RunConfiguration *runConfig);
static DebuggerRunTool *createFromKit(ProjectExplorer::Kit *kit);
void startRunControl();
void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1); void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1);
void start() override; void start() override;

View File

@@ -214,7 +214,11 @@ void GdbServerStarter::attach(int port)
rp.inferior.executable = localExecutable; rp.inferior.executable = localExecutable;
rp.startMode = AttachToRemoteServer; rp.startMode = AttachToRemoteServer;
rp.closeMode = KillAtClose; rp.closeMode = KillAtClose;
createAndScheduleRun(rp, d->kit);
auto debugger = DebuggerRunTool::createFromKit(d->kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
} }
void GdbServerStarter::handleProcessClosed(int status) void GdbServerStarter::handleProcessClosed(int status)