Commit 69a4f80c authored by David Schulz's avatar David Schulz

WinRT: Fix C++ debugging when qml debugging is also enabled.

This is also a preparation to enable QML debugging. Unfortunately
the WinRT QML library isn't printing the needed "Waiting for connection"
output so far.

Change-Id: I5e106de0272a0876749aaf77f1ebf74b952d3471
Reviewed-by: default avatarOliver Wolff <oliver.wolff@theqtcompany.com>
parent 9d465e4e
......@@ -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));
}
}
......
......@@ -33,14 +33,18 @@
#include "winrtrunnerhelper.h"
#include <debugger/debuggerkitinformation.h>
#include <debugger/debuggerrunconfigurationaspect.h>
#include <debugger/debuggerruncontrol.h>
#include <debugger/debuggerstartparameters.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <qmldebug/qmldebugcommandlinearguments.h>
#include <QFileInfo>
#include <QLocalServer>
#include <QLocalSocket>
#include <QTcpServer>
#include <utils/qtcprocess.h>
......@@ -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<Debugger::DebuggerRunConfigurationAspect>();
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;
}
......
......@@ -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;
......
......@@ -45,6 +45,7 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/qtcprocess.h>
#include <debugger/debuggerruncontrol.h>
#include <QDir>
......@@ -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()));
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment