Commit c128731f authored by hjk's avatar hjk

Debugger: Use a QUrl for Qml server port and host

Host and port reasonably belong together, using a QUrl makes that more
explicit and follows the lead of the Qml profiler in that area.

Change-Id: I754cb17d165ce6b2f25c655eeebfd8ac8f5a93c7
Reviewed-by: Vikas Pachdha's avatarVikas Pachdha <vikas.pachdha@qt.io>
parent 60614d6c
......@@ -133,8 +133,7 @@ void AndroidDebugSupport::start()
.appendPath(toNdkArch(AndroidManager::targetArch(target))).toString();
}
if (isQmlDebugging()) {
params.qmlServer.host = m_runner->qmlServerHost();
params.qmlServer.port = m_runner->qmlServerPort();
params.qmlServer = m_runner->qmlServer();
//TODO: Not sure if these are the right paths.
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
if (version) {
......
......@@ -226,8 +226,7 @@ public:
Utils::Port localGdbServerPort() const { return m_localGdbServerPort; }
signals:
void remoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlServerPort,
QString qmlServerHost, int pid);
void remoteProcessStarted(Utils::Port gdbServerPort, const QUrl &qmlServer, int pid);
void remoteProcessFinished(const QString &errString = QString());
void remoteOutput(const QString &output);
......@@ -258,8 +257,7 @@ private:
bool m_useCppDebugger = false;
QmlDebug::QmlDebugServicesPreset m_qmlDebugServices;
Utils::Port m_localGdbServerPort; // Local end of forwarded debug socket.
QString m_qmlServerHost;
Utils::Port m_qmlPort;
QUrl m_qmlServer;
QString m_pingFile;
QString m_pongFile;
QString m_gdbserverPath;
......@@ -297,10 +295,8 @@ AndroidRunnerWorker::AndroidRunnerWorker(RunControl *runControl, const AndroidRu
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|| server.listen(QHostAddress::LocalHostIPv6),
qDebug() << tr("No free ports available on host for QML debugging."));
m_qmlServerHost = server.serverAddress().toString();
m_qmlPort = Utils::Port(server.serverPort());
} else {
m_qmlPort = Utils::Port();
m_qmlServer.setHost(server.serverAddress().toString());
m_qmlServer.setPort(server.serverPort());
}
m_adb = AndroidConfigurations::currentConfig().adbToolPath().toString();
......@@ -418,7 +414,7 @@ void AndroidRunnerWorker::asyncStart()
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
// currently forward to same port on device and host
const QString port = QString("tcp:%1").arg(m_qmlPort.number());
const QString port = QString("tcp:%1").arg(m_qmlServer.port());
if (!runAdb({"forward", port, port}, &errorMessage)) {
emit remoteProcessFinished(tr("Failed to forward QML debugging ports. Reason: %1.")
.arg(errorMessage));
......@@ -428,7 +424,7 @@ void AndroidRunnerWorker::asyncStart()
args << "-e" << "qml_debug" << "true"
<< "-e" << "qmljsdebugger"
<< QString("port:%1,block,services:%2")
.arg(m_qmlPort.number()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
.arg(m_qmlServer.port()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
}
if (!runAdb(args, &errorMessage)) {
......@@ -641,7 +637,7 @@ void AndroidRunnerWorker::onProcessIdChanged(qint64 pid)
} else {
// In debugging cases this will be funneled to the engine to actually start
// and attach gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below.
emit remoteProcessStarted(m_localGdbServerPort, m_qmlPort, m_qmlServerHost, m_processPID);
emit remoteProcessStarted(m_localGdbServerPort, m_qmlServer, m_processPID);
logcatReadStandardOutput();
QTC_ASSERT(!m_psIsAlive, /**/);
m_psIsAlive.reset(new QProcess);
......@@ -785,13 +781,12 @@ void AndroidRunner::remoteErrorOutput(const QString &output)
m_outputParser.processOutput(output);
}
void AndroidRunner::handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlServerPort,
QString qmlServerHost, int pid)
void AndroidRunner::handleRemoteProcessStarted(Utils::Port gdbServerPort,
const QUrl &qmlServer, int pid)
{
m_pid = ProcessHandle(pid);
m_gdbServerPort = gdbServerPort;
m_qmlServerHost = qmlServerHost;
m_qmlServerPort = qmlServerPort;
m_qmlServer = qmlServer;
reportStarted();
}
......
......@@ -57,8 +57,7 @@ public:
const AndroidRunnable &runnable() const { return m_androidRunnable; }
Utils::Port gdbServerPort() const { return m_gdbServerPort; }
QString qmlServerHost() const { return m_qmlServerHost; }
Utils::Port qmlServerPort() const { return m_qmlServerPort; }
QUrl qmlServer() const { return m_qmlServer; }
Utils::ProcessHandle pid() const { return m_pid; }
void start() override;
......@@ -77,8 +76,7 @@ private:
void remoteOutput(const QString &output);
void remoteErrorOutput(const QString &output);
void gotRemoteOutput(const QString &output);
void handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlServerPort,
QString qmlServerHost, int pid);
void handleRemoteProcessStarted(Utils::Port gdbServerPort, const QUrl &qmlServer, int pid);
void handleRemoteProcessFinished(const QString &errString = QString());
void checkAVD();
void launchAVD();
......@@ -90,8 +88,7 @@ private:
QScopedPointer<AndroidRunnerWorker> m_worker;
QPointer<ProjectExplorer::Target> m_target;
Utils::Port m_gdbServerPort;
QString m_qmlServerHost;
Utils::Port m_qmlServerPort;
QUrl m_qmlServer;
Utils::ProcessHandle m_pid;
QmlDebug::QmlOutputParser m_outputParser;
};
......
......@@ -2159,8 +2159,8 @@ void DebuggerPluginPrivate::attachToQmlPort()
const QVariant qmlServerPort = configValue("LastQmlServerPort");
if (qmlServerPort.isValid())
dlg.setPort(qmlServerPort.toInt());
else if (rp.qmlServer.port.isValid())
dlg.setPort(rp.qmlServer.port.number());
else if (rp.qmlServer.port() > 0)
dlg.setPort(rp.qmlServer.port());
else
dlg.setPort(-1);
......@@ -2181,9 +2181,9 @@ void DebuggerPluginPrivate::attachToQmlPort()
QSsh::SshConnectionParameters sshParameters = device->sshParameters();
rp.remoteChannel = QString("%1:%2").arg(sshParameters.host).arg(sshParameters.port);
QUrl toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
rp.qmlServer.host = toolControl.host();
rp.qmlServer.setHost(toolControl.host());
}
rp.qmlServer.port = Utils::Port(dlg.port());
rp.qmlServer.setPort(dlg.port());
rp.startMode = AttachToRemoteProcess;
rp.closeMode = KillAtClose;
rp.languages = QmlLanguage;
......@@ -2937,9 +2937,8 @@ static QString formatStartParameters(DebuggerRunParameters &sp)
}
if (!sp.remoteChannel.isEmpty())
str << "Remote: " << sp.remoteChannel << '\n';
if (!sp.qmlServer.host.isEmpty())
str << "QML server: " << sp.qmlServer.host << ':'
<< (sp.qmlServer.port.isValid() ? sp.qmlServer.port.number() : -1) << '\n';
if (!sp.qmlServer.host().isEmpty())
str << "QML server: " << sp.qmlServer.host() << ':' << sp.qmlServer.port() << '\n';
str << "Sysroot: " << sp.sysRoot << '\n';
str << "Debug Source Location: " << sp.debugSourceLocation.join(QLatin1Char(':')) << '\n';
return rc;
......
......@@ -485,7 +485,7 @@ static bool fixupParameters(DebuggerRunParameters &rp, RunControl *runControl, Q
IDevice::ConstPtr device = runControl->device();
if (rp.languages & QmlLanguage) {
if (device && device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
if (rp.qmlServer.host.isEmpty() || !rp.qmlServer.port.isValid()) {
if (rp.qmlServer.host().isEmpty() || rp.qmlServer.port() <= 0) {
QTcpServer server;
const bool canListen = server.listen(QHostAddress::LocalHost)
|| server.listen(QHostAddress::LocalHostIPv6);
......@@ -493,10 +493,8 @@ static bool fixupParameters(DebuggerRunParameters &rp, RunControl *runControl, Q
m_errors.append(DebuggerPlugin::tr("Not enough free ports for QML debugging.") + ' ');
return false;
}
TcpServerConnection conn;
conn.host = server.serverAddress().toString();
conn.port = Utils::Port(server.serverPort());
rp.qmlServer = conn;
rp.qmlServer.setHost(server.serverAddress().toString());
rp.qmlServer.setPort(server.serverPort());
}
// Makes sure that all bindings go through the JavaScript engine, so that
......@@ -534,10 +532,10 @@ static bool fixupParameters(DebuggerRunParameters &rp, RunControl *runControl, Q
service = QmlDebug::QmlDebuggerServices;
}
if (rp.startMode != AttachExternal && rp.startMode != AttachCrashedExternal) {
QtcProcess::addArg(&rp.inferior.commandLineArguments,
(rp.languages & CppLanguage) && rp.nativeMixedEnabled ?
QmlDebug::qmlDebugNativeArguments(service, false) :
QmlDebug::qmlDebugTcpArguments(service, rp.qmlServer.port));
QString qmlarg = (rp.languages & CppLanguage) && rp.nativeMixedEnabled
? QmlDebug::qmlDebugNativeArguments(service, false)
: QmlDebug::qmlDebugTcpArguments(service, Port(rp.qmlServer.port()));
QtcProcess::addArg(&rp.inferior.commandLineArguments, qmlarg);
}
}
}
......
......@@ -46,13 +46,6 @@ namespace Debugger {
// Note: This is part of the "soft interface" of the debugger plugin.
// Do not add anything that needs implementation in a .cpp file.
class DEBUGGER_EXPORT TcpServerConnection
{
public:
QString host;
Utils::Port port;
};
class DEBUGGER_EXPORT DebuggerStartParameters
{
public:
......@@ -68,7 +61,7 @@ public:
bool needFixup = true; // FIXME: Make false the default...
// Used by Qml debugging.
TcpServerConnection qmlServer;
QUrl qmlServer;
// Used by general remote debugging.
QString remoteChannel;
......
......@@ -384,7 +384,7 @@ void QmlEngine::beginConnection()
QObject::disconnect(d->startupMessageFilterConnection);
QString host = runParameters().qmlServer.host;
QString host = runParameters().qmlServer.host();
// Use localhost as default
if (host.isEmpty())
host = QHostAddress(QHostAddress::LocalHost).toString();
......@@ -401,12 +401,12 @@ void QmlEngine::beginConnection()
* the connection will be closed again (instead of returning the "connection refused"
* error that we expect).
*/
Utils::Port port = runParameters().qmlServer.port;
int port = runParameters().qmlServer.port();
if (!d->connection || d->connection->isConnected())
return;
d->connection->connectToHost(host, port.number());
d->connection->connectToHost(host, port);
//A timeout to check the connection state
d->connectionTimer.start();
......
......@@ -518,13 +518,13 @@ void IosDebugSupport::start()
QTcpServer server;
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|| server.listen(QHostAddress::LocalHostIPv6), return);
params.qmlServer.host = server.serverAddress().toString();
params.qmlServer.setHost(server.serverAddress().toString());
if (!cppDebug)
params.startMode = AttachToRemoteServer;
}
if (qmlServerPort.isValid()) {
params.qmlServer.port = qmlServerPort;
params.qmlServer.setPort(qmlServerPort.number());
params.inferior.commandLineArguments.replace("%qml_port%", qmlServerPort.toString());
}
......
......@@ -126,9 +126,10 @@ void QnxDebugSupport::start()
params.inferior.commandLineArguments = runConfig->arguments();
if (isQmlDebugging()) {
params.qmlServer.host = device()->sshParameters().host;
params.qmlServer.port = m_portsGatherer->qmlServerPort();
params.inferior.commandLineArguments.replace("%qml_port%", params.qmlServer.port.toString());
const int qmlServerPort = m_portsGatherer->qmlServerPort().number();
params.qmlServer.setHost(device()->sshParameters().host);
params.qmlServer.setPort(qmlServerPort);
params.inferior.commandLineArguments.replace("%qml_port%", QString::number(qmlServerPort));
}
auto qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(k));
......
......@@ -77,17 +77,16 @@ void LinuxDeviceDebugSupport::start()
const QString host = device()->sshParameters().host;
const Port gdbServerPort = m_portsGatherer->gdbServerPort();
const Port qmlServerPort = m_portsGatherer->qmlServerPort();
const int qmlServerPort = m_portsGatherer->qmlServerPort().number();
DebuggerStartParameters params;
params.startMode = AttachToRemoteServer;
params.closeMode = KillAndExitMonitorAtClose;
if (isQmlDebugging()) {
params.qmlServer.host = host;
params.qmlServer.port = qmlServerPort;
params.inferior.commandLineArguments.replace("%qml_port%",
QString::number(qmlServerPort.number()));
params.qmlServer.setHost(host);
params.qmlServer.setPort(qmlServerPort);
params.inferior.commandLineArguments.replace("%qml_port%", QString::number(qmlServerPort));
}
if (isCppDebugging()) {
Runnable r = runnable();
......
......@@ -64,13 +64,11 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl)
}
if (isQmlDebugging()) {
QUrl qmlServer = ProjectExplorer::urlFromLocalHostAndFreePort();
if (qmlServer.port() <= 0) {
params.qmlServer = ProjectExplorer::urlFromLocalHostAndFreePort();
if (params.qmlServer.port() <= 0) {
reportFailure(tr("Not enough free ports for QML debugging."));
return;
}
params.qmlServer.host = qmlServer.host();
params.qmlServer.port = Utils::Port(qmlServer.port());
}
QString errorMessage;
......
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