diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 2c323a3b1ea..7f16e9b8e19 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -518,19 +518,20 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const const bool wantQmlDebugger = m_debuggerAspect->useQmlDebugger() && (m_rp.languages & QmlLanguage); if (wantQmlDebugger) { - QString qmlArgs; + QmlDebug::QmlDebugServicesPreset service; if (wantCppDebugger) { if (m_rp.nativeMixedEnabled) { - qmlArgs = QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlNativeDebuggerServices); + service = QmlDebug::QmlNativeDebuggerServices; } else { m_rp.masterEngineType = QmlCppEngineType; - qmlArgs = QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlDebuggerServices, m_rp.qmlServerPort); + service = QmlDebug::QmlDebuggerServices; } } else { m_rp.masterEngineType = QmlEngineType; - qmlArgs = QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlDebuggerServices, m_rp.qmlServerPort); + service = QmlDebug::QmlDebuggerServices; } - QtcProcess::addArg(&m_rp.processArgs, qmlArgs); + if (m_rp.startMode != AttachExternal) + QtcProcess::addArg(&m_rp.processArgs, QmlDebug::qmlDebugCommandLineArguments(service, m_rp.qmlServerPort)); } } diff --git a/src/plugins/winrt/winrtdebugsupport.cpp b/src/plugins/winrt/winrtdebugsupport.cpp index 0f25380fc82..5f597d89df7 100644 --- a/src/plugins/winrt/winrtdebugsupport.cpp +++ b/src/plugins/winrt/winrtdebugsupport.cpp @@ -33,14 +33,18 @@ #include "winrtrunnerhelper.h" #include +#include #include #include #include #include +#include + #include #include #include +#include #include @@ -57,6 +61,24 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, WinRtRunnerHelper * connect(m_debugRunControl, SIGNAL(finished()), this, SLOT(finish())); } +bool WinRtDebugSupport::useQmlDebugging(WinRtRunConfiguration *runConfig) +{ + Debugger::DebuggerRunConfigurationAspect *extraAspect = + runConfig->extraAspect(); + return extraAspect && extraAspect->useQmlDebugger(); +} + +bool WinRtDebugSupport::getFreePort(quint16 &qmlDebuggerPort, QString *errorMessage) +{ + QTcpServer server; + if (!server.listen(QHostAddress::LocalHost, qmlDebuggerPort)) { + *errorMessage = tr("Not enough free ports for QML debugging."); + return false; + } + qmlDebuggerPort = server.serverPort(); + return true; +} + WinRtDebugSupport::~WinRtDebugSupport() { delete m_runner; @@ -87,6 +109,16 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC return 0; } + if (useQmlDebugging(runConfig)) { + quint16 qmlDebugPort = 0; + if (!getFreePort(qmlDebugPort, errorMessage)) + return 0; + runConfig->setArguments(runConfig->arguments() + QLatin1Char(' ') + + QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlDebuggerServices, qmlDebugPort)); + params.qmlServerAddress = QHostAddress::LocalHost; + params.qmlServerPort = qmlDebugPort; + } + WinRtRunnerHelper *runner = new WinRtRunnerHelper(runConfig, errorMessage); if (!errorMessage->isEmpty()) return 0; @@ -121,7 +153,7 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC server.close(); Debugger::DebuggerRunControl *debugRunControl = createDebuggerRunControl(params, runConfig, errorMessage, mode); - runner->setRunControl(debugRunControl); + runner->setDebugRunControl(debugRunControl); new WinRtDebugSupport(debugRunControl, runner); return debugRunControl; } diff --git a/src/plugins/winrt/winrtdebugsupport.h b/src/plugins/winrt/winrtdebugsupport.h index f92281beb27..11113a88457 100644 --- a/src/plugins/winrt/winrtdebugsupport.h +++ b/src/plugins/winrt/winrtdebugsupport.h @@ -54,6 +54,9 @@ public: private: WinRtDebugSupport(ProjectExplorer::RunControl *runControl, WinRtRunnerHelper *runner); + static bool useQmlDebugging(WinRtRunConfiguration *runConfig); + static bool getFreePort(quint16 &qmlDebuggerPort, QString *errorMessage); + ProjectExplorer::RunControl *m_debugRunControl; WinRtRunnerHelper *m_runner; diff --git a/src/plugins/winrt/winrtrunnerhelper.cpp b/src/plugins/winrt/winrtrunnerhelper.cpp index 4eae432a2a6..36d13d13379 100644 --- a/src/plugins/winrt/winrtrunnerhelper.cpp +++ b/src/plugins/winrt/winrtrunnerhelper.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -54,6 +55,7 @@ using namespace WinRt::Internal; WinRtRunnerHelper::WinRtRunnerHelper(WinRtRunConfiguration *runConfiguration, QString *errormessage) : QObject() , m_messenger(0) + , m_debugMessenger(0) , m_runConfiguration(runConfiguration) , m_process(0) { @@ -63,6 +65,7 @@ WinRtRunnerHelper::WinRtRunnerHelper(WinRtRunConfiguration *runConfiguration, QS WinRtRunnerHelper::WinRtRunnerHelper(ProjectExplorer::RunControl *runControl) : QObject(runControl) , m_messenger(runControl) + , m_debugMessenger(0) , m_runConfiguration(0) , m_process(0) { @@ -112,6 +115,17 @@ bool WinRtRunnerHelper::init(WinRtRunConfiguration *runConfiguration, QString *e return true; } +void WinRtRunnerHelper::appendMessage(const QString &message, Utils::OutputFormat format) +{ + if (m_debugMessenger && (format == Utils::StdOutFormat || format == Utils::StdErrFormat)){ + // We wan to filter out the waiting for connection message from the QML debug server + m_debugMessenger->showMessage(message, format == Utils::StdOutFormat ? Debugger::AppOutput + : Debugger::AppError); + } else if (m_messenger) { + m_messenger->appendMessage(message, format); + } +} + void WinRtRunnerHelper::debug(const QString &debuggerExecutable, const QString &debuggerArguments) { m_debuggerExecutable = debuggerExecutable; @@ -138,27 +152,22 @@ bool WinRtRunnerHelper::waitForStarted(int msecs) return m_process->waitForStarted(msecs); } -void WinRtRunnerHelper::setRunControl(ProjectExplorer::RunControl *runControl) +void WinRtRunnerHelper::setDebugRunControl(Debugger::DebuggerRunControl *runControl) { + m_debugMessenger = runControl; m_messenger = runControl; } void WinRtRunnerHelper::onProcessReadyReadStdOut() { QTC_ASSERT(m_process, return); - if (m_messenger) { - m_messenger->appendMessage(QString::fromLocal8Bit( - m_process->readAllStandardOutput()), Utils::StdOutFormat); - } + appendMessage(QString::fromLocal8Bit(m_process->readAllStandardOutput()), Utils::StdOutFormat); } void WinRtRunnerHelper::onProcessReadyReadStdErr() { QTC_ASSERT(m_process, return); - if (m_messenger) { - m_messenger->appendMessage(QString::fromLocal8Bit( - m_process->readAllStandardError()), Utils::StdErrFormat); - } + appendMessage(QString::fromLocal8Bit(m_process->readAllStandardError()), Utils::StdErrFormat); } void WinRtRunnerHelper::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) @@ -173,11 +182,8 @@ void WinRtRunnerHelper::onProcessFinished(int exitCode, QProcess::ExitStatus exi void WinRtRunnerHelper::onProcessError(QProcess::ProcessError processError) { QTC_ASSERT(m_process, return); - if (m_messenger) { - m_messenger->appendMessage(tr("Error while executing the WinRT Runner Tool: %1\n").arg( - m_process->errorString()), - Utils::ErrorMessageFormat); - } + appendMessage(tr("Error while executing the WinRT Runner Tool: %1\n").arg( + m_process->errorString()), Utils::ErrorMessageFormat); m_process->disconnect(); m_process->deleteLater(); m_process = 0; @@ -193,16 +199,16 @@ void WinRtRunnerHelper::startWinRtRunner(const RunConf &conf) QtcProcess::addArg(&runnerArgs, QString::number(m_device->deviceId())); } - Utils::QtcProcess *process = 0; + QtcProcess *process = 0; bool connectProcess = false; switch (conf) { case Debug: - Utils::QtcProcess::addArg(&runnerArgs, QStringLiteral("--debug")); - Utils::QtcProcess::addArg(&runnerArgs, m_debuggerExecutable); + QtcProcess::addArg(&runnerArgs, QStringLiteral("--debug")); + QtcProcess::addArg(&runnerArgs, m_debuggerExecutable); if (!m_debuggerArguments.isEmpty()) { - Utils::QtcProcess::addArg(&runnerArgs, QStringLiteral("--debugger-arguments")); - Utils::QtcProcess::addArg(&runnerArgs, m_debuggerArguments); + QtcProcess::addArg(&runnerArgs, QStringLiteral("--debugger-arguments")); + QtcProcess::addArg(&runnerArgs, m_debuggerArguments); } // fall through case Start: @@ -213,7 +219,7 @@ void WinRtRunnerHelper::startWinRtRunner(const RunConf &conf) process = m_process; break; case Stop: - Utils::QtcProcess::addArgs(&runnerArgs, QStringLiteral("--stop")); + QtcProcess::addArgs(&runnerArgs, QStringLiteral("--stop")); process = new QtcProcess(this); break; } @@ -225,10 +231,7 @@ void WinRtRunnerHelper::startWinRtRunner(const RunConf &conf) if (!m_arguments.isEmpty()) QtcProcess::addArgs(&runnerArgs, m_arguments); - if (m_messenger) { - m_messenger->appendMessage(QStringLiteral("winrtrunner ") + runnerArgs + QLatin1Char('\n'), - Utils::NormalMessageFormat); - } + appendMessage(QStringLiteral("winrtrunner ") + runnerArgs + QLatin1Char('\n'), NormalMessageFormat); if (connectProcess) { connect(process, SIGNAL(started()), SIGNAL(started())); diff --git a/src/plugins/winrt/winrtrunnerhelper.h b/src/plugins/winrt/winrtrunnerhelper.h index 2252a598dac..881b6c1f7dd 100644 --- a/src/plugins/winrt/winrtrunnerhelper.h +++ b/src/plugins/winrt/winrtrunnerhelper.h @@ -43,6 +43,7 @@ namespace Utils { class QtcProcess; } namespace ProjectExplorer { class RunControl; } +namespace Debugger { class DebuggerRunControl; } namespace WinRt { namespace Internal { @@ -62,7 +63,7 @@ public: void stop(); bool waitForStarted(int msecs = 10000); - void setRunControl(ProjectExplorer::RunControl *runControl); + void setDebugRunControl(Debugger::DebuggerRunControl *runControl); signals: void started(); @@ -79,8 +80,10 @@ private: enum RunConf { Start, Stop, Debug }; void startWinRtRunner(const RunConf &conf); bool init(WinRtRunConfiguration *runConfiguration, QString *errorMessage); + void appendMessage(const QString &message, Utils::OutputFormat format); ProjectExplorer::RunControl *m_messenger; + Debugger::DebuggerRunControl *m_debugMessenger; WinRtRunConfiguration *m_runConfiguration; WinRtDevice::ConstPtr m_device; Utils::Environment m_environment;