diff --git a/src/plugins/boot2qt/qdbdevice.cpp b/src/plugins/boot2qt/qdbdevice.cpp index 2d69e4ce415..269383f7bdb 100644 --- a/src/plugins/boot2qt/qdbdevice.cpp +++ b/src/plugins/boot2qt/qdbdevice.cpp @@ -83,7 +83,7 @@ public: &DeviceApplicationObserver::handleAppendMessage); connect(&m_appRunner, &ApplicationLauncher::error, this, [this] { m_error = m_appRunner.errorString(); }); - connect(&m_appRunner, &ApplicationLauncher::processExited, this, + connect(&m_appRunner, &ApplicationLauncher::finished, this, &DeviceApplicationObserver::handleFinished); QTC_ASSERT(device, return); @@ -106,13 +106,15 @@ private: m_stderr += data; } - void handleFinished(int exitCode, QProcess::ExitStatus exitStatus) + void handleFinished() { - Q_UNUSED(exitCode) // FIXME: Needed in a post-adb world? // adb does not forward exit codes and all stderr goes to stdout. - const bool failure = exitStatus == QProcess::CrashExit || m_stdout.contains("fail") - || m_stdout.contains("error") || m_stdout.contains("not found"); + const bool failure = m_appRunner.exitStatus() == QProcess::CrashExit + || m_stdout.contains("fail") + || m_stdout.contains("error") + || m_stdout.contains("not found"); + if (failure) { QString errorString; if (!m_error.isEmpty()) { diff --git a/src/plugins/boot2qt/qdbdevicedebugsupport.cpp b/src/plugins/boot2qt/qdbdevicedebugsupport.cpp index 91b334a442e..ef493fd0738 100644 --- a/src/plugins/boot2qt/qdbdevicedebugsupport.cpp +++ b/src/plugins/boot2qt/qdbdevicedebugsupport.cpp @@ -57,7 +57,7 @@ public: connect(&m_launcher, &ApplicationLauncher::processStarted, this, &RunWorker::reportStarted); - connect(&m_launcher, &ApplicationLauncher::processExited, + connect(&m_launcher, &ApplicationLauncher::finished, this, &RunWorker::reportStopped); connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); diff --git a/src/plugins/boot2qt/qdbstopapplicationservice.cpp b/src/plugins/boot2qt/qdbstopapplicationservice.cpp index 9094f213d50..192a8c542c0 100644 --- a/src/plugins/boot2qt/qdbstopapplicationservice.cpp +++ b/src/plugins/boot2qt/qdbstopapplicationservice.cpp @@ -57,11 +57,10 @@ QdbStopApplicationService::~QdbStopApplicationService() delete d; } -void QdbStopApplicationService::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) +void QdbStopApplicationService::handleProcessFinished() { - Q_UNUSED(exitCode) - const auto failureMessage = tr("Could not check and possibly stop running application."); - if (exitStatus == QProcess::CrashExit) { + const QString failureMessage = tr("Could not check and possibly stop running application."); + if (d->applicationLauncher.exitStatus() == QProcess::CrashExit) { emit errorMessage(failureMessage); stopDeployment(); return; @@ -91,7 +90,7 @@ void QdbStopApplicationService::doDeploy() { connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::error, this, [this] { emit stdErrData(d->applicationLauncher.errorString()); }); - connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::processExited, + connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished, this, &QdbStopApplicationService::handleProcessFinished); connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage, this, &QdbStopApplicationService::handleAppendMessage); diff --git a/src/plugins/boot2qt/qdbstopapplicationservice.h b/src/plugins/boot2qt/qdbstopapplicationservice.h index f9b35681823..3db114a3188 100644 --- a/src/plugins/boot2qt/qdbstopapplicationservice.h +++ b/src/plugins/boot2qt/qdbstopapplicationservice.h @@ -28,8 +28,6 @@ #include #include -#include - namespace Qdb { namespace Internal { @@ -43,7 +41,7 @@ public: ~QdbStopApplicationService(); private: - void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); + void handleProcessFinished(); void handleAppendMessage(const QString &message, Utils::OutputFormat format); bool isDeploymentNecessary() const final { return true; } diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index 9952b37ad00..35217779b39 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -269,7 +269,7 @@ QmlEngine::QmlEngine() connect(stackHandler(), &StackHandler::currentIndexChanged, this, &QmlEngine::updateCurrentContext); - connect(&d->applicationLauncher, &ApplicationLauncher::processExited, + connect(&d->applicationLauncher, &ApplicationLauncher::finished, this, &QmlEngine::disconnected); connect(&d->applicationLauncher, &ApplicationLauncher::appendMessage, this, &QmlEngine::appMessage); @@ -515,7 +515,7 @@ void QmlEngine::startApplicationLauncher() void QmlEngine::stopApplicationLauncher() { if (d->applicationLauncher.isRunning()) { - disconnect(&d->applicationLauncher, &ApplicationLauncher::processExited, + disconnect(&d->applicationLauncher, &ApplicationLauncher::finished, this, &QmlEngine::disconnected); d->applicationLauncher.stop(); } diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index cae0167ef18..a57c7147e1a 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -116,11 +116,13 @@ public: // Remote QString m_remoteErrorString; QProcess::ProcessError m_remoteError = QProcess::UnknownError; - QProcess::ExitStatus m_remoteExitStatus = QProcess::CrashExit; State m_state = Inactive; bool m_stopRequested = false; Runnable m_runnable; + + int m_exitCode = 0; + QProcess::ExitStatus m_exitStatus = QProcess::NormalExit; }; } // Internal @@ -188,7 +190,7 @@ void ApplicationLauncherPrivate::stop() if (m_stopRequested) return; m_stopRequested = true; - m_remoteExitStatus = QProcess::CrashExit; + m_exitStatus = QProcess::CrashExit; emit q->appendMessage(ApplicationLauncher::tr("User requested stop. Shutting down..."), Utils::NormalMessageFormat); switch (m_state) { @@ -252,17 +254,17 @@ void ApplicationLauncherPrivate::localProcessError(QProcess::ProcessError error) emit q->appendMessage(m_process->errorString(), ErrorMessageFormat); if (m_processRunning && m_process->processId() == 0) { m_processRunning = false; - emit q->processExited(-1, QProcess::NormalExit); + m_exitCode = -1; + emit q->finished(); } } else { QString error; - QProcess::ExitStatus status = QProcess::NormalExit; switch (m_process->error()) { case QProcess::FailedToStart: error = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?"); break; case QProcess::Crashed: - status = QProcess::CrashExit; + m_exitStatus = QProcess::CrashExit; break; default: error = ApplicationLauncher::tr("Some error has occurred while running the program."); @@ -271,7 +273,8 @@ void ApplicationLauncherPrivate::localProcessError(QProcess::ProcessError error) emit q->appendMessage(error, ErrorMessageFormat); if (m_processRunning && !isRunning()) { m_processRunning = false; - emit q->processExited(-1, status); + m_exitCode = -1; + emit q->finished(); } } emit q->error(error); @@ -311,7 +314,9 @@ void ApplicationLauncherPrivate::localProcessDone(int exitCode, QProcess::ExitSt { QTimer::singleShot(100, this, [this, exitCode, status]() { m_listeningPid = 0; - emit q->processExited(exitCode, status); + m_exitCode = exitCode; + m_exitStatus = status; + emit q->finished(); }); } @@ -340,6 +345,9 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc { m_isLocal = local; + m_exitCode = 0; + m_exitStatus = QProcess::NormalExit; + if (m_isLocal) { m_process.reset(new QtcProcess(this)); m_process->setProcessChannelMode(m_processChannelMode); @@ -411,7 +419,6 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc } m_stopRequested = false; - m_remoteExitStatus = QProcess::NormalExit; m_process.reset(device->createProcess(this)); connect(m_process.get(), &QtcProcess::started, @@ -448,12 +455,10 @@ void ApplicationLauncherPrivate::setFinished() if (m_state == Inactive) return; - int exitCode = 0; - if (m_process) - exitCode = m_process->exitCode(); + m_exitCode = m_process ? m_exitCode = m_process->exitCode() : 0; m_state = Inactive; - emit q->processExited(exitCode, m_remoteExitStatus); + emit q->finished(); } void ApplicationLauncherPrivate::handleApplicationFinished() @@ -483,7 +488,7 @@ void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess: { m_remoteErrorString = message; m_remoteError = error; - m_remoteExitStatus = QProcess::CrashExit; + m_exitStatus = QProcess::CrashExit; emit q->error(error); } diff --git a/src/plugins/projectexplorer/applicationlauncher.h b/src/plugins/projectexplorer/applicationlauncher.h index 1582d5906ce..c5272eba5bd 100644 --- a/src/plugins/projectexplorer/applicationlauncher.h +++ b/src/plugins/projectexplorer/applicationlauncher.h @@ -69,10 +69,13 @@ public: static QString msgWinCannotRetrieveDebuggingOutput(); + int exitCode() const; + QProcess::ExitStatus exitStatus() const; + signals: void appendMessage(const QString &message, Utils::OutputFormat format, bool appendNewLine = true); void processStarted(); - void processExited(int exitCode, QProcess::ExitStatus exitStatus); + void finished(); void error(QProcess::ProcessError error); private: diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 884e53a8cd9..2567e9ce63f 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1202,16 +1202,14 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP m_launcher.setUseTerminal(m_useTerminal); m_launcher.setRunAsRoot(m_runAsRoot); - const bool isDesktop = device.isNull() || device.dynamicCast(); const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput()); appendMessage(msg, Utils::NormalMessageFormat); - connect(&m_launcher, &ApplicationLauncher::processExited, - this, [this, runnable](int exitCode, QProcess::ExitStatus status) { + connect(&m_launcher, &ApplicationLauncher::finished, this, [this, runnable]() { if (m_stopReported) return; - const QString msg = (status == QProcess::CrashExit) - ? tr("%1 crashed.") : tr("%2 exited with code %1").arg(exitCode); + const QString msg = (m_launcher.exitStatus() == QProcess::CrashExit) + ? tr("%1 crashed.") : tr("%2 exited with code %1").arg(m_launcher.exitCode()); const QString displayName = runnable.command.executable().toUserOutput(); appendMessage(msg.arg(displayName), Utils::NormalMessageFormat); m_stopReported = true; @@ -1233,6 +1231,7 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); + const bool isDesktop = device.isNull() || device.dynamicCast(); if (isDesktop) { connect(&m_launcher, &ApplicationLauncher::processStarted, this, [this] { // Console processes only know their pid after being started diff --git a/src/plugins/valgrind/callgrind/callgrindcontroller.cpp b/src/plugins/valgrind/callgrind/callgrindcontroller.cpp index 263d58d2357..eaab4ce0376 100644 --- a/src/plugins/valgrind/callgrind/callgrindcontroller.cpp +++ b/src/plugins/valgrind/callgrind/callgrindcontroller.cpp @@ -117,7 +117,7 @@ void CallgrindController::run(Option option) #if CALLGRIND_CONTROL_DEBUG m_controllerProcess->setProcessChannelMode(QProcess::ForwardedChannels); #endif - connect(m_controllerProcess, &ApplicationLauncher::processExited, + connect(m_controllerProcess, &ApplicationLauncher::finished, this, &CallgrindController::controllerProcessFinished); connect(m_controllerProcess, &ApplicationLauncher::error, this, &CallgrindController::handleControllerProcessError); @@ -149,7 +149,7 @@ void CallgrindController::handleControllerProcessError(QProcess::ProcessError) m_controllerProcess = nullptr; } -void CallgrindController::controllerProcessFinished(int rc, QProcess::ExitStatus status) +void CallgrindController::controllerProcessFinished() { QTC_ASSERT(m_controllerProcess, return); const QString error = m_controllerProcess->errorString(); @@ -157,7 +157,7 @@ void CallgrindController::controllerProcessFinished(int rc, QProcess::ExitStatus m_controllerProcess->deleteLater(); // Called directly from finished() signal in m_process m_controllerProcess = nullptr; - if (rc != 0 || status != QProcess::NormalExit) { + if (m_controllerProcess->exitCode() != 0 || m_controllerProcess->exitStatus() != QProcess::NormalExit) { qWarning() << "Controller exited abnormally:" << error; return; } diff --git a/src/plugins/valgrind/callgrind/callgrindcontroller.h b/src/plugins/valgrind/callgrind/callgrindcontroller.h index 848c2ba2b62..6f0b7af2716 100644 --- a/src/plugins/valgrind/callgrind/callgrindcontroller.h +++ b/src/plugins/valgrind/callgrind/callgrindcontroller.h @@ -76,7 +76,7 @@ private: void sftpJobFinished(QSsh::SftpJobId job, const QString &error); void cleanupTempFile(); - void controllerProcessFinished(int, QProcess::ExitStatus); + void controllerProcessFinished(); void controllerProcessError(QProcess::ProcessError); ProjectExplorer::ApplicationLauncher *m_controllerProcess = nullptr; diff --git a/src/plugins/valgrind/valgrindrunner.cpp b/src/plugins/valgrind/valgrindrunner.cpp index bfa59ab6202..d91c01847ed 100644 --- a/src/plugins/valgrind/valgrindrunner.cpp +++ b/src/plugins/valgrind/valgrindrunner.cpp @@ -114,7 +114,7 @@ bool ValgrindRunner::Private::run() // consider appending our options last so they override any interfering user-supplied options // -q as suggested by valgrind manual - connect(&m_valgrindProcess, &ApplicationLauncher::processExited, + connect(&m_valgrindProcess, &ApplicationLauncher::finished, q, &ValgrindRunner::processFinished); connect(&m_valgrindProcess, &ApplicationLauncher::processStarted, this, &ValgrindRunner::Private::processStarted); @@ -295,7 +295,7 @@ void ValgrindRunner::processError(QProcess::ProcessError e) emit finished(); } -void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status) +void ValgrindRunner::processFinished() { emit extraProcessFinished(); @@ -307,7 +307,7 @@ void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status) // make sure we don't wait for the connection anymore emit finished(); - if (ret != 0 || status == QProcess::CrashExit) + if (d->m_valgrindProcess.exitCode() != 0 || d->m_valgrindProcess.exitStatus() == QProcess::CrashExit) emit processErrorReceived(errorString(), d->m_valgrindProcess.processError()); } diff --git a/src/plugins/valgrind/valgrindrunner.h b/src/plugins/valgrind/valgrindrunner.h index 647cac8bae8..1e2e83fd464 100644 --- a/src/plugins/valgrind/valgrindrunner.h +++ b/src/plugins/valgrind/valgrindrunner.h @@ -72,7 +72,7 @@ signals: private: bool startServers(); void processError(QProcess::ProcessError); - void processFinished(int, QProcess::ExitStatus); + void processFinished(); void xmlSocketConnected(); void logSocketConnected();