From 74a96bd0a62904803c2499b9b5f7f95ec5430ccf Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 23 May 2017 16:40:49 +0200 Subject: [PATCH] ProjectExplorer: Fix debugger shut down Change-Id: Ic74470aedc6d5b9d70858e21a73df1bcdb48ac49 Reviewed-by: David Schulz --- src/plugins/debugger/debuggerruncontrol.cpp | 6 +-- .../projectexplorer/runconfiguration.cpp | 54 +++++++++++++------ .../projectexplorer/runconfiguration.h | 1 + 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 1a9fc9e6e60..d1f9210428a 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -153,14 +153,14 @@ void DebuggerRunTool::start() } } - appendMessage(tr("Debugging starts") + QLatin1Char('\n'), NormalMessageFormat); + appendMessage(tr("Debugging starts"), NormalMessageFormat); Internal::runControlStarted(this); engine->start(); } void DebuggerRunTool::startFailed() { - appendMessage(tr("Debugging has failed") + QLatin1Char('\n'), NormalMessageFormat); + appendMessage(tr("Debugging has failed"), NormalMessageFormat); m_engine->handleStartFailed(); } @@ -192,8 +192,8 @@ void DebuggerRunTool::onTargetFailure() void DebuggerRunTool::debuggingFinished() { - Internal::runControlFinished(this); appendMessage(tr("Debugging has finished"), NormalMessageFormat); + Internal::runControlFinished(this); reportStopped(); } diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 219cc5baff4..5e357f8d6ef 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -515,20 +515,20 @@ enum class RunWorkerState Initialized, Starting, Running, Stopping, Done, Failed }; -//static QString stateName(RunWorkerState s) -//{ -//# define SN(x) case x: return QLatin1String(#x); -// switch (s) { -// SN(RunWorkerState::Initialized) -// SN(RunWorkerState::Starting) -// SN(RunWorkerState::Running) -// SN(RunWorkerState::Stopping) -// SN(RunWorkerState::Done) -// SN(RunWorkerState::Failed) -// } -// return QLatin1String(""); -//# undef SN -//} +static QString stateName(RunWorkerState s) +{ +# define SN(x) case x: return QLatin1String(#x); + switch (s) { + SN(RunWorkerState::Initialized) + SN(RunWorkerState::Starting) + SN(RunWorkerState::Running) + SN(RunWorkerState::Stopping) + SN(RunWorkerState::Done) + SN(RunWorkerState::Failed) + } + return QLatin1String(""); +# undef SN +} class RunWorkerPrivate : public QObject { @@ -864,7 +864,22 @@ void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg) void RunControlPrivate::onWorkerStopped(RunWorker *worker) { - debugMessage(worker->displayName() + " stopped."); + switch (worker->d->state) { + case RunWorkerState::Running: + // That was a spontaneous stop. + worker->d->state = RunWorkerState::Done; + debugMessage(worker->displayName() + " stopped spontaneously."); + break; + case RunWorkerState::Stopping: + worker->d->state = RunWorkerState::Done; + debugMessage(worker->displayName() + " stopped expectedly."); + break; + default: + debugMessage(worker->displayName() + " stopped unexpectedly in state" + + stateName(worker->d->state)); + worker->d->state = RunWorkerState::Failed; + break; + } continueStop(); } @@ -1206,6 +1221,8 @@ void SimpleTargetRunner::start() this, &SimpleTargetRunner::onProcessStarted); connect(&m_launcher, &ApplicationLauncher::processExited, this, &SimpleTargetRunner::onProcessFinished); + connect(&m_launcher, &ApplicationLauncher::error, + this, &SimpleTargetRunner::onProcessError); QTC_ASSERT(r.is(), return); const QString executable = r.as().executable; @@ -1291,6 +1308,13 @@ void SimpleTargetRunner::onProcessFinished(int exitCode, QProcess::ExitStatus st reportStopped(); } +void SimpleTargetRunner::onProcessError(QProcess::ProcessError) +{ + QString msg = tr("%1 finished."); + appendMessage(msg.arg(runnable().displayName()), Utils::NormalMessageFormat); + reportStopped(); +} + void RunControl::reportFailure(const QString &msg) { d->showError(msg); diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 17f14e64577..3f25e8fc1fe 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -535,6 +535,7 @@ protected: private: void onProcessStarted(); void onProcessFinished(int exitCode, QProcess::ExitStatus status); + void onProcessError(QProcess::ProcessError error); ApplicationLauncher m_launcher; };