Commit 6e990f96 authored by hjk's avatar hjk

Debugger: Remove DebuggerRunControl

Use plain RunControl + DebuggerRunTool combo instead.

Change-Id: Ib71b5eab50da667b9d71dcc6689d2643ad8ecdee
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 6e275624
......@@ -138,28 +138,30 @@ RunControl *AndroidDebugSupport::createDebugRunControl(RunConfiguration *runConf
}
}
RunControl *runControl = createDebuggerRunControl(params, runConfig, errorMessage);
new AndroidDebugSupport(runControl);
auto runControl = new ProjectExplorer::RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new AndroidDebugSupport(runControl, params, errorMessage);
return runControl;
}
AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl)
: ToolRunner(runControl),
AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl,
const Debugger::DebuggerStartParameters &sp,
QString *errorMessage)
: DebuggerRunTool(runControl, sp, errorMessage),
m_runner(new AndroidRunner(this, runControl->runConfiguration(), runControl->runMode()))
{
connect(runControl, &RunControl::finished,
m_runner, &AndroidRunner::stop);
connect(this->runControl()->toolRunner(), &DebuggerRunTool::requestRemoteSetup,
connect(this, &DebuggerRunTool::requestRemoteSetup,
m_runner, &AndroidRunner::start);
// FIXME: Move signal to base class and generalize handling.
connect(this->runControl()->toolRunner(), &DebuggerRunTool::aboutToNotifyInferiorSetupOk,
connect(this, &DebuggerRunTool::aboutToNotifyInferiorSetupOk,
m_runner, &AndroidRunner::remoteDebuggerRunning);
connect(m_runner, &AndroidRunner::remoteServerRunning,
[this](const QByteArray &serverChannel, int pid) {
this->runControl()->toolRunner()->notifyEngineRemoteServerRunning(serverChannel, pid);
notifyEngineRemoteServerRunning(serverChannel, pid);
});
connect(m_runner, &AndroidRunner::remoteProcessStarted,
......@@ -173,12 +175,12 @@ AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl)
connect(m_runner, &AndroidRunner::remoteErrorOutput,
[this](const QString &output) {
this->runControl()->toolRunner()->showMessage(output, AppError);
showMessage(output, AppError);
});
connect(m_runner, &AndroidRunner::remoteOutput,
[this](const QString &output) {
this->runControl()->toolRunner()->showMessage(output, AppOutput);
showMessage(output, AppOutput);
});
QTC_ASSERT(runControl, return);
......@@ -200,12 +202,7 @@ void AndroidDebugSupport::handleRemoteProcessStarted(Utils::Port gdbServerPort,
result.success = true;
result.gdbServerPort = gdbServerPort;
result.qmlServerPort = qmlPort;
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
}
DebuggerRunControl *AndroidDebugSupport::runControl()
{
return qobject_cast<DebuggerRunControl *>(ToolRunner::runControl());
notifyEngineRemoteSetupFinished(result);
}
} // namespace Internal
......
......@@ -25,30 +25,29 @@
#pragma once
#include <projectexplorer/runconfiguration.h>
#include <debugger/debuggerruncontrol.h>
#include "androidrunconfiguration.h"
namespace Debugger { class DebuggerRunControl; }
namespace Android {
namespace Internal {
class AndroidRunner;
class AndroidDebugSupport : public ProjectExplorer::ToolRunner
class AndroidDebugSupport : public Debugger::DebuggerRunTool
{
Q_OBJECT
public:
explicit AndroidDebugSupport(ProjectExplorer::RunControl *runControl);
AndroidDebugSupport(ProjectExplorer::RunControl *runControl,
const Debugger::DebuggerStartParameters &sp,
QString *errorMessage);
static ProjectExplorer::RunControl *createDebugRunControl(ProjectExplorer::RunConfiguration *runConfig,
QString *errorMessage);
private:
void handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort);
Debugger::DebuggerRunControl *runControl();
AndroidRunner * const m_runner;
};
......
......@@ -336,8 +336,9 @@ void TestRunner::debugTests()
sp.displayName = config->displayName();
QString errorMessage;
auto runControl = Debugger::createDebuggerRunControl(sp, config->runConfiguration(),
&errorMessage);
auto runControl = new ProjectExplorer::RunControl(config->runConfiguration(),
ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new Debugger::DebuggerRunTool(runControl, sp, &errorMessage);
if (!runControl) {
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
......@@ -364,18 +365,18 @@ void TestRunner::debugTests()
if (useOutputProcessor) {
TestOutputReader *outputreader = config->outputReader(*futureInterface, 0);
connect(runControl, &Debugger::DebuggerRunControl::appendMessageRequested,
connect(runControl, &ProjectExplorer::RunControl::appendMessageRequested,
this, [this, outputreader]
(ProjectExplorer::RunControl *, const QString &msg, Utils::OutputFormat format) {
processOutput(outputreader, msg, format);
});
connect(runControl, &Debugger::DebuggerRunControl::finished,
connect(runControl, &ProjectExplorer::RunControl::finished,
outputreader, &QObject::deleteLater);
}
connect(this, &TestRunner::requestStopTestRun, runControl, &ProjectExplorer::RunControl::stop);
connect(runControl, &Debugger::DebuggerRunControl::finished, this, &TestRunner::onFinished);
connect(runControl, &ProjectExplorer::RunControl::finished, this, &TestRunner::onFinished);
ProjectExplorer::ProjectExplorerPlugin::startRunControl(runControl);
}
......
......@@ -42,11 +42,11 @@ using namespace ProjectExplorer;
namespace BareMetal {
namespace Internal {
BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl)
: ToolRunner(runControl)
BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl, const Debugger::DebuggerStartParameters &sp)
: Debugger::DebuggerRunTool(runControl, sp)
, m_appLauncher(new ProjectExplorer::ApplicationLauncher(this))
{
connect(this->runControl()->toolRunner(), &Debugger::DebuggerRunTool::requestRemoteSetup,
connect(this, &Debugger::DebuggerRunTool::requestRemoteSetup,
this, &BareMetalDebugSupport::remoteSetupRequested);
connect(runControl, &RunControl::finished,
this, &BareMetalDebugSupport::debuggingFinished);
......@@ -96,12 +96,12 @@ void BareMetalDebugSupport::appRunnerFinished(bool success)
if (m_state == Running) {
if (!success)
runControl()->toolRunner()->notifyInferiorIll();
notifyInferiorIll();
} else if (m_state == StartingRunner) {
Debugger::RemoteSetupResult result;
result.success = false;
result.reason = tr("Debugging failed.");
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
notifyEngineRemoteSetupFinished(result);
}
reset();
......@@ -116,7 +116,7 @@ void BareMetalDebugSupport::appRunnerError(const QString &error)
{
if (m_state == Running) {
showMessage(error, Debugger::AppError);
runControl()->toolRunner()->notifyInferiorIll();
notifyInferiorIll();
} else if (m_state != Inactive) {
adapterSetupFailed(error);
}
......@@ -127,7 +127,7 @@ void BareMetalDebugSupport::adapterSetupDone()
m_state = Running;
Debugger::RemoteSetupResult result;
result.success = true;
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
notifyEngineRemoteSetupFinished(result);
}
void BareMetalDebugSupport::adapterSetupFailed(const QString &error)
......@@ -137,7 +137,7 @@ void BareMetalDebugSupport::adapterSetupFailed(const QString &error)
Debugger::RemoteSetupResult result;
result.success = false;
result.reason = tr("Initial setup failed: %1").arg(error);
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
notifyEngineRemoteSetupFinished(result);
}
void BareMetalDebugSupport::startExecution()
......@@ -188,16 +188,5 @@ void BareMetalDebugSupport::reset()
m_state = Inactive;
}
void BareMetalDebugSupport::showMessage(const QString &msg, int channel)
{
if (m_state != Inactive)
runControl()->toolRunner()->showMessage(msg, channel);
}
Debugger::DebuggerRunControl *BareMetalDebugSupport::runControl()
{
return qobject_cast<Debugger::DebuggerRunControl *>(ToolRunner::runControl());
}
} // namespace Internal
} // namespace BareMetal
......@@ -25,21 +25,20 @@
#pragma once
#include <projectexplorer/runconfiguration.h>
namespace Debugger { class DebuggerRunControl; }
#include <debugger/debuggerruncontrol.h>
namespace ProjectExplorer { class ApplicationLauncher; }
namespace BareMetal {
namespace Internal {
class BareMetalDebugSupport : public ProjectExplorer::ToolRunner
class BareMetalDebugSupport : public Debugger::DebuggerRunTool
{
Q_OBJECT
public:
explicit BareMetalDebugSupport(ProjectExplorer::RunControl *runControl);
BareMetalDebugSupport(ProjectExplorer::RunControl *runControl,
const Debugger::DebuggerStartParameters &sp);
~BareMetalDebugSupport();
private:
......@@ -60,9 +59,6 @@ private:
void startExecution();
void setFinished();
void reset();
void showMessage(const QString &msg, int channel);
Debugger::DebuggerRunControl *runControl();
ProjectExplorer::ApplicationLauncher *m_appLauncher;
State m_state = Inactive;
......
......@@ -135,9 +135,8 @@ RunControl *BareMetalRunControlFactory::create(
if (p->startupMode() == GdbServerProvider::StartupOnNetwork)
sp.remoteSetupNeeded = true;
auto runControl = createDebuggerRunControl(sp, rc, errorMessage, mode);
if (runControl && sp.remoteSetupNeeded)
new BareMetalDebugSupport(runControl);
auto runControl = new RunControl(rc, mode);
new BareMetalDebugSupport(runControl, sp);
return runControl;
}
......
......@@ -199,7 +199,7 @@ public:
const DebuggerRunParameters &runParameters() const;
DebuggerRunParameters &runParameters();
void setRunTool(DebuggerRunTool *runTool);
virtual void setRunTool(DebuggerRunTool *runTool);
DebuggerRunTool *runTool() const;
void startDebugger();
......
......@@ -2127,7 +2127,7 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
rp.closeMode = DetachAtClose;
rp.toolChainAbi = rc->abi();
if (RunConfiguration *runConfig = rc->runConfiguration()) {
auto runControl = new DebuggerRunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new DebuggerRunTool(runControl, rp);
ProjectExplorerPlugin::startRunControl(runControl);
} else {
......@@ -3687,7 +3687,7 @@ void DebuggerUnitTests::testStateMachine()
rp.inferior = rc->runnable().as<StandardRunnable>();
rp.testCase = TestNoBoundsOfCurrentFunction;
auto runControl = new DebuggerRunControl(rc, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto runControl = new RunControl(rc, ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new DebuggerRunTool(runControl, rp);
ProjectExplorerPlugin::startRunControl(runControl);
......
......@@ -107,36 +107,7 @@ static QLatin1String engineTypeName(DebuggerEngineType et)
return QLatin1String("No engine");
}
/// DebuggerRunControl
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfig, Core::Id runMode)
: RunControl(runConfig, runMode)
{
setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
setPromptToStop([&](bool *optionalPrompt) {
const QString question = tr("A debugging session is still in progress. "
"Terminating the session in the current"
" state can leave the target in an inconsistent state."
" Would you still like to terminate it?");
bool result = showPromptToStopDialog(tr("Close Debugging Session"), question,
QString(), QString(), optionalPrompt);
if (result)
disconnect(this);
return result;
});
}
DebuggerRunControl::~DebuggerRunControl()
{
}
void DebuggerRunControl::start()
{
toolRunner()->startIt();
}
void DebuggerRunTool::startIt()
void DebuggerRunTool::start()
{
Debugger::Internal::saveModeToRestore();
Debugger::selectPerspective(Debugger::Constants::CppPerspectiveId);
......@@ -209,22 +180,11 @@ void DebuggerRunTool::notifyEngineRemoteSetupFinished(const RemoteSetupResult &r
m_engine->notifyEngineRemoteSetupFinished(result);
}
void DebuggerRunControl::stop()
{
m_debuggerTool->stopIt();
}
void DebuggerRunTool::stopIt()
void DebuggerRunTool::stop()
{
m_engine->quitDebugger();
}
DebuggerRunTool *DebuggerRunControl::toolRunner() const
{
// return qobject_cast<DebuggerRunTool *>(RunControl::toolRunner());
return m_debuggerTool;
}
void DebuggerRunTool::debuggingFinished()
{
runControl()->reportApplicationStop();
......@@ -519,13 +479,25 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartPara
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp, QString *errorMessage)
: ToolRunner(runControl)
{
this->runControl()->m_debuggerTool = this; // FIXME: Remove.
DebuggerRunParameters m_rp = rp;
runControl->setDisplayName(m_rp.displayName);
// QML and/or mixed are not prepared for it.
runControl->setSupportsReRunning(!(m_rp.languages & QmlLanguage));
runControl->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
runControl->setPromptToStop([&](bool *optionalPrompt) {
const QString question = tr("A debugging session is still in progress. "
"Terminating the session in the current"
" state can leave the target in an inconsistent state."
" Would you still like to terminate it?");
bool result = runControl->showPromptToStopDialog(tr("Close Debugging Session"),
question, QString(), QString(), optionalPrompt);
if (result)
disconnect(this);
return result;
});
if (Internal::fixupParameters(m_rp, runControl, m_errors)) {
m_engine = createEngine(m_rp.masterEngineType, m_rp, &m_errors);
if (!m_engine) {
......@@ -567,11 +539,6 @@ void DebuggerRunTool::handleFinished()
runControlFinished(m_engine);
}
DebuggerRunControl *DebuggerRunTool::runControl() const
{
return static_cast<DebuggerRunControl *>(ToolRunner::runControl());
}
void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout)
{
if (channel == ConsoleOutput)
......@@ -610,7 +577,7 @@ public:
QTC_ASSERT(runConfig, return 0);
QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0);
auto runControl = new DebuggerRunControl(runConfig, mode);
auto runControl = new RunControl(runConfig, mode);
(void) new DebuggerRunTool(runControl, DebuggerStartParameters(), errorMessage);
return runControl;
}
......@@ -679,7 +646,7 @@ RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, Kit *kit)
{
RunConfiguration *runConfig = dummyRunConfigForKit(kit);
QTC_ASSERT(runConfig, return nullptr);
auto runControl = new DebuggerRunControl(runConfig, DebugRunMode);
auto runControl = new RunControl(runConfig, DebugRunMode);
(void) new DebuggerRunTool(runControl, rp);
QTC_ASSERT(runControl, return nullptr);
ProjectExplorerPlugin::startRunControl(runControl);
......@@ -687,20 +654,4 @@ RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, Kit *kit)
}
} // Internal
/**
* Main entry point for target plugins.
*/
RunControl *createDebuggerRunControl(const DebuggerStartParameters &sp,
RunConfiguration *runConfig,
QString *errorMessage,
Core::Id runMode)
{
QTC_ASSERT(runConfig, return nullptr);
auto runControl = new DebuggerRunControl(runConfig, runMode);
(void) new DebuggerRunTool(runControl, sp, errorMessage);
return runControl;
}
} // namespace Debugger
......@@ -35,13 +35,6 @@ namespace Debugger {
class RemoteSetupResult;
class DebuggerStartParameters;
class DebuggerRunControl;
DEBUGGER_EXPORT ProjectExplorer::RunControl *
createDebuggerRunControl(const DebuggerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfig,
QString *errorMessage,
Core::Id runMode = ProjectExplorer::Constants::DEBUG_RUN_MODE);
class DEBUGGER_EXPORT DebuggerRunTool : public ProjectExplorer::ToolRunner
{
......@@ -57,12 +50,11 @@ public:
~DebuggerRunTool();
Internal::DebuggerEngine *engine() const { return m_engine; }
DebuggerRunControl *runControl() const;
void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1);
void startIt();
void stopIt();
void start() override;
void stop() override;
void handleFinished();
......@@ -87,21 +79,4 @@ private:
QStringList m_errors;
};
class DEBUGGER_EXPORT DebuggerRunControl : public ProjectExplorer::RunControl
{
Q_OBJECT
public:
DebuggerRunControl(ProjectExplorer::RunConfiguration *runConfig, Core::Id runMode);
~DebuggerRunControl() override;
void start() override;
void stop() override; // Called from SnapshotWindow.
DebuggerRunTool *toolRunner() const;
public:
DebuggerRunTool *m_debuggerTool = nullptr;
};
} // namespace Debugger
......@@ -3331,7 +3331,7 @@ void GdbEngine::handleMakeSnapshot(const DebuggerResponse &response, const QStri
}
rp.displayName = function + ": " + QDateTime::currentDateTime().toString();
rp.isSnapshot = true;
auto rc = new DebuggerRunControl(runControl()->runConfiguration(), ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto rc = new RunControl(runControl()->runConfiguration(), ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new DebuggerRunTool(rc, rp);
ProjectExplorerPlugin::startRunControl(rc);
} else {
......
......@@ -335,10 +335,6 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
connect(d->msgClient, &QDebugMessageClient::message,
this, &appendDebugOutput);
d->startupMessageFilterConnection = connect(
runControl(), &RunControl::appendMessageRequested,
d, &QmlEnginePrivate::filterApplicationMessage);
}
QmlEngine::~QmlEngine()
......@@ -356,6 +352,15 @@ QmlEngine::~QmlEngine()
delete d;
}
void QmlEngine::setRunTool(DebuggerRunTool *runTool)
{
DebuggerEngine::setRunTool(runTool);
d->startupMessageFilterConnection = connect(
runTool->runControl(), &RunControl::appendMessageRequested,
d, &QmlEnginePrivate::filterApplicationMessage);
}
void QmlEngine::setupInferior()
{
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
......
......@@ -47,6 +47,8 @@ public:
DebuggerEngine *masterEngine = nullptr);
~QmlEngine() override;
void setRunTool(DebuggerRunTool *runTool) override;
void logServiceStateChange(const QString &service, float version,
QmlDebug::QmlDebugClient::State newState);
void logServiceActivity(const QString &service, const QString &logMessage);
......
......@@ -155,18 +155,18 @@ RunControl *IosDebugSupport::createDebugRunControl(RunConfiguration *runConfig,
params.startMode = AttachToRemoteServer;
}
RunControl *runControl = createDebuggerRunControl(params, runConfig, errorMessage);
if (runControl)
new IosDebugSupport(runControl, cppDebug, qmlDebug);
Q_UNUSED(errorMessage); // FIXME
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
(void) new IosDebugSupport(runControl, params, cppDebug, qmlDebug);
return runControl;
}
IosDebugSupport::IosDebugSupport(RunControl *runControl, bool cppDebug, bool qmlDebug)
: ToolRunner(runControl),
IosDebugSupport::IosDebugSupport(RunControl *runControl, const DebuggerStartParameters &sp, bool cppDebug, bool qmlDebug)
: Debugger::DebuggerRunTool(runControl, sp),
m_runner(new IosRunner(this, runControl, cppDebug,
qmlDebug ? QmlDebug::QmlDebuggerServices : QmlDebug::NoQmlDebugServices))
{
connect(this->runControl()->toolRunner(), &DebuggerRunTool::requestRemoteSetup,
connect(this, &Debugger::DebuggerRunTool::requestRemoteSetup,
m_runner, &IosRunner::start);
connect(runControl, &RunControl::finished,
m_runner, &IosRunner::stop);
......@@ -193,7 +193,7 @@ void IosDebugSupport::handleServerPorts(Utils::Port gdbServerPort, Utils::Port q
|| (m_runner && !m_runner->cppDebug() && qmlPort.isValid());
if (!result.success)
result.reason = tr("Could not get debug server file descriptor.");
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
notifyEngineRemoteSetupFinished(result);
}
void IosDebugSupport::handleGotInferiorPid(qint64 pid, Utils::Port qmlPort)
......@@ -204,7 +204,7 @@ void IosDebugSupport::handleGotInferiorPid(qint64 pid, Utils::Port qmlPort)
result.success = pid > 0;
if (!result.success)
result.reason = tr("Got an invalid process id.");
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
notifyEngineRemoteSetupFinished(result);
}
void IosDebugSupport::handleRemoteProcessFinished(bool cleanEnd)
......@@ -213,22 +213,17 @@ void IosDebugSupport::handleRemoteProcessFinished(bool cleanEnd)
appendMessage(tr("Run ended with error."), Utils::DebugFormat);
else
appendMessage(tr("Run ended."), Utils::DebugFormat);
runControl()->toolRunner()->abortDebugger();
abortDebugger();
}
void IosDebugSupport::handleRemoteOutput(const QString &output)
{
runControl()->toolRunner()->showMessage(output, AppOutput);
showMessage(output, AppOutput);
}
void IosDebugSupport::handleRemoteErrorOutput(const QString &output)
{
runControl()->toolRunner()->showMessage(output, AppError);
}
DebuggerRunControl *IosDebugSupport::runControl()
{
return qobject_cast<DebuggerRunControl *>(ToolRunner::runControl()) ;
showMessage(output, AppError);
}
} // namespace Internal
......
......@@ -27,10 +27,7 @@
#include "iosrunconfiguration.h"
#include <projectexplorer/runconfiguration.h>
namespace Debugger { class DebuggerRunControl; }
namespace ProjectExplorer { class RunControl; }
#include <debugger/debuggerruncontrol.h>
namespace Ios {
namespace Internal {
......@@ -38,7 +35,7 @@ namespace Internal {
class IosRunConfiguration;
class IosRunner;
class IosDebugSupport : public ProjectExplorer::ToolRunner
class IosDebugSupport : public Debugger::DebuggerRunTool
{
Q_OBJECT
......@@ -46,7 +43,9 @@ public:
static ProjectExplorer::RunControl *createDebugRunControl(ProjectExplorer::RunConfiguration *runConfig,
QString *errorMessage);
IosDebugSupport(ProjectExplorer::RunControl *runControl, bool cppDebug, bool qmlDebug);
IosDebugSupport(ProjectExplorer::RunControl *runControl,
const Debugger::DebuggerStartParameters &sp,
<