From 6f0a600bcf7647493f8044f7d5d18d698e8c2fdc Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 7 Jul 2017 17:20:16 +0200 Subject: [PATCH] Debugger: Streamline error string handling Let the workers keep track of errors instead of passing around string pointers in some but not all interesting places. Change-Id: I3956bc947a50747dd3a0c9302b9f9873d192e9c6 Reviewed-by: Christian Stenger Reviewed-by: David Schulz --- src/plugins/autotest/testrunner.cpp | 2 +- src/plugins/debugger/debuggerruncontrol.cpp | 21 +++++------ src/plugins/debugger/debuggerruncontrol.h | 12 +++---- .../projectexplorer/runconfiguration.cpp | 7 +++- .../projectexplorer/runconfiguration.h | 1 + src/plugins/qnx/qnxattachdebugsupport.cpp | 13 +------ src/plugins/winrt/winrtdebugsupport.cpp | 35 ++++++++++--------- src/plugins/winrt/winrtdebugsupport.h | 4 +-- src/plugins/winrt/winrtrunfactories.cpp | 11 ++---- 9 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index ee188ff647..df6ce4206d 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -347,7 +347,7 @@ void TestRunner::debugTests() return; } - (void) new Debugger::DebuggerRunTool(runControl, sp, &errorMessage); + (void) new Debugger::DebuggerRunTool(runControl, sp); bool useOutputProcessor = true; if (ProjectExplorer::Target *targ = config->project()->activeTarget()) { diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 8aa0933bee..fd5f944c9f 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -506,26 +506,25 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl) }); } -DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp, QString *errorMessage) +DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp) : DebuggerRunTool(runControl) { - setStartParameters(sp, errorMessage); + setStartParameters(sp); } -DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp, QString *errorMessage) +DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp) : DebuggerRunTool(runControl) { - setRunParameters(rp, errorMessage); + setRunParameters(rp); } -void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp, QString *errorMessage) +void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp) { - setRunParameters(sp, errorMessage); + setRunParameters(sp); } -void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString *errorMessage) +void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp) { - Q_UNUSED(errorMessage); m_runParameters = rp; } @@ -618,15 +617,13 @@ public: : IRunControlFactory(parent) {} - RunControl *create(RunConfiguration *runConfig, - Core::Id mode, QString *errorMessage) override + RunControl *create(RunConfiguration *runConfig, Core::Id mode, QString *) override { QTC_ASSERT(runConfig, return 0); QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0); - DebuggerStartParameters sp; auto runControl = new RunControl(runConfig, mode); - (void) new DebuggerRunTool(runControl, sp, errorMessage); + (void) new DebuggerRunTool(runControl); return runControl; } diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h index 20c28dce64..71a72f25b3 100644 --- a/src/plugins/debugger/debuggerruncontrol.h +++ b/src/plugins/debugger/debuggerruncontrol.h @@ -44,17 +44,13 @@ public: DebuggerRunTool(ProjectExplorer::RunControl *runControl); // Use. DebuggerRunTool(ProjectExplorer::RunControl *runControl, - const DebuggerStartParameters &sp, - QString *errorMessage = nullptr); // Use rarely. + const DebuggerStartParameters &sp); // Use rarely. DebuggerRunTool(ProjectExplorer::RunControl *runControl, - const Internal::DebuggerRunParameters &rp, - QString *errorMessage = nullptr); // FIXME: Don't use. + const Internal::DebuggerRunParameters &rp); // FIXME: Don't use. ~DebuggerRunTool(); - void setStartParameters(const DebuggerStartParameters &sp, - QString *errorMessage = nullptr); // Use rarely. - void setRunParameters(const Internal::DebuggerRunParameters &rp, - QString *errorMessage = nullptr); // FIXME: Don't use. + void setStartParameters(const DebuggerStartParameters &sp); // Use rarely. + void setRunParameters(const Internal::DebuggerRunParameters &rp); // FIXME: Don't use. Internal::DebuggerEngine *engine() const { return m_engine; } Internal::DebuggerEngine *activeEngine() const; diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index ab597a98fb..75df5b6ff6 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -1547,7 +1547,12 @@ void RunWorker::setSupportsReRunning(bool reRunningSupported) bool RunWorker::supportsReRunning() const { - return d->supportsReRunning; + return d->supportsReRunning; +} + +bool RunWorker::hasFailed() const +{ + return d->state == RunWorkerState::Failed; } QString RunWorker::userMessageForProcessError(QProcess::ProcessError error, const QString &program) diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 31c0e88692..b7a69ca2eb 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -361,6 +361,7 @@ public: void reportFailure(const QString &msg = QString()); void setSupportsReRunning(bool reRunningSupported); bool supportsReRunning() const; + bool hasFailed() const; static QString userMessageForProcessError(QProcess::ProcessError, const QString &programName); diff --git a/src/plugins/qnx/qnxattachdebugsupport.cpp b/src/plugins/qnx/qnxattachdebugsupport.cpp index 6cbe3594fd..16ef27610d 100644 --- a/src/plugins/qnx/qnxattachdebugsupport.cpp +++ b/src/plugins/qnx/qnxattachdebugsupport.cpp @@ -131,18 +131,7 @@ void QnxAttachDebugSupport::attachToProcess() sp.solibSearchPath = QnxUtils::searchPaths(qtVersion); auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE); - if (!runControl) { - handleError(tr("Attaching failed.")); - stopPDebug(); - return; - } - QString errorMessage; - (void) new Debugger::DebuggerRunTool(runControl, sp, &errorMessage); - if (!errorMessage.isEmpty()) { - handleError(errorMessage); - stopPDebug(); - return; - } + (void) new Debugger::DebuggerRunTool(runControl, sp); // connect(qobject_cast(runControl->toolRunner()), // &Debugger::DebuggerRunTool::stateChanged, // this, &QnxAttachDebugSupport::handleDebuggerStateChanged); diff --git a/src/plugins/winrt/winrtdebugsupport.cpp b/src/plugins/winrt/winrtdebugsupport.cpp index 352ac3f3f9..7499200df1 100644 --- a/src/plugins/winrt/winrtdebugsupport.cpp +++ b/src/plugins/winrt/winrtdebugsupport.cpp @@ -45,7 +45,7 @@ using namespace ProjectExplorer; namespace WinRt { namespace Internal { -WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessage) +WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl) : DebuggerRunTool(runControl) { // FIXME: This is just working for local debugging; @@ -57,35 +57,38 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa QFileInfo debuggerHelper(QCoreApplication::applicationDirPath() + QLatin1String("/winrtdebughelper.exe")); if (!debuggerHelper.isExecutable()) { - *errorMessage = tr("The WinRT debugging helper is missing from your Qt Creator " - "installation. It was assumed to be located at %1").arg( - debuggerHelper.absoluteFilePath()); + reportFailure(tr("The WinRT debugging helper is missing from your Qt Creator " + "installation. It was assumed to be located at %1").arg( + debuggerHelper.absoluteFilePath())); return; } if (isQmlDebugging()) { Utils::Port qmlDebugPort; - if (!getFreePort(qmlDebugPort, errorMessage)) + if (!getFreePort(qmlDebugPort)) return; params.qmlServer.host = QHostAddress(QHostAddress::LocalHost).toString(); params.qmlServer.port = qmlDebugPort; } - m_runner = new WinRtRunnerHelper(this, errorMessage); - if (!errorMessage->isEmpty()) + QString errorMessage; + m_runner = new WinRtRunnerHelper(this, &errorMessage); + if (!errorMessage.isEmpty()) { + reportFailure(errorMessage); return; + } QLocalServer server; server.listen(QLatin1String("QtCreatorWinRtDebugPIDPipe")); m_runner->debug(debuggerHelper.absoluteFilePath()); if (!m_runner->waitForStarted()) { - *errorMessage = tr("Cannot start the WinRT Runner Tool."); + reportFailure(tr("Cannot start the WinRT Runner Tool.")); return; } if (!server.waitForNewConnection(10000)) { - *errorMessage = tr("Cannot establish connection to the WinRT debugging helper."); + reportFailure(tr("Cannot establish connection to the WinRT debugging helper.")); return; } @@ -98,12 +101,12 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa bool ok =false; params.attachPID = Utils::ProcessHandle(arg.last().toInt(&ok)); if (!ok) { - *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. " - "(output: %1)").arg(QString::fromLocal8Bit(output)); + reportFailure(tr("Cannot extract the PID from the WinRT debugging helper. " + "(output: %1)").arg(QString::fromLocal8Bit(output))); return; } server.close(); - setStartParameters(params, errorMessage); + setStartParameters(params); return; } } @@ -111,16 +114,16 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa server.close(); - *errorMessage = tr("Cannot create an appropriate run control for " - "the current run configuration."); + reportFailure(tr("Cannot create an appropriate run control for " + "the current run configuration.")); } -bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage) +bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort) { QTcpServer server; if (!server.listen(QHostAddress::LocalHost, qmlDebuggerPort.isValid() ? qmlDebuggerPort.number() : 0)) { - *errorMessage = tr("Not enough free ports for QML debugging."); + reportFailure(tr("Not enough free ports for QML debugging.")); return false; } qmlDebuggerPort = Utils::Port(server.serverPort()); diff --git a/src/plugins/winrt/winrtdebugsupport.h b/src/plugins/winrt/winrtdebugsupport.h index 995c3a0b73..0a8ed4e31a 100644 --- a/src/plugins/winrt/winrtdebugsupport.h +++ b/src/plugins/winrt/winrtdebugsupport.h @@ -38,11 +38,11 @@ class WinRtDebugSupport : public Debugger::DebuggerRunTool Q_OBJECT public: - WinRtDebugSupport(ProjectExplorer::RunControl *runControl, QString *errorMessage); + explicit WinRtDebugSupport(ProjectExplorer::RunControl *runControl); ~WinRtDebugSupport(); private: - static bool getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage); + bool getFreePort(Utils::Port &qmlDebuggerPort); WinRtRunnerHelper *m_runner = nullptr; }; diff --git a/src/plugins/winrt/winrtrunfactories.cpp b/src/plugins/winrt/winrtrunfactories.cpp index af4914c9bd..3269b32d64 100644 --- a/src/plugins/winrt/winrtrunfactories.cpp +++ b/src/plugins/winrt/winrtrunfactories.cpp @@ -151,7 +151,7 @@ bool WinRtRunControlFactory::canRun(RunConfiguration *runConfiguration, } RunControl *WinRtRunControlFactory::create( - RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) + RunConfiguration *runConfiguration, Core::Id mode, QString *) { RunControl *runControl = nullptr; if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) { @@ -161,15 +161,10 @@ RunControl *WinRtRunControlFactory::create( } else if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) { runControl = new RunControl(runConfiguration, mode); - (void) new WinRtDebugSupport(runControl, errorMessage); - } else { - *errorMessage = tr("Unsupported run mode %1.").arg(mode.toString()); - } - - if (errorMessage->isEmpty()) + (void) new WinRtDebugSupport(runControl); return runControl; + } - delete runControl; return nullptr; } -- GitLab