diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 2687d71be22..78d5b8db47f 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -58,6 +58,7 @@ #include #include +#include #include #include @@ -80,6 +81,98 @@ DebuggerEngine *createQmlEngine(bool useTerminal); DebuggerEngine *createQmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal); DebuggerEngine *createLldbEngine(); + +class LocalProcessRunner : public RunWorker +{ +public: + LocalProcessRunner(RunControl *runControl, const StandardRunnable &runnable) + : RunWorker(runControl), m_runnable(runnable) + { + connect(&m_proc, &QProcess::errorOccurred, + this, &LocalProcessRunner::handleError); + connect(&m_proc, &QProcess::readyReadStandardOutput, + this, &LocalProcessRunner::handleStandardOutput); + connect(&m_proc, &QProcess::readyReadStandardError, + this, &LocalProcessRunner::handleStandardError); + connect(&m_proc, static_cast(&QProcess::finished), + this, &LocalProcessRunner::handleFinished); + } + + void start() override + { + m_proc.setCommand(m_runnable.executable, m_runnable.commandLineArguments); + m_proc.start(); + } + + void stop() override + { + m_proc.terminate(); + } + + void handleStandardOutput() + { + const QByteArray ba = m_proc.readAllStandardOutput(); + const QString msg = QString::fromLocal8Bit(ba, ba.length()); + showMessage(msg, LogOutput); + showMessage(msg, AppOutput); + } + + void handleStandardError() + { + const QByteArray ba = m_proc.readAllStandardError(); + const QString msg = QString::fromLocal8Bit(ba, ba.length()); + showMessage(msg, LogOutput); + showMessage(msg, AppError); + } + + void handleFinished() + { + if (m_proc.exitStatus() == QProcess::NormalExit && m_proc.exitCode() == 0) { + // all good. + reportDone(); + } else { + reportFailure(tr("Upload failed: %1").arg(m_proc.errorString())); + } + } + + void handleError(QProcess::ProcessError error) + { + QString msg; + switch (error) { + case QProcess::FailedToStart: + msg = tr("The upload process failed to start. Shell missing?"); + break; + case QProcess::Crashed: + msg = tr("The upload process crashed some time after starting " + "successfully."); + break; + case QProcess::Timedout: + msg = tr("The last waitFor...() function timed out. " + "The state of QProcess is unchanged, and you can try calling " + "waitFor...() again."); + break; + case QProcess::WriteError: + msg = tr("An error occurred when attempting to write " + "to the upload process. For example, the process may not be running, " + "or it may have closed its input channel."); + break; + case QProcess::ReadError: + msg = tr("An error occurred when attempting to read from " + "the upload process. For example, the process may not be running."); + break; + default: + msg = tr("An unknown error in the upload process occurred. " + "This is the default return value of error()."); + } + + showMessage(msg, StatusBar); + Core::AsynchronousMessageBox::critical(tr("Error"), msg); + } + + StandardRunnable m_runnable; + Utils::QtcProcess m_proc; +}; + } // namespace Internal @@ -522,6 +615,15 @@ void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp) void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp) { m_runParameters = rp; + + if (!rp.serverStartScript.isEmpty()) { + // Provide script information about the environment + StandardRunnable serverStarter; + serverStarter.executable = rp.serverStartScript; + QtcProcess::addArg(&serverStarter.commandLineArguments, rp.inferior.executable); + QtcProcess::addArg(&serverStarter.commandLineArguments, rp.remoteChannel); + addStartDependency(new LocalProcessRunner(runControl(), serverStarter)); + } } void DebuggerRunTool::setupEngine() diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp index cf55a82dc6b..5184e4b7c4e 100644 --- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp +++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp @@ -31,8 +31,6 @@ #include #include -#include - #include #include #include @@ -58,13 +56,6 @@ namespace Internal { GdbRemoteServerEngine::GdbRemoteServerEngine(bool useTerminal) : GdbEngine(useTerminal) { - connect(&m_uploadProc, &QProcess::errorOccurred, this, &GdbRemoteServerEngine::uploadProcError); - connect(&m_uploadProc, &QProcess::readyReadStandardOutput, - this, &GdbRemoteServerEngine::readUploadStandardOutput); - connect(&m_uploadProc, &QProcess::readyReadStandardError, - this, &GdbRemoteServerEngine::readUploadStandardError); - connect(&m_uploadProc, static_cast(&QProcess::finished), - this, &GdbRemoteServerEngine::uploadProcFinished); } void GdbRemoteServerEngine::setupEngine() @@ -74,82 +65,10 @@ void GdbRemoteServerEngine::setupEngine() QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); showMessage("TRYING TO START ADAPTER"); - QString serverStartScript = runParameters().serverStartScript; - if (!serverStartScript.isEmpty()) { - - // Provide script information about the environment - QString arglist; - QtcProcess::addArg(&arglist, serverStartScript); - QtcProcess::addArg(&arglist, runParameters().inferior.executable); - QtcProcess::addArg(&arglist, runParameters().remoteChannel); - - m_uploadProc.start(arglist); - m_uploadProc.waitForStarted(); - m_uploadProc.waitForFinished(); - } startGdb(); } -void GdbRemoteServerEngine::uploadProcError(QProcess::ProcessError error) -{ - QString msg; - switch (error) { - case QProcess::FailedToStart: - msg = tr("The upload process failed to start. Shell missing?"); - break; - case QProcess::Crashed: - msg = tr("The upload process crashed some time after starting " - "successfully."); - break; - case QProcess::Timedout: - msg = tr("The last waitFor...() function timed out. " - "The state of QProcess is unchanged, and you can try calling " - "waitFor...() again."); - break; - case QProcess::WriteError: - msg = tr("An error occurred when attempting to write " - "to the upload process. For example, the process may not be running, " - "or it may have closed its input channel."); - break; - case QProcess::ReadError: - msg = tr("An error occurred when attempting to read from " - "the upload process. For example, the process may not be running."); - break; - default: - msg = tr("An unknown error in the upload process occurred. " - "This is the default return value of error()."); - } - - showMessage(msg, StatusBar); - Core::AsynchronousMessageBox::critical(tr("Error"), msg); -} - -void GdbRemoteServerEngine::readUploadStandardOutput() -{ - const QByteArray ba = m_uploadProc.readAllStandardOutput(); - const QString msg = QString::fromLocal8Bit(ba, ba.length()); - showMessage(msg, LogOutput); - showMessage(msg, AppOutput); -} - -void GdbRemoteServerEngine::readUploadStandardError() -{ - const QByteArray ba = m_uploadProc.readAllStandardError(); - const QString msg = QString::fromLocal8Bit(ba, ba.length()); - showMessage(msg, LogOutput); - showMessage(msg, AppError); -} - -void GdbRemoteServerEngine::uploadProcFinished() -{ - if (m_uploadProc.exitStatus() == QProcess::NormalExit && m_uploadProc.exitCode() == 0) { - // all good. - } else { - runTool()->reportFailure(tr("Upload failed: %1").arg(m_uploadProc.errorString())); - } -} - void GdbRemoteServerEngine::setupInferior() { QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state()); diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.h b/src/plugins/debugger/gdb/remotegdbserveradapter.h index 0f042b669a2..a72c3814f71 100644 --- a/src/plugins/debugger/gdb/remotegdbserveradapter.h +++ b/src/plugins/debugger/gdb/remotegdbserveradapter.h @@ -44,10 +44,6 @@ private: void interruptInferior2() override; void shutdownEngine() override; - void readUploadStandardOutput(); - void readUploadStandardError(); - void uploadProcError(QProcess::ProcessError error); - void uploadProcFinished(); void callTargetRemote(); void handleSetTargetAsync(const DebuggerResponse &response); @@ -60,8 +56,6 @@ private: void handleSetNtoExecutable(const DebuggerResponse &response); void handleInterruptInferior(const DebuggerResponse &response); void handleExecRun(const DebuggerResponse &response); - - QProcess m_uploadProc; }; } // namespace Internal