Use Utils::Port where possible

This solves the ambiguity between 0 and -1 being the "invalid" port.

Change-Id: I3bac11dd4117bb1820fbd58186699925b73df1c5
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2016-04-19 16:43:30 +02:00
parent e14238650c
commit 385237dbbd
62 changed files with 239 additions and 187 deletions

View File

@@ -25,6 +25,7 @@
#pragma once #pragma once
#include <utils/port.h>
#include <QString> #include <QString>
namespace QmlDebug { namespace QmlDebug {
@@ -63,11 +64,13 @@ static inline QString qmlDebugCommandLineArguments(QmlDebugServicesPreset servic
.arg(QLatin1String(block ? ",block" : "")).arg(qmlDebugServices(services)); .arg(QLatin1String(block ? ",block" : "")).arg(qmlDebugServices(services));
} }
static inline QString qmlDebugTcpArguments(QmlDebugServicesPreset services, quint16 port = 0, static inline QString qmlDebugTcpArguments(QmlDebugServicesPreset services,
Utils::Port port = Utils::Port(),
bool block = true) bool block = true)
{ {
return qmlDebugCommandLineArguments(services, port ? QString::fromLatin1("port:%1").arg(port) : return qmlDebugCommandLineArguments(services, port.isValid() ?
QStringLiteral("port:%qml_port%"), block); QString::fromLatin1("port:%1").arg(port.number()) :
QStringLiteral("port:%qml_port%"), block);
} }
static inline QString qmlDebugNativeArguments(QmlDebugServicesPreset services, bool block = true) static inline QString qmlDebugNativeArguments(QmlDebugServicesPreset services, bool block = true)

View File

@@ -84,7 +84,7 @@ void QmlOutputParser::processOutput(const QString &output)
bool canConvert; bool canConvert;
quint16 port = waitingTcp.cap(1).toUShort(&canConvert); quint16 port = waitingTcp.cap(1).toUShort(&canConvert);
if (canConvert) if (canConvert)
emit waitingForConnectionOnPort(port); emit waitingForConnectionOnPort(Utils::Port(port));
continue; continue;
} }
} else if (status.startsWith(unableToListen)) { } else if (status.startsWith(unableToListen)) {

View File

@@ -27,6 +27,7 @@
#include "qmldebug_global.h" #include "qmldebug_global.h"
#include <utils/port.h>
#include <QObject> #include <QObject>
namespace QmlDebug { namespace QmlDebug {
@@ -41,7 +42,7 @@ public:
void processOutput(const QString &output); void processOutput(const QString &output);
signals: signals:
void waitingForConnectionOnPort(quint16 port); void waitingForConnectionOnPort(Utils::Port port);
void connectionEstablishedMessage(); void connectionEstablishedMessage();
void connectingToSocketMessage(); void connectingToSocketMessage();
void errorMessage(const QString &detailedError); void errorMessage(const QString &detailedError);

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include "utils_global.h" #include "utils_global.h"
#include "qtcassert.h"
namespace Utils { namespace Utils {
@@ -34,12 +35,28 @@ class QTCREATOR_UTILS_EXPORT Port
public: public:
Port() : m_port(-1) {} Port() : m_port(-1) {}
explicit Port(quint16 port) : m_port(port) {} explicit Port(quint16 port) : m_port(port) {}
explicit Port(int port) :
m_port((port < 0 || port > std::numeric_limits<quint16>::max()) ? -1 : port)
{
}
quint16 number() const { return quint16(m_port); } explicit Port(uint port) :
m_port(port > std::numeric_limits<quint16>::max() ? -1 : port)
{
}
quint16 number() const { QTC_ASSERT(isValid(), return 0); return quint16(m_port); }
bool isValid() const { return m_port != -1; } bool isValid() const { return m_port != -1; }
private: private:
int m_port; int m_port;
}; };
inline bool operator<(const Port &p1, const Port &p2) { return p1.number() < p2.number(); }
inline bool operator<=(const Port &p1, const Port &p2) { return p1.number() <= p2.number(); }
inline bool operator>(const Port &p1, const Port &p2) { return p1.number() > p2.number(); }
inline bool operator>=(const Port &p1, const Port &p2) { return p1.number() >= p2.number(); }
inline bool operator==(const Port &p1, const Port &p2) { return p1.number() == p2.number(); }
inline bool operator!=(const Port &p1, const Port &p2) { return p1.number() != p2.number(); }
} // Utils } // Utils

View File

@@ -35,7 +35,7 @@ namespace Utils {
namespace Internal { namespace Internal {
namespace { namespace {
typedef QPair<int, int> Range; typedef QPair<Port, Port> Range;
class PortsSpecParser class PortsSpecParser
{ {
@@ -82,19 +82,19 @@ private:
void parseElem() void parseElem()
{ {
const int startPort = parsePort(); const Port startPort = parsePort();
if (atEnd() || nextChar() != '-') { if (atEnd() || nextChar() != '-') {
m_portList.addPort(startPort); m_portList.addPort(startPort);
return; return;
} }
++m_pos; ++m_pos;
const int endPort = parsePort(); const Port endPort = parsePort();
if (endPort < startPort) if (endPort < startPort)
throw ParseException("Invalid range (end < start)."); throw ParseException("Invalid range (end < start).");
m_portList.addRange(startPort, endPort); m_portList.addRange(startPort, endPort);
} }
int parsePort() Port parsePort()
{ {
if (atEnd()) if (atEnd())
throw ParseException("Empty port string."); throw ParseException("Empty port string.");
@@ -108,7 +108,7 @@ private:
} while (!atEnd()); } while (!atEnd());
if (port == 0 || port >= 2 << 16) if (port == 0 || port >= 2 << 16)
throw ParseException("Invalid port value."); throw ParseException("Invalid port value.");
return port; return Port(port);
} }
bool atEnd() const { return m_pos == m_portsSpec.length(); } bool atEnd() const { return m_pos == m_portsSpec.length(); }
@@ -153,16 +153,16 @@ PortList PortList::fromString(const QString &portsSpec)
return Internal::PortsSpecParser(portsSpec).parse(); return Internal::PortsSpecParser(portsSpec).parse();
} }
void PortList::addPort(int port) { addRange(port, port); } void PortList::addPort(Port port) { addRange(port, port); }
void PortList::addRange(int startPort, int endPort) void PortList::addRange(Port startPort, Port endPort)
{ {
d->ranges << Internal::Range(startPort, endPort); d->ranges << Internal::Range(startPort, endPort);
} }
bool PortList::hasMore() const { return !d->ranges.isEmpty(); } bool PortList::hasMore() const { return !d->ranges.isEmpty(); }
bool PortList::contains(int port) const bool PortList::contains(Port port) const
{ {
foreach (const Internal::Range &r, d->ranges) { foreach (const Internal::Range &r, d->ranges) {
if (port >= r.first && port <= r.second) if (port >= r.first && port <= r.second)
@@ -175,16 +175,17 @@ int PortList::count() const
{ {
int n = 0; int n = 0;
foreach (const Internal::Range &r, d->ranges) foreach (const Internal::Range &r, d->ranges)
n += r.second - r.first + 1; n += r.second.number() - r.first.number() + 1;
return n; return n;
} }
int PortList::getNext() Port PortList::getNext()
{ {
Q_ASSERT(!d->ranges.isEmpty()); Q_ASSERT(!d->ranges.isEmpty());
Internal::Range &firstRange = d->ranges.first(); Internal::Range &firstRange = d->ranges.first();
const int next = firstRange.first++; const Port next = firstRange.first;
firstRange.first = Port(firstRange.first.number() + 1);
if (firstRange.first > firstRange.second) if (firstRange.first > firstRange.second)
d->ranges.removeFirst(); d->ranges.removeFirst();
return next; return next;
@@ -194,9 +195,9 @@ QString PortList::toString() const
{ {
QString stringRep; QString stringRep;
foreach (const Internal::Range &range, d->ranges) { foreach (const Internal::Range &range, d->ranges) {
stringRep += QString::number(range.first); stringRep += QString::number(range.first.number());
if (range.second != range.first) if (range.second != range.first)
stringRep += QLatin1Char('-') + QString::number(range.second); stringRep += QLatin1Char('-') + QString::number(range.second.number());
stringRep += QLatin1Char(','); stringRep += QLatin1Char(',');
} }
if (!stringRep.isEmpty()) if (!stringRep.isEmpty())

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include "utils_global.h" #include "utils_global.h"
#include "port.h"
QT_FORWARD_DECLARE_CLASS(QString) QT_FORWARD_DECLARE_CLASS(QString)
@@ -40,12 +41,12 @@ public:
PortList &operator=(const PortList &other); PortList &operator=(const PortList &other);
~PortList(); ~PortList();
void addPort(int port); void addPort(Port port);
void addRange(int startPort, int endPort); void addRange(Port startPort, Port endPort);
bool hasMore() const; bool hasMore() const;
bool contains(int port) const; bool contains(Port port) const;
int count() const; int count() const;
int getNext(); Port getNext();
QString toString() const; QString toString() const;
static PortList fromString(const QString &portsSpec); static PortList fromString(const QString &portsSpec);

View File

@@ -79,12 +79,12 @@ AndroidAnalyzeSupport::AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig,
[runner]() { runner->start(); }); [runner]() { runner->start(); });
connect(&m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort, connect(&m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort,
[this, runControl](quint16) { [this, runControl](Utils::Port) {
runControl->notifyRemoteSetupDone(m_qmlPort); runControl->notifyRemoteSetupDone(m_qmlPort);
}); });
connect(runner, &AndroidRunner::remoteProcessStarted, connect(runner, &AndroidRunner::remoteProcessStarted,
[this](int, int qmlPort) { [this](Utils::Port, Utils::Port qmlPort) {
m_qmlPort = qmlPort; m_qmlPort = qmlPort;
}); });

View File

@@ -49,7 +49,7 @@ public:
private: private:
QmlDebug::QmlOutputParser m_outputParser; QmlDebug::QmlOutputParser m_outputParser;
int m_qmlPort; Utils::Port m_qmlPort;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -171,7 +171,7 @@ AndroidDebugSupport::AndroidDebugSupport(AndroidRunConfiguration *runConfig,
}); });
} }
void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlPort) void AndroidDebugSupport::handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort)
{ {
disconnect(m_runner, &AndroidRunner::remoteProcessStarted, disconnect(m_runner, &AndroidRunner::remoteProcessStarted,
this, &AndroidDebugSupport::handleRemoteProcessStarted); this, &AndroidDebugSupport::handleRemoteProcessStarted);

View File

@@ -49,7 +49,7 @@ public:
QString *errorMessage); QString *errorMessage);
private: private:
void handleRemoteProcessStarted(int gdbServerPort, int qmlPort); void handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort);
Debugger::DebuggerRunControl *m_runControl; Debugger::DebuggerRunControl *m_runControl;
AndroidRunner * const m_runner; AndroidRunner * const m_runner;

View File

@@ -137,16 +137,16 @@ AndroidRunner::AndroidRunner(QObject *parent,
m_qmlDebugServices = QmlDebug::NoQmlDebugServices; m_qmlDebugServices = QmlDebug::NoQmlDebugServices;
QString channel = runConfig->remoteChannel(); QString channel = runConfig->remoteChannel();
QTC_CHECK(channel.startsWith(QLatin1Char(':'))); QTC_CHECK(channel.startsWith(QLatin1Char(':')));
m_localGdbServerPort = channel.mid(1).toUShort(); m_localGdbServerPort = Utils::Port(channel.mid(1).toUShort());
QTC_CHECK(m_localGdbServerPort); QTC_CHECK(m_localGdbServerPort.isValid());
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) { if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
QTcpServer server; QTcpServer server;
QTC_ASSERT(server.listen(QHostAddress::LocalHost) QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|| server.listen(QHostAddress::LocalHostIPv6), || server.listen(QHostAddress::LocalHostIPv6),
qDebug() << tr("No free ports available on host for QML debugging.")); qDebug() << tr("No free ports available on host for QML debugging."));
m_qmlPort = server.serverPort(); m_qmlPort = Utils::Port(server.serverPort());
} else { } else {
m_qmlPort = 0; m_qmlPort = Utils::Port();
} }
ProjectExplorer::Target *target = runConfig->target(); ProjectExplorer::Target *target = runConfig->target();
m_androidRunnable.intentName = AndroidManager::intentName(target); m_androidRunnable.intentName = AndroidManager::intentName(target);
@@ -276,18 +276,18 @@ void AndroidRunner::checkPID()
if (m_useCppDebugger) { if (m_useCppDebugger) {
// This will be funneled to the engine to actually start and attach // This will be funneled to the engine to actually start and attach
// gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below.
QByteArray serverChannel = ':' + QByteArray::number(m_localGdbServerPort); QByteArray serverChannel = ':' + QByteArray::number(m_localGdbServerPort.number());
emit remoteServerRunning(serverChannel, m_processPID); emit remoteServerRunning(serverChannel, m_processPID);
} else if (m_qmlDebugServices == QmlDebug::QmlDebuggerServices) { } else if (m_qmlDebugServices == QmlDebug::QmlDebuggerServices) {
// This will be funneled to the engine to actually start and attach // This will be funneled to the engine to actually start and attach
// gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below. // gdb. Afterwards this ends up in handleRemoteDebuggerRunning() below.
QByteArray serverChannel = QByteArray::number(m_qmlPort); QByteArray serverChannel = QByteArray::number(m_qmlPort.number());
emit remoteServerRunning(serverChannel, m_processPID); emit remoteServerRunning(serverChannel, m_processPID);
} else if (m_qmlDebugServices == QmlDebug::QmlProfilerServices) { } else if (m_qmlDebugServices == QmlDebug::QmlProfilerServices) {
emit remoteProcessStarted(-1, m_qmlPort); emit remoteProcessStarted(Utils::Port(), m_qmlPort);
} else { } else {
// Start without debugging. // Start without debugging.
emit remoteProcessStarted(-1, -1); emit remoteProcessStarted(Utils::Port(), Utils::Port());
} }
m_wasStarted = true; m_wasStarted = true;
logcatReadStandardOutput(); logcatReadStandardOutput();
@@ -348,7 +348,7 @@ void AndroidRunner::asyncStart()
if (m_useCppDebugger) { if (m_useCppDebugger) {
QProcess adb; QProcess adb;
adb.start(m_adb, selector() << _("forward") adb.start(m_adb, selector() << _("forward")
<< QString::fromLatin1("tcp:%1").arg(m_localGdbServerPort) << QString::fromLatin1("tcp:%1").arg(m_localGdbServerPort.number())
<< _("localfilesystem:") + m_gdbserverSocket); << _("localfilesystem:") + m_gdbserverSocket);
if (!adb.waitForStarted()) { if (!adb.waitForStarted()) {
emit remoteProcessFinished(tr("Failed to forward C++ debugging ports. Reason: %1.").arg(adb.errorString())); emit remoteProcessFinished(tr("Failed to forward C++ debugging ports. Reason: %1.").arg(adb.errorString()));
@@ -390,7 +390,7 @@ void AndroidRunner::asyncStart()
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) { if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
// currently forward to same port on device and host // currently forward to same port on device and host
const QString port = QString::fromLatin1("tcp:%1").arg(m_qmlPort); const QString port = QString::fromLatin1("tcp:%1").arg(m_qmlPort.number());
QProcess adb; QProcess adb;
adb.start(m_adb, selector() << _("forward") << port << port); adb.start(m_adb, selector() << _("forward") << port << port);
if (!adb.waitForStarted()) { if (!adb.waitForStarted()) {
@@ -405,7 +405,7 @@ void AndroidRunner::asyncStart()
args << _("-e") << _("qml_debug") << _("true") args << _("-e") << _("qml_debug") << _("true")
<< _("-e") << _("qmljsdebugger") << _("-e") << _("qmljsdebugger")
<< QString::fromLatin1("port:%1,block,services:%2") << QString::fromLatin1("port:%1,block,services:%2")
.arg(m_qmlPort).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices)); .arg(m_qmlPort.number()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
} }
QProcess adb; QProcess adb;

View File

@@ -68,7 +68,7 @@ public slots:
signals: signals:
void remoteServerRunning(const QByteArray &serverChannel, int pid); void remoteServerRunning(const QByteArray &serverChannel, int pid);
void remoteProcessStarted(int gdbServerPort, int qmlPort); void remoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort);
void remoteProcessFinished(const QString &errString = QString()); void remoteProcessFinished(const QString &errString = QString());
void remoteOutput(const QString &output); void remoteOutput(const QString &output);
@@ -101,8 +101,8 @@ private:
qint64 m_processPID; qint64 m_processPID;
bool m_useCppDebugger; bool m_useCppDebugger;
QmlDebug::QmlDebugServicesPreset m_qmlDebugServices; QmlDebug::QmlDebugServicesPreset m_qmlDebugServices;
ushort m_localGdbServerPort; // Local end of forwarded debug socket. Utils::Port m_localGdbServerPort; // Local end of forwarded debug socket.
quint16 m_qmlPort; Utils::Port m_qmlPort;
QString m_pingFile; QString m_pingFile;
QString m_pongFile; QString m_pongFile;
QString m_gdbserverPath; QString m_gdbserverPath;

View File

@@ -31,6 +31,7 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <utils/outputformat.h> #include <utils/outputformat.h>
#include <utils/port.h>
namespace Debugger { namespace Debugger {
@@ -51,7 +52,7 @@ public:
virtual void pause() {} virtual void pause() {}
virtual void unpause() {} virtual void unpause() {}
virtual void notifyRemoteSetupDone(quint16) {} virtual void notifyRemoteSetupDone(Utils::Port) {}
virtual void notifyRemoteFinished() {} virtual void notifyRemoteFinished() {}
signals: signals:

View File

@@ -29,6 +29,7 @@
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/port.h>
#include <QMetaType> #include <QMetaType>
@@ -40,7 +41,7 @@ public:
QSsh::SshConnectionParameters connParams; QSsh::SshConnectionParameters connParams;
QString analyzerHost; QString analyzerHost;
QString analyzerSocket; QString analyzerSocket;
quint16 analyzerPort = 0; Utils::Port analyzerPort;
}; };
DEBUGGER_EXPORT bool operator==(const AnalyzerConnection &c1, const AnalyzerConnection &c2); DEBUGGER_EXPORT bool operator==(const AnalyzerConnection &c1, const AnalyzerConnection &c2);

View File

@@ -896,26 +896,27 @@ void DebuggerEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &re
if (result.success) { if (result.success) {
showMessage(_("NOTE: REMOTE SETUP DONE: GDB SERVER PORT: %1 QML PORT %2") showMessage(_("NOTE: REMOTE SETUP DONE: GDB SERVER PORT: %1 QML PORT %2")
.arg(result.gdbServerPort).arg(result.qmlServerPort)); .arg(result.gdbServerPort.number()).arg(result.qmlServerPort.number()));
if (d->remoteSetupState() != RemoteSetupCancelled) if (d->remoteSetupState() != RemoteSetupCancelled)
d->setRemoteSetupState(RemoteSetupSucceeded); d->setRemoteSetupState(RemoteSetupSucceeded);
if (result.gdbServerPort != InvalidPid) { if (result.gdbServerPort.isValid()) {
QString &rc = d->m_runParameters.remoteChannel; QString &rc = d->m_runParameters.remoteChannel;
const int sepIndex = rc.lastIndexOf(QLatin1Char(':')); const int sepIndex = rc.lastIndexOf(QLatin1Char(':'));
if (sepIndex != -1) { if (sepIndex != -1) {
rc.replace(sepIndex + 1, rc.count() - sepIndex - 1, rc.replace(sepIndex + 1, rc.count() - sepIndex - 1,
QString::number(result.gdbServerPort)); QString::number(result.gdbServerPort.number()));
} }
} else if (result.inferiorPid != InvalidPid && runParameters().startMode == AttachExternal) { } else if (result.inferiorPid != InvalidPid && runParameters().startMode == AttachExternal) {
// e.g. iOS Simulator // e.g. iOS Simulator
runParameters().attachPID = result.inferiorPid; runParameters().attachPID = result.inferiorPid;
} }
if (result.qmlServerPort != InvalidPort) { if (result.qmlServerPort.isValid()) {
d->m_runParameters.qmlServerPort = result.qmlServerPort; d->m_runParameters.qmlServerPort = result.qmlServerPort;
d->m_runParameters.inferior.commandLineArguments.replace(_("%qml_port%"), QString::number(result.qmlServerPort)); d->m_runParameters.inferior.commandLineArguments.replace(
_("%qml_port%"), QString::number(result.qmlServerPort.number()));
} }
} else { } else {

View File

@@ -2112,8 +2112,10 @@ void DebuggerPluginPrivate::attachToQmlPort()
const QVariant qmlServerPort = configValue("LastQmlServerPort"); const QVariant qmlServerPort = configValue("LastQmlServerPort");
if (qmlServerPort.isValid()) if (qmlServerPort.isValid())
dlg.setPort(qmlServerPort.toInt()); dlg.setPort(qmlServerPort.toInt());
else if (rp.qmlServerPort.isValid())
dlg.setPort(rp.qmlServerPort.number());
else else
dlg.setPort(rp.qmlServerPort); dlg.setPort(-1);
const Id kitId = Id::fromSetting(configValue("LastProfile")); const Id kitId = Id::fromSetting(configValue("LastProfile"));
if (kitId.isValid()) if (kitId.isValid())
@@ -2132,7 +2134,7 @@ void DebuggerPluginPrivate::attachToQmlPort()
rp.connParams = device->sshParameters(); rp.connParams = device->sshParameters();
rp.qmlServerAddress = device->qmlProfilerHost(); rp.qmlServerAddress = device->qmlProfilerHost();
} }
rp.qmlServerPort = dlg.port(); rp.qmlServerPort = Utils::Port(dlg.port());
rp.startMode = AttachToRemoteProcess; rp.startMode = AttachToRemoteProcess;
rp.closeMode = KillAtClose; rp.closeMode = KillAtClose;
rp.languages = QmlLanguage; rp.languages = QmlLanguage;
@@ -2863,7 +2865,7 @@ static QString formatStartParameters(DebuggerRunParameters &sp)
} }
if (!sp.qmlServerAddress.isEmpty()) if (!sp.qmlServerAddress.isEmpty())
str << "QML server: " << sp.qmlServerAddress << ':' str << "QML server: " << sp.qmlServerAddress << ':'
<< sp.qmlServerPort << '\n'; << (sp.qmlServerPort.isValid() ? sp.qmlServerPort.number() : -1) << '\n';
if (!sp.remoteChannel.isEmpty()) if (!sp.remoteChannel.isEmpty())
str << "Remote: " << sp.remoteChannel << '\n'; str << "Remote: " << sp.remoteChannel << '\n';
str << "Sysroot: " << sp.sysRoot << '\n'; str << "Sysroot: " << sp.sysRoot << '\n';

View File

@@ -440,7 +440,7 @@ static DebuggerRunControl *doCreate(DebuggerRunParameters rp, RunConfiguration *
return 0; return 0;
} }
rp.qmlServerAddress = server.serverAddress().toString(); rp.qmlServerAddress = server.serverAddress().toString();
rp.qmlServerPort = server.serverPort(); rp.qmlServerPort = Utils::Port(server.serverPort());
// Makes sure that all bindings go through the JavaScript engine, so that // Makes sure that all bindings go through the JavaScript engine, so that
// breakpoints are actually hit! // breakpoints are actually hit!

View File

@@ -30,6 +30,7 @@
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/port.h>
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
@@ -44,14 +45,13 @@ namespace Debugger {
// Note: This is part of the "soft interface" of the debugger plugin. // Note: This is part of the "soft interface" of the debugger plugin.
// Do not add anything that needs implementation in a .cpp file. // Do not add anything that needs implementation in a .cpp file.
const int InvalidPort = -1;
const qint64 InvalidPid = -1; const qint64 InvalidPid = -1;
class DEBUGGER_EXPORT RemoteSetupResult class DEBUGGER_EXPORT RemoteSetupResult
{ {
public: public:
int gdbServerPort = InvalidPort; Utils::Port gdbServerPort;
int qmlServerPort = InvalidPort; Utils::Port qmlServerPort;
qint64 inferiorPid = InvalidPid; qint64 inferiorPid = InvalidPid;
bool success = false; bool success = false;
QString reason; QString reason;
@@ -73,7 +73,7 @@ public:
// Used by Qml debugging. // Used by Qml debugging.
QString qmlServerAddress; QString qmlServerAddress;
int qmlServerPort = InvalidPort; Utils::Port qmlServerPort;
// Used by general remote debugging. // Used by general remote debugging.
QString remoteChannel; QString remoteChannel;

View File

@@ -108,8 +108,8 @@ void GdbServerStarter::run()
void GdbServerStarter::portListReady() void GdbServerStarter::portListReady()
{ {
PortList ports = d->device->freePorts(); PortList ports = d->device->freePorts();
const int port = d->gatherer.getNextFreePort(&ports); const Port port = d->gatherer.getNextFreePort(&ports);
if (port == -1) { if (!port.isValid()) {
QTC_ASSERT(false, /**/); QTC_ASSERT(false, /**/);
emit logMessage(tr("Process aborted")); emit logMessage(tr("Process aborted"));
return; return;
@@ -130,7 +130,7 @@ void GdbServerStarter::portListReady()
if (gdbServerPath.isEmpty()) if (gdbServerPath.isEmpty())
gdbServerPath = "gdbserver"; gdbServerPath = "gdbserver";
QByteArray cmd = gdbServerPath + " --attach :" QByteArray cmd = gdbServerPath + " --attach :"
+ QByteArray::number(port) + ' ' + QByteArray::number(d->process.pid); + QByteArray::number(port.number()) + ' ' + QByteArray::number(d->process.pid);
logMessage(tr("Running command: %1").arg(QString::fromLatin1(cmd))); logMessage(tr("Running command: %1").arg(QString::fromLatin1(cmd)));
d->runner.run(cmd, d->device->sshParameters()); d->runner.run(cmd, d->device->sshParameters());
} }

View File

@@ -347,7 +347,7 @@ void QmlEngine::connectionEstablished()
notifyEngineRunAndInferiorRunOk(); notifyEngineRunAndInferiorRunOk();
} }
void QmlEngine::tryToConnect(quint16 port) void QmlEngine::tryToConnect(Utils::Port port)
{ {
showMessage(QLatin1String("QML Debugger: No application output received in time, trying to connect ..."), LogStatus); showMessage(QLatin1String("QML Debugger: No application output received in time, trying to connect ..."), LogStatus);
d->retryOnConnectFail = true; d->retryOnConnectFail = true;
@@ -366,7 +366,7 @@ void QmlEngine::tryToConnect(quint16 port)
} }
} }
void QmlEngine::beginConnection(quint16 port) void QmlEngine::beginConnection(Utils::Port port)
{ {
d->noDebugOutputTimer.stop(); d->noDebugOutputTimer.stop();
@@ -391,13 +391,13 @@ void QmlEngine::beginConnection(quint16 port)
* the connection will be closed again (instead of returning the "connection refused" * the connection will be closed again (instead of returning the "connection refused"
* error that we expect). * error that we expect).
*/ */
if (runParameters().qmlServerPort > 0) if (runParameters().qmlServerPort.isValid())
port = runParameters().qmlServerPort; port = runParameters().qmlServerPort;
if (!d->connection || d->connection->isConnected()) if (!d->connection || d->connection->isConnected())
return; return;
d->connection->connectToHost(host, port); d->connection->connectToHost(host, port.number());
//A timeout to check the connection state //A timeout to check the connection state
d->connectionTimer.start(); d->connectionTimer.start();
@@ -563,7 +563,7 @@ void QmlEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
DebuggerEngine::notifyEngineRemoteSetupFinished(result); DebuggerEngine::notifyEngineRemoteSetupFinished(result);
if (result.success) { if (result.success) {
if (result.qmlServerPort != InvalidPort) if (result.qmlServerPort.isValid())
runParameters().qmlServerPort = result.qmlServerPort; runParameters().qmlServerPort = result.qmlServerPort;
notifyEngineSetupOk(); notifyEngineSetupOk();
@@ -587,7 +587,7 @@ void QmlEngine::notifyEngineRemoteServerRunning(const QByteArray &serverChannel,
bool ok = false; bool ok = false;
quint16 qmlPort = serverChannel.toUInt(&ok); quint16 qmlPort = serverChannel.toUInt(&ok);
if (ok) if (ok)
runParameters().qmlServerPort = qmlPort; runParameters().qmlServerPort = Utils::Port(qmlPort);
else else
qWarning() << tr("QML debugging port not set: Unable to convert %1 to unsigned int.").arg(QString::fromLatin1(serverChannel)); qWarning() << tr("QML debugging port not set: Unable to convert %1 to unsigned int.").arg(QString::fromLatin1(serverChannel));

View File

@@ -60,8 +60,8 @@ private slots:
void errorMessageBoxFinished(int result); void errorMessageBoxFinished(int result);
void updateCurrentContext(); void updateCurrentContext();
void tryToConnect(quint16 port = 0); void tryToConnect(Utils::Port port = Utils::Port());
void beginConnection(quint16 port = 0); void beginConnection(Utils::Port port = Utils::Port());
void connectionEstablished(); void connectionEstablished();
void connectionStartupFailed(); void connectionStartupFailed();
void appStartupFailed(const QString &errorMessage); void appStartupFailed(const QString &errorMessage);

View File

@@ -97,13 +97,13 @@ void IosAnalyzeSupport::qmlServerReady()
m_runControl->notifyRemoteSetupDone(m_qmlPort); m_runControl->notifyRemoteSetupDone(m_qmlPort);
} }
void IosAnalyzeSupport::handleServerPorts(int gdbServerPort, int qmlPort) void IosAnalyzeSupport::handleServerPorts(Utils::Port gdbServerPort, Utils::Port qmlPort)
{ {
Q_UNUSED(gdbServerPort); Q_UNUSED(gdbServerPort);
m_qmlPort = qmlPort; m_qmlPort = qmlPort;
} }
void IosAnalyzeSupport::handleGotInferiorPid(qint64 pid, int qmlPort) void IosAnalyzeSupport::handleGotInferiorPid(qint64 pid, Utils::Port qmlPort)
{ {
Q_UNUSED(pid); Q_UNUSED(pid);
m_qmlPort = qmlPort; m_qmlPort = qmlPort;

View File

@@ -28,6 +28,7 @@
#include "iosrunconfiguration.h" #include "iosrunconfiguration.h"
#include <qmldebug/qmloutputparser.h> #include <qmldebug/qmloutputparser.h>
#include <utils/port.h>
#include <QProcess> #include <QProcess>
#include <QObject> #include <QObject>
@@ -51,8 +52,8 @@ public:
private: private:
void qmlServerReady(); void qmlServerReady();
void handleServerPorts(int gdbServerFd, int qmlPort); void handleServerPorts(Utils::Port gdbServerPort, Utils::Port qmlPort);
void handleGotInferiorPid(qint64 pid, int qmlPort); void handleGotInferiorPid(qint64 pid, Utils::Port qmlPort);
void handleRemoteProcessFinished(bool cleanEnd); void handleRemoteProcessFinished(bool cleanEnd);
void handleRemoteOutput(const QString &output); void handleRemoteOutput(const QString &output);
@@ -61,7 +62,7 @@ private:
Debugger::AnalyzerRunControl *m_runControl; Debugger::AnalyzerRunControl *m_runControl;
IosRunner * const m_runner; IosRunner * const m_runner;
QmlDebug::QmlOutputParser m_outputParser; QmlDebug::QmlOutputParser m_outputParser;
int m_qmlPort; Utils::Port m_qmlPort;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -181,18 +181,19 @@ IosDebugSupport::~IosDebugSupport()
{ {
} }
void IosDebugSupport::handleServerPorts(int gdbServerPort, int qmlPort) void IosDebugSupport::handleServerPorts(Utils::Port gdbServerPort, Utils::Port qmlPort)
{ {
RemoteSetupResult result; RemoteSetupResult result;
result.gdbServerPort = gdbServerPort; result.gdbServerPort = gdbServerPort;
result.qmlServerPort = qmlPort; result.qmlServerPort = qmlPort;
result.success = gdbServerPort > 0 || (m_runner && !m_runner->cppDebug() && qmlPort > 0); result.success = gdbServerPort.isValid()
|| (m_runner && !m_runner->cppDebug() && qmlPort.isValid());
if (!result.success) if (!result.success)
result.reason = tr("Could not get debug server file descriptor."); result.reason = tr("Could not get debug server file descriptor.");
m_runControl->notifyEngineRemoteSetupFinished(result); m_runControl->notifyEngineRemoteSetupFinished(result);
} }
void IosDebugSupport::handleGotInferiorPid(qint64 pid, int qmlPort) void IosDebugSupport::handleGotInferiorPid(qint64 pid, Utils::Port qmlPort)
{ {
RemoteSetupResult result; RemoteSetupResult result;
result.qmlServerPort = qmlPort; result.qmlServerPort = qmlPort;

View File

@@ -50,8 +50,8 @@ public:
~IosDebugSupport(); ~IosDebugSupport();
private: private:
void handleServerPorts(int gdbServerFd, int qmlPort); void handleServerPorts(Utils::Port gdbServerPort, Utils::Port qmlPort);
void handleGotInferiorPid(qint64, int qmlPort); void handleGotInferiorPid(qint64, Utils::Port qmlPort);
void handleRemoteProcessFinished(bool cleanEnd); void handleRemoteProcessFinished(bool cleanEnd);
void handleRemoteOutput(const QString &output); void handleRemoteOutput(const QString &output);

View File

@@ -88,8 +88,8 @@ IosDevice::IosDevice()
setDisplayName(IosDevice::name()); setDisplayName(IosDevice::name());
setDeviceState(DeviceDisconnected); setDeviceState(DeviceDisconnected);
Utils::PortList ports; Utils::PortList ports;
ports.addRange(Constants::IOS_DEVICE_PORT_START, ports.addRange(Utils::Port(Constants::IOS_DEVICE_PORT_START),
Constants::IOS_DEVICE_PORT_END); Utils::Port(Constants::IOS_DEVICE_PORT_END));
setFreePorts(ports); setFreePorts(ports);
} }
@@ -200,12 +200,12 @@ QString IosDevice::osVersion() const
return m_extraInfo.value(QLatin1String("osVersion")); return m_extraInfo.value(QLatin1String("osVersion"));
} }
quint16 IosDevice::nextPort() const Utils::Port IosDevice::nextPort() const
{ {
// use qrand instead? // use qrand instead?
if (++m_lastPort >= Constants::IOS_DEVICE_PORT_END) if (++m_lastPort >= Constants::IOS_DEVICE_PORT_END)
m_lastPort = Constants::IOS_DEVICE_PORT_START; m_lastPort = Constants::IOS_DEVICE_PORT_START;
return m_lastPort; return Utils::Port(m_lastPort);
} }
bool IosDevice::canAutoDetectPorts() const bool IosDevice::canAutoDetectPorts() const

View File

@@ -66,7 +66,7 @@ public:
QString uniqueDeviceID() const; QString uniqueDeviceID() const;
IosDevice(const QString &uid); IosDevice(const QString &uid);
QString osVersion() const; QString osVersion() const;
quint16 nextPort() const; Utils::Port nextPort() const;
bool canAutoDetectPorts() const override; bool canAutoDetectPorts() const override;
static QString name(); static QString name();

View File

@@ -76,7 +76,7 @@ QString IosRunner::bundlePath()
QStringList IosRunner::extraArgs() QStringList IosRunner::extraArgs()
{ {
QStringList res = m_arguments; QStringList res = m_arguments;
if (m_qmlPort != 0) if (m_qmlPort.isValid())
res << QmlDebug::qmlDebugTcpArguments(m_qmlDebugServices, m_qmlPort); res << QmlDebug::qmlDebugTcpArguments(m_qmlDebugServices, m_qmlPort);
return res; return res;
} }
@@ -113,7 +113,7 @@ void IosRunner::start()
emit finished(m_cleanExit); emit finished(m_cleanExit);
} }
m_cleanExit = false; m_cleanExit = false;
m_qmlPort = 0; m_qmlPort = Utils::Port();
if (!QFileInfo::exists(m_bundleDir)) { if (!QFileInfo::exists(m_bundleDir)) {
TaskHub::addTask(Task::Warning, TaskHub::addTask(Task::Warning,
tr("Could not find %1.").arg(m_bundleDir), tr("Could not find %1.").arg(m_bundleDir),
@@ -177,7 +177,8 @@ void IosRunner::handleDidStartApp(IosToolHandler *handler, const QString &bundle
} }
void IosRunner::handleGotServerPorts(IosToolHandler *handler, const QString &bundlePath, void IosRunner::handleGotServerPorts(IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int gdbPort, int qmlPort) const QString &deviceId, Utils::Port gdbPort,
Utils::Port qmlPort)
{ {
Q_UNUSED(bundlePath); Q_UNUSED(deviceId); Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
m_qmlPort = qmlPort; m_qmlPort = qmlPort;
@@ -200,8 +201,8 @@ void IosRunner::handleAppOutput(IosToolHandler *handler, const QString &output)
QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)...")); QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)..."));
int index = qmlPortRe.indexIn(output); int index = qmlPortRe.indexIn(output);
QString res(output); QString res(output);
if (index != -1 && m_qmlPort) if (index != -1 && m_qmlPort.isValid())
res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort)); res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort.number()));
emit appOutput(res); emit appOutput(res);
} }
@@ -222,8 +223,8 @@ void IosRunner::handleErrorMsg(IosToolHandler *handler, const QString &msg)
} }
QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)...")); QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)..."));
int index = qmlPortRe.indexIn(msg); int index = qmlPortRe.indexIn(msg);
if (index != -1 && m_qmlPort) if (index != -1 && m_qmlPort.isValid())
res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort)); res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort.number()));
emit errorMsg(res); emit errorMsg(res);
} }

View File

@@ -66,8 +66,8 @@ public slots:
signals: signals:
void didStartApp(Ios::IosToolHandler::OpStatus status); void didStartApp(Ios::IosToolHandler::OpStatus status);
void gotServerPorts(int gdbPort, int qmlPort); void gotServerPorts(Utils::Port gdbPort, Utils::Port qmlPort);
void gotInferiorPid(qint64 pid, int); void gotInferiorPid(qint64 pid, Utils::Port qmlPort);
void appOutput(const QString &output); void appOutput(const QString &output);
void errorMsg(const QString &msg); void errorMsg(const QString &msg);
void finished(bool cleanExit); void finished(bool cleanExit);
@@ -76,7 +76,7 @@ private:
void handleDidStartApp(Ios::IosToolHandler *handler, const QString &bundlePath, void handleDidStartApp(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, Ios::IosToolHandler::OpStatus status); const QString &deviceId, Ios::IosToolHandler::OpStatus status);
void handleGotServerPorts(Ios::IosToolHandler *handler, const QString &bundlePath, void handleGotServerPorts(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int gdbPort, int qmlPort); const QString &deviceId, Utils::Port gdbPort, Utils::Port qmlPort);
void handleGotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath, void handleGotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, qint64 pid); const QString &deviceId, qint64 pid);
void handleAppOutput(Ios::IosToolHandler *handler, const QString &output); void handleAppOutput(Ios::IosToolHandler *handler, const QString &output);
@@ -93,7 +93,7 @@ private:
QmlDebug::QmlDebugServicesPreset m_qmlDebugServices; QmlDebug::QmlDebugServicesPreset m_qmlDebugServices;
bool m_cleanExit; bool m_cleanExit;
quint16 m_qmlPort; Utils::Port m_qmlPort;
qint64 m_pid; qint64 m_pid;
}; };

View File

@@ -28,6 +28,7 @@
#include "iostoolhandler.h" #include "iostoolhandler.h"
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <utils/port.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QMapIterator> #include <QMapIterator>
@@ -171,7 +172,7 @@ QVariantMap IosSimulator::toMap() const
return res; return res;
} }
quint16 IosSimulator::nextPort() const Utils::Port IosSimulator::nextPort() const
{ {
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
// use qrand instead? // use qrand instead?
@@ -192,7 +193,7 @@ quint16 IosSimulator::nextPort() const
|| portVerifier.exitCode() != 0) || portVerifier.exitCode() != 0)
break; break;
} }
return m_lastPort; return Utils::Port(m_lastPort);
} }
bool IosSimulator::canAutoDetectPorts() const bool IosSimulator::canAutoDetectPorts() const

View File

@@ -79,7 +79,7 @@ public:
ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override; ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override;
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override; QVariantMap toMap() const override;
quint16 nextPort() const; Utils::Port nextPort() const;
bool canAutoDetectPorts() const override; bool canAutoDetectPorts() const override;
ProjectExplorer::IDevice::Ptr clone() const override; ProjectExplorer::IDevice::Ptr clone() const override;

View File

@@ -141,8 +141,8 @@ public:
IosToolHandler::OpStatus status); IosToolHandler::OpStatus status);
void didStartApp(const QString &bundlePath, const QString &deviceId, void didStartApp(const QString &bundlePath, const QString &deviceId,
IosToolHandler::OpStatus status); IosToolHandler::OpStatus status);
void gotServerPorts(const QString &bundlePath, const QString &deviceId, int gdbPort, void gotServerPorts(const QString &bundlePath, const QString &deviceId, Utils::Port gdbPort,
int qmlPort); Utils::Port qmlPort);
void gotInferiorPid(const QString &bundlePath, const QString &deviceId, qint64 pid); void gotInferiorPid(const QString &bundlePath, const QString &deviceId, qint64 pid);
void deviceInfo(const QString &deviceId, const IosToolHandler::Dict &info); void deviceInfo(const QString &deviceId, const IosToolHandler::Dict &info);
void appOutput(const QString &output); void appOutput(const QString &output);
@@ -306,8 +306,8 @@ void IosToolHandlerPrivate::didStartApp(const QString &bundlePath, const QString
emit q->didStartApp(q, bundlePath, deviceId, status); emit q->didStartApp(q, bundlePath, deviceId, status);
} }
void IosToolHandlerPrivate::gotServerPorts(const QString &bundlePath, void IosToolHandlerPrivate::gotServerPorts(const QString &bundlePath, const QString &deviceId,
const QString &deviceId, int gdbPort, int qmlPort) Utils::Port gdbPort, Utils::Port qmlPort)
{ {
emit q->gotServerPorts(q, bundlePath, deviceId, gdbPort, qmlPort); emit q->gotServerPorts(q, bundlePath, deviceId, gdbPort, qmlPort);
} }
@@ -445,8 +445,10 @@ void IosToolHandlerPrivate::processXml()
} else if (elName == QLatin1String("server_ports")) { } else if (elName == QLatin1String("server_ports")) {
stack.append(ParserState(ParserState::ServerPorts)); stack.append(ParserState(ParserState::ServerPorts));
QXmlStreamAttributes attributes = outputParser.attributes(); QXmlStreamAttributes attributes = outputParser.attributes();
int gdbServerPort = attributes.value(QLatin1String("gdb_server")).toString().toInt(); Utils::Port gdbServerPort(
int qmlServerPort = attributes.value(QLatin1String("qml_server")).toString().toInt(); attributes.value(QLatin1String("gdb_server")).toString().toInt());
Utils::Port qmlServerPort(
attributes.value(QLatin1String("qml_server")).toString().toInt());
gotServerPorts(bundlePath, deviceId, gdbServerPort, qmlServerPort); gotServerPorts(bundlePath, deviceId, gdbServerPort, qmlServerPort);
} else { } else {
qCWarning(toolHandlerLog) << "unexpected element " << elName; qCWarning(toolHandlerLog) << "unexpected element " << elName;

View File

@@ -25,6 +25,8 @@
#pragma once #pragma once
#include <utils/port.h>
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
#include <QString> #include <QString>
@@ -72,7 +74,7 @@ signals:
void didStartApp(Ios::IosToolHandler *handler, const QString &bundlePath, void didStartApp(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, Ios::IosToolHandler::OpStatus status); const QString &deviceId, Ios::IosToolHandler::OpStatus status);
void gotServerPorts(Ios::IosToolHandler *handler, const QString &bundlePath, void gotServerPorts(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int gdbPort, int qmlPort); const QString &deviceId, Utils::Port gdbPort, Utils::Port qmlPort);
void gotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath, void gotInferiorPid(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, qint64 pid); const QString &deviceId, qint64 pid);
void deviceInfo(Ios::IosToolHandler *handler, const QString &deviceId, void deviceInfo(Ios::IosToolHandler *handler, const QString &deviceId,

View File

@@ -25,6 +25,7 @@
#include "deviceusedportsgatherer.h" #include "deviceusedportsgatherer.h"
#include <utils/port.h>
#include <utils/portlist.h> #include <utils/portlist.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
@@ -42,7 +43,7 @@ class DeviceUsedPortsGathererPrivate
public: public:
SshConnection *connection; SshConnection *connection;
SshRemoteProcess::Ptr process; SshRemoteProcess::Ptr process;
QList<int> usedPorts; QList<Port> usedPorts;
QByteArray remoteStdout; QByteArray remoteStdout;
QByteArray remoteStderr; QByteArray remoteStderr;
IDevice::ConstPtr device; IDevice::ConstPtr device;
@@ -110,17 +111,17 @@ void DeviceUsedPortsGatherer::stop()
d->connection = 0; d->connection = 0;
} }
int DeviceUsedPortsGatherer::getNextFreePort(PortList *freePorts) const Port DeviceUsedPortsGatherer::getNextFreePort(PortList *freePorts) const
{ {
while (freePorts->hasMore()) { while (freePorts->hasMore()) {
const int port = freePorts->getNext(); const Port port = freePorts->getNext();
if (!d->usedPorts.contains(port)) if (!d->usedPorts.contains(port))
return port; return port;
} }
return -1; return Port();
} }
QList<int> DeviceUsedPortsGatherer::usedPorts() const QList<Port> DeviceUsedPortsGatherer::usedPorts() const
{ {
return d->usedPorts; return d->usedPorts;
} }
@@ -128,8 +129,8 @@ QList<int> DeviceUsedPortsGatherer::usedPorts() const
void DeviceUsedPortsGatherer::setupUsedPorts() void DeviceUsedPortsGatherer::setupUsedPorts()
{ {
d->usedPorts.clear(); d->usedPorts.clear();
const QList<int> usedPorts = d->device->portsGatheringMethod()->usedPorts(d->remoteStdout); const QList<Port> usedPorts = d->device->portsGatheringMethod()->usedPorts(d->remoteStdout);
foreach (const int port, usedPorts) { foreach (const Port port, usedPorts) {
if (d->device->freePorts().contains(port)) if (d->device->freePorts().contains(port))
d->usedPorts << port; d->usedPorts << port;
} }

View File

@@ -27,7 +27,10 @@
#include "idevice.h" #include "idevice.h"
namespace Utils { class PortList; } namespace Utils {
class Port;
class PortList;
} // namespace Utils
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { class DeviceUsedPortsGathererPrivate; } namespace Internal { class DeviceUsedPortsGathererPrivate; }
@@ -42,8 +45,8 @@ public:
void start(const ProjectExplorer::IDevice::ConstPtr &device); void start(const ProjectExplorer::IDevice::ConstPtr &device);
void stop(); void stop();
int getNextFreePort(Utils::PortList *freePorts) const; // returns -1 if no more are left Utils::Port getNextFreePort(Utils::PortList *freePorts) const; // returns -1 if no more are left
QList<int> usedPorts() const; QList<Utils::Port> usedPorts() const;
signals: signals:
void error(const QString &errMsg); void error(const QString &errMsg);

View File

@@ -44,6 +44,7 @@ namespace QSsh { class SshConnectionParameters; }
namespace Utils { namespace Utils {
class Environment; class Environment;
class PortList; class PortList;
class Port;
} // Utils } // Utils
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -103,7 +104,7 @@ public:
virtual ~PortsGatheringMethod() = default; virtual ~PortsGatheringMethod() = default;
virtual QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const = 0; virtual QByteArray commandLine(QAbstractSocket::NetworkLayerProtocol protocol) const = 0;
virtual QList<int> usedPorts(const QByteArray &commandOutput) const = 0; virtual QList<Utils::Port> usedPorts(const QByteArray &commandOutput) const = 0;
}; };
// See cpp file for documentation. // See cpp file for documentation.

View File

@@ -51,16 +51,16 @@ QString LocalQmlProfilerRunner::findFreeSocket()
} }
} }
quint16 LocalQmlProfilerRunner::findFreePort(QString &host) Utils::Port LocalQmlProfilerRunner::findFreePort(QString &host)
{ {
QTcpServer server; QTcpServer server;
if (!server.listen(QHostAddress::LocalHost) if (!server.listen(QHostAddress::LocalHost)
&& !server.listen(QHostAddress::LocalHostIPv6)) { && !server.listen(QHostAddress::LocalHostIPv6)) {
qWarning() << "Cannot open port on host for QML profiling."; qWarning() << "Cannot open port on host for QML profiling.";
return 0; return Utils::Port();
} }
host = server.serverAddress().toString(); host = server.serverAddress().toString();
return server.serverPort(); return Utils::Port(server.serverPort());
} }
LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration, LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration,
@@ -102,9 +102,12 @@ void LocalQmlProfilerRunner::start()
runnable.runMode = ApplicationLauncher::Gui; runnable.runMode = ApplicationLauncher::Gui;
if (QmlProfilerPlugin::debugOutput) { if (QmlProfilerPlugin::debugOutput) {
QString portOrSocket = m_configuration.socket.isEmpty() ?
QString::number(m_configuration.port.isValid() ?
m_configuration.port.number() : -1) :
m_configuration.socket;
qWarning("QmlProfiler: Launching %s:%s", qPrintable(m_configuration.debuggee.executable), qWarning("QmlProfiler: Launching %s:%s", qPrintable(m_configuration.debuggee.executable),
qPrintable(m_configuration.socket.isEmpty() ? qPrintable(portOrSocket));
QString::number(m_configuration.port) : m_configuration.socket));
} }
connect(&m_launcher, &ApplicationLauncher::processExited, connect(&m_launcher, &ApplicationLauncher::processExited,

View File

@@ -27,6 +27,7 @@
#include "qmlprofiler_global.h" #include "qmlprofiler_global.h"
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/port.h>
#include <projectexplorer/applicationlauncher.h> #include <projectexplorer/applicationlauncher.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
@@ -40,14 +41,14 @@ class QMLPROFILER_EXPORT LocalQmlProfilerRunner : public QObject
public: public:
struct Configuration { struct Configuration {
ProjectExplorer::StandardRunnable debuggee; ProjectExplorer::StandardRunnable debuggee;
quint16 port; Utils::Port port;
QString socket; QString socket;
}; };
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine); LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine);
~LocalQmlProfilerRunner(); ~LocalQmlProfilerRunner();
static quint16 findFreePort(QString &host); static Utils::Port findFreePort(QString &host);
static QString findFreeSocket(); static QString findFreeSocket();
signals: signals:

View File

@@ -55,7 +55,7 @@ public:
QString localSocket; QString localSocket;
QString tcpHost; QString tcpHost;
quint64 tcpPort; Utils::Port tcpPort;
QString sysroot; QString sysroot;
quint32 flushInterval; quint32 flushInterval;
bool aggregateTraces; bool aggregateTraces;
@@ -108,7 +108,7 @@ void QmlProfilerClientManager::setAggregateTraces(bool aggregateTraces)
d->aggregateTraces = aggregateTraces; d->aggregateTraces = aggregateTraces;
} }
void QmlProfilerClientManager::setTcpConnection(QString host, quint64 port) void QmlProfilerClientManager::setTcpConnection(QString host, Utils::Port port)
{ {
d->tcpHost = host; d->tcpHost = host;
d->tcpPort = port; d->tcpPort = port;
@@ -118,7 +118,7 @@ void QmlProfilerClientManager::setTcpConnection(QString host, quint64 port)
void QmlProfilerClientManager::setLocalSocket(QString file) void QmlProfilerClientManager::setLocalSocket(QString file)
{ {
d->localSocket = file; d->localSocket = file;
d->tcpPort = 0; d->tcpPort = Utils::Port();
connectLocalClient(file); connectLocalClient(file);
} }
@@ -133,7 +133,7 @@ void QmlProfilerClientManager::discardPendingData()
clearBufferedData(); clearBufferedData();
} }
void QmlProfilerClientManager::connectTcpClient(quint16 port) void QmlProfilerClientManager::connectTcpClient(Utils::Port port)
{ {
if (d->connection) { if (d->connection) {
if (port == d->tcpPort) { if (port == d->tcpPort) {
@@ -147,7 +147,7 @@ void QmlProfilerClientManager::connectTcpClient(quint16 port)
createConnection(); createConnection();
d->connectionTimer.start(); d->connectionTimer.start();
d->tcpPort = port; d->tcpPort = port;
d->connection->connectToHost(d->tcpHost, d->tcpPort); d->connection->connectToHost(d->tcpHost, d->tcpPort.number());
} }
void QmlProfilerClientManager::connectLocalClient(const QString &file) void QmlProfilerClientManager::connectLocalClient(const QString &file)
@@ -269,7 +269,7 @@ void QmlProfilerClientManager::tryToConnect()
d->connection = 0; d->connection = 0;
connectTcpClient(d->tcpPort); connectTcpClient(d->tcpPort);
} else if (!d->connection->isConnecting()) { } else if (!d->connection->isConnecting()) {
d->connection->connectToHost(d->tcpHost, d->tcpPort); d->connection->connectToHost(d->tcpHost, d->tcpPort.number());
} }
} else if (d->connectionAttempts == 50) { } else if (d->connectionAttempts == 50) {
d->connectionTimer.stop(); d->connectionTimer.stop();

View File

@@ -27,6 +27,7 @@
#include "qmlprofilerstatemanager.h" #include "qmlprofilerstatemanager.h"
#include <qmldebug/qmlprofilereventlocation.h> #include <qmldebug/qmlprofilereventlocation.h>
#include <utils/port.h>
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
@@ -45,7 +46,7 @@ public:
~QmlProfilerClientManager(); ~QmlProfilerClientManager();
void registerProfilerStateManager(QmlProfilerStateManager *profilerState); void registerProfilerStateManager(QmlProfilerStateManager *profilerState);
void setTcpConnection(QString host, quint64 port); void setTcpConnection(QString host, Utils::Port port);
void setLocalSocket(QString file); void setLocalSocket(QString file);
void clearBufferedData(); void clearBufferedData();
@@ -63,7 +64,7 @@ signals:
void connectionClosed(); void connectionClosed();
public slots: public slots:
void connectTcpClient(quint16 port); void connectTcpClient(Utils::Port port);
void connectLocalClient(const QString &file); void connectLocalClient(const QString &file);
void disconnectClient(); void disconnectClient();

View File

@@ -86,15 +86,15 @@ QmlProfilerRunControl::QmlProfilerRunControl(RunConfiguration *runConfiguration,
d->m_noDebugOutputTimer.setSingleShot(true); d->m_noDebugOutputTimer.setSingleShot(true);
d->m_noDebugOutputTimer.setInterval(4000); d->m_noDebugOutputTimer.setInterval(4000);
connect(&d->m_noDebugOutputTimer, &QTimer::timeout, connect(&d->m_noDebugOutputTimer, &QTimer::timeout,
this, [this](){processIsRunning(0);}); this, [this](){processIsRunning(Utils::Port());});
d->m_outputParser.setNoOutputText(ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput()); d->m_outputParser.setNoOutputText(ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput());
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort, connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort,
this, &QmlProfilerRunControl::processIsRunning); this, &QmlProfilerRunControl::processIsRunning);
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::noOutputMessage, connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::noOutputMessage,
this, [this](){processIsRunning(0);}); this, [this](){processIsRunning(Utils::Port());});
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::connectingToSocketMessage, connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::connectingToSocketMessage,
this, [this](){processIsRunning(0);}); this, [this](){processIsRunning(Utils::Port());});
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::errorMessage, connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::errorMessage,
this, &QmlProfilerRunControl::wrongSetupMessageBox); this, &QmlProfilerRunControl::wrongSetupMessageBox);
} }
@@ -114,7 +114,7 @@ void QmlProfilerRunControl::start()
QTC_ASSERT(connection().is<AnalyzerConnection>(), finished(); return); QTC_ASSERT(connection().is<AnalyzerConnection>(), finished(); return);
auto conn = connection().as<AnalyzerConnection>(); auto conn = connection().as<AnalyzerConnection>();
if (conn.analyzerPort != 0) if (conn.analyzerPort.isValid())
emit processRunning(conn.analyzerPort); emit processRunning(conn.analyzerPort);
else if (conn.analyzerSocket.isEmpty()) else if (conn.analyzerSocket.isEmpty())
d->m_noDebugOutputTimer.start(); d->m_noDebugOutputTimer.start();
@@ -236,19 +236,19 @@ void QmlProfilerRunControl::wrongSetupMessageBoxFinished(int button)
} }
} }
void QmlProfilerRunControl::notifyRemoteSetupDone(quint16 port) void QmlProfilerRunControl::notifyRemoteSetupDone(Utils::Port port)
{ {
d->m_noDebugOutputTimer.stop(); d->m_noDebugOutputTimer.stop();
emit processRunning(port); emit processRunning(port);
} }
void QmlProfilerRunControl::processIsRunning(quint16 port) void QmlProfilerRunControl::processIsRunning(Utils::Port port)
{ {
d->m_noDebugOutputTimer.stop(); d->m_noDebugOutputTimer.stop();
if (port == 0) if (!port.isValid())
port = connection().as<AnalyzerConnection>().analyzerPort; port = connection().as<AnalyzerConnection>().analyzerPort;
if (port != 0) if (port.isValid())
emit processRunning(port); emit processRunning(port);
} }

View File

@@ -45,7 +45,7 @@ public:
void registerProfilerStateManager( QmlProfilerStateManager *profilerState ); void registerProfilerStateManager( QmlProfilerStateManager *profilerState );
void notifyRemoteSetupDone(quint16 port) override; void notifyRemoteSetupDone(Utils::Port port) override;
void start() override; void start() override;
StopResult stop() override; StopResult stop() override;
bool isRunning() const override; bool isRunning() const override;
@@ -54,12 +54,12 @@ public:
void logApplicationMessage(const QString &msg, Utils::OutputFormat format) override; void logApplicationMessage(const QString &msg, Utils::OutputFormat format) override;
signals: signals:
void processRunning(quint16 port); void processRunning(Utils::Port port);
private: private:
void wrongSetupMessageBox(const QString &errorMessage); void wrongSetupMessageBox(const QString &errorMessage);
void wrongSetupMessageBoxFinished(int); void wrongSetupMessageBoxFinished(int);
void processIsRunning(quint16 port); void processIsRunning(Utils::Port port);
void profilerStateChanged(); void profilerStateChanged();
class QmlProfilerRunControlPrivate; class QmlProfilerRunControlPrivate;

View File

@@ -564,7 +564,7 @@ void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc)
connection.connParams = device->sshParameters(); connection.connParams = device->sshParameters();
connection.analyzerHost = device->qmlProfilerHost(); connection.analyzerHost = device->qmlProfilerHost();
} }
connection.analyzerPort = port; connection.analyzerPort = Utils::Port(port);
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc)); auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc));
runControl->setConnection(connection); runControl->setConnection(connection);

View File

@@ -117,10 +117,10 @@ void QnxAbstractRunSupport::handleError(const QString &)
{ {
} }
bool QnxAbstractRunSupport::setPort(int &port) bool QnxAbstractRunSupport::setPort(Utils::Port &port)
{ {
port = m_portsGatherer->getNextFreePort(&m_portList); port = m_portsGatherer->getNextFreePort(&m_portList);
if (port == -1) { if (!port.isValid()) {
handleError(tr("Not enough free ports on device for debugging.")); handleError(tr("Not enough free ports on device for debugging."));
return false; return false;
} }

View File

@@ -56,7 +56,7 @@ public:
QnxAbstractRunSupport(QnxRunConfiguration *runConfig, QObject *parent = 0); QnxAbstractRunSupport(QnxRunConfiguration *runConfig, QObject *parent = 0);
protected: protected:
bool setPort(int &port); bool setPort(Utils::Port &port);
virtual void startExecution() = 0; virtual void startExecution() = 0;
void setFinished(); void setFinished();

View File

@@ -97,7 +97,7 @@ void QnxAnalyzeSupport::startExecution()
if (state() == Inactive) if (state() == Inactive)
return; return;
if (!setPort(m_qmlPort) && m_qmlPort == -1) if (!setPort(m_qmlPort) && !m_qmlPort.isValid())
return; return;
setState(StartingRemoteProcess); setState(StartingRemoteProcess);
@@ -105,8 +105,8 @@ void QnxAnalyzeSupport::startExecution()
StandardRunnable r = m_runnable; StandardRunnable r = m_runnable;
if (!r.commandLineArguments.isEmpty()) if (!r.commandLineArguments.isEmpty())
r.commandLineArguments += QLatin1Char(' '); r.commandLineArguments += QLatin1Char(' ');
r.commandLineArguments r.commandLineArguments += QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices,
+= QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, m_qmlPort); m_qmlPort);
appRunner()->start(device(), r); appRunner()->start(device(), r);
} }

View File

@@ -67,7 +67,7 @@ private:
ProjectExplorer::StandardRunnable m_runnable; ProjectExplorer::StandardRunnable m_runnable;
Debugger::AnalyzerRunControl *m_runControl; Debugger::AnalyzerRunControl *m_runControl;
QmlDebug::QmlOutputParser m_outputParser; QmlDebug::QmlOutputParser m_outputParser;
int m_qmlPort; Utils::Port m_qmlPort;
Slog2InfoRunner *m_slog2Info; Slog2InfoRunner *m_slog2Info;
}; };

View File

@@ -105,14 +105,14 @@ void QnxAttachDebugSupport::launchPDebug()
{ {
Utils::PortList portList = m_device->freePorts(); Utils::PortList portList = m_device->freePorts();
m_pdebugPort = m_portsGatherer->getNextFreePort(&portList); m_pdebugPort = m_portsGatherer->getNextFreePort(&portList);
if (m_pdebugPort == -1) { if (!m_pdebugPort.isValid()) {
handleError(tr("No free ports for debugging.")); handleError(tr("No free ports for debugging."));
return; return;
} }
StandardRunnable r; StandardRunnable r;
r.executable = QLatin1String("pdebug"); r.executable = QLatin1String("pdebug");
r.commandLineArguments = QString::number(m_pdebugPort); r.commandLineArguments = QString::number(m_pdebugPort.number());
m_runner->start(m_device, r); m_runner->start(m_device, r);
} }
@@ -122,9 +122,11 @@ void QnxAttachDebugSupport::attachToProcess()
sp.attachPID = m_process.pid; sp.attachPID = m_process.pid;
sp.startMode = Debugger::AttachToRemoteServer; sp.startMode = Debugger::AttachToRemoteServer;
sp.closeMode = Debugger::DetachAtClose; sp.closeMode = Debugger::DetachAtClose;
sp.connParams.port = m_pdebugPort; sp.connParams.port = m_pdebugPort.number();
sp.remoteChannel = m_device->sshParameters().host + QLatin1Char(':') + QString::number(m_pdebugPort); sp.remoteChannel = m_device->sshParameters().host + QLatin1Char(':') +
sp.displayName = tr("Remote: \"%1:%2\" - Process %3").arg(sp.connParams.host).arg(m_pdebugPort).arg(m_process.pid); QString::number(m_pdebugPort.number());
sp.displayName = tr("Remote: \"%1:%2\" - Process %3").arg(sp.connParams.host)
.arg(m_pdebugPort.number()).arg(m_process.pid);
sp.inferior.executable = m_localExecutablePath; sp.inferior.executable = m_localExecutablePath;
sp.useCtrlCStub = true; sp.useCtrlCStub = true;

View File

@@ -28,6 +28,7 @@
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h> #include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/devicesupport/idevice.h>
#include <utils/port.h>
#include <QObject> #include <QObject>
@@ -71,7 +72,7 @@ private:
ProjectExplorer::DeviceUsedPortsGatherer *m_portsGatherer; ProjectExplorer::DeviceUsedPortsGatherer *m_portsGatherer;
Debugger::DebuggerRunControl *m_runControl = 0; Debugger::DebuggerRunControl *m_runControl = 0;
int m_pdebugPort = -1; Utils::Port m_pdebugPort;
QString m_projectSourceDirectory; QString m_projectSourceDirectory;
QString m_localExecutablePath; QString m_localExecutablePath;
}; };

View File

@@ -105,7 +105,7 @@ void QnxDebugSupport::startExecution()
QStringList arguments; QStringList arguments;
if (m_useCppDebugger) if (m_useCppDebugger)
arguments << QString::number(m_pdebugPort); arguments << QString::number(m_pdebugPort.number());
else if (m_useQmlDebugger && !m_useCppDebugger) else if (m_useQmlDebugger && !m_useCppDebugger)
arguments = Utils::QtcProcess::splitArgs( arguments = Utils::QtcProcess::splitArgs(
m_runControl->startParameters().inferior.commandLineArguments); m_runControl->startParameters().inferior.commandLineArguments);

View File

@@ -73,8 +73,8 @@ private:
Slog2InfoRunner *m_slog2Info; Slog2InfoRunner *m_slog2Info;
Debugger::DebuggerRunControl *m_runControl; Debugger::DebuggerRunControl *m_runControl;
int m_pdebugPort; Utils::Port m_pdebugPort;
int m_qmlPort; Utils::Port m_qmlPort;
bool m_useCppDebugger; bool m_useCppDebugger;
bool m_useQmlDebugger; bool m_useQmlDebugger;

View File

@@ -33,6 +33,7 @@
#include <projectexplorer/devicesupport/sshdeviceprocess.h> #include <projectexplorer/devicesupport/sshdeviceprocess.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/port.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QApplication> #include <QApplication>
@@ -66,16 +67,16 @@ class QnxPortsGatheringMethod : public PortsGatheringMethod
"done"; "done";
} }
QList<int> usedPorts(const QByteArray &output) const QList<Port> usedPorts(const QByteArray &output) const
{ {
QList<int> ports; QList<Port> ports;
QList<QByteArray> portStrings = output.split('\n'); QList<QByteArray> portStrings = output.split('\n');
portStrings.removeFirst(); portStrings.removeFirst();
foreach (const QByteArray &portString, portStrings) { foreach (const QByteArray &portString, portStrings) {
if (portString.isEmpty()) if (portString.isEmpty())
continue; continue;
bool ok; bool ok;
const int port = portString.toInt(&ok, 16); const Port port(portString.toInt(&ok, 16));
if (ok) { if (ok) {
if (!ports.contains(port)) if (!ports.contains(port))
ports << port; ports << port;

View File

@@ -75,7 +75,7 @@ static DebuggerStartParameters createDebuggerStartParameters(QnxRunConfiguration
auto aspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>(); auto aspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>();
if (aspect->useQmlDebugger()) { if (aspect->useQmlDebugger()) {
params.qmlServerAddress = device->sshParameters().host; params.qmlServerAddress = device->sshParameters().host;
params.qmlServerPort = 0; // QML port is handed out later params.qmlServerPort = Utils::Port(); // QML port is handed out later
} }
auto qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(k)); auto qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(k));
@@ -147,7 +147,7 @@ RunControl *QnxRunControlFactory::create(RunConfiguration *runConfig, Core::Id m
AnalyzerConnection connection; AnalyzerConnection connection;
connection.connParams = device->sshParameters(); connection.connParams = device->sshParameters();
connection.analyzerHost = connection.connParams.host; connection.analyzerHost = connection.connParams.host;
connection.analyzerPort = connection.connParams.port; connection.analyzerPort = Utils::Port(connection.connParams.port);
runControl->setConnection(connection); runControl->setConnection(connection);
auto analyzeSupport = new QnxAnalyzeSupport(rc, runControl); auto analyzeSupport = new QnxAnalyzeSupport(rc, runControl);
connect(runControl, &RunControl::finished, analyzeSupport, &QnxAnalyzeSupport::handleProfilingFinished); connect(runControl, &RunControl::finished, analyzeSupport, &QnxAnalyzeSupport::handleProfilingFinished);

View File

@@ -128,10 +128,10 @@ void AbstractRemoteLinuxRunSupport::setFinished()
d->state = Inactive; d->state = Inactive;
} }
bool AbstractRemoteLinuxRunSupport::setPort(int &port) bool AbstractRemoteLinuxRunSupport::setPort(Utils::Port &port)
{ {
port = d->portsGatherer.getNextFreePort(&d->portList); port = d->portsGatherer.getNextFreePort(&d->portList);
if (port == -1) { if (!port.isValid()) {
handleAdapterSetupFailed(tr("Not enough free ports on device for debugging.")); handleAdapterSetupFailed(tr("Not enough free ports on device for debugging."));
return false; return false;
} }

View File

@@ -28,6 +28,7 @@
#include "remotelinux_export.h" #include "remotelinux_export.h"
#include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/devicesupport/idevice.h>
#include <utils/port.h>
#include <QObject> #include <QObject>
@@ -68,7 +69,7 @@ protected:
virtual void handleAdapterSetupDone(); virtual void handleAdapterSetupDone();
void setFinished(); void setFinished();
bool setPort(int &port); bool setPort(Utils::Port &port);
const ProjectExplorer::IDevice::ConstPtr device() const; const ProjectExplorer::IDevice::ConstPtr device() const;
const ProjectExplorer::StandardRunnable &runnable() const; const ProjectExplorer::StandardRunnable &runnable() const;

View File

@@ -37,6 +37,7 @@
#include <projectexplorer/devicesupport/sshdeviceprocesslist.h> #include <projectexplorer/devicesupport/sshdeviceprocesslist.h>
#include <ssh/sshremoteprocessrunner.h> #include <ssh/sshremoteprocessrunner.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/port.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QTimer> #include <QTimer>
@@ -137,16 +138,16 @@ class LinuxPortsGatheringMethod : public PortsGatheringMethod
.arg(addressLength).arg(procFilePath).toUtf8(); .arg(addressLength).arg(procFilePath).toUtf8();
} }
QList<int> usedPorts(const QByteArray &output) const QList<Utils::Port> usedPorts(const QByteArray &output) const
{ {
QList<int> ports; QList<Utils::Port> ports;
QList<QByteArray> portStrings = output.split('\n'); QList<QByteArray> portStrings = output.split('\n');
portStrings.removeFirst(); portStrings.removeFirst();
foreach (const QByteArray &portString, portStrings) { foreach (const QByteArray &portString, portStrings) {
if (portString.isEmpty()) if (portString.isEmpty())
continue; continue;
bool ok; bool ok;
const int port = portString.toInt(&ok, 16); const Utils::Port port(portString.toInt(&ok, 16));
if (ok) { if (ok) {
if (!ports.contains(port)) if (!ports.contains(port))
ports << port; ports << port;

View File

@@ -26,6 +26,7 @@
#include "linuxdevicetester.h" #include "linuxdevicetester.h"
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h> #include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
#include <utils/port.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <ssh/sshremoteprocess.h> #include <ssh/sshremoteprocess.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
@@ -169,8 +170,8 @@ void GenericLinuxDeviceTester::handlePortListReady()
emit progressMessage(tr("All specified ports are available.") + QLatin1Char('\n')); emit progressMessage(tr("All specified ports are available.") + QLatin1Char('\n'));
} else { } else {
QString portList; QString portList;
foreach (const int port, d->portsGatherer.usedPorts()) foreach (const Utils::Port port, d->portsGatherer.usedPorts())
portList += QString::number(port) + QLatin1String(", "); portList += QString::number(port.number()) + QLatin1String(", ");
portList.remove(portList.count() - 2, 2); portList.remove(portList.count() - 2, 2);
emit errorMessage(tr("The following specified ports are currently in use: %1") emit errorMessage(tr("The following specified ports are currently in use: %1")
.arg(portList) + QLatin1Char('\n')); .arg(portList) + QLatin1Char('\n'));

View File

@@ -57,14 +57,13 @@ class RemoteLinuxAnalyzeSupportPrivate
public: public:
RemoteLinuxAnalyzeSupportPrivate(AnalyzerRunControl *rc, Core::Id runMode) RemoteLinuxAnalyzeSupportPrivate(AnalyzerRunControl *rc, Core::Id runMode)
: runControl(rc), : runControl(rc),
qmlProfiling(runMode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE), qmlProfiling(runMode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE)
qmlPort(-1)
{ {
} }
const QPointer<AnalyzerRunControl> runControl; const QPointer<AnalyzerRunControl> runControl;
bool qmlProfiling; bool qmlProfiling;
int qmlPort; Utils::Port qmlPort;
QmlDebug::QmlOutputParser outputParser; QmlDebug::QmlOutputParser outputParser;
}; };
@@ -135,8 +134,8 @@ void RemoteLinuxAnalyzeSupport::startExecution()
auto r = runnable(); auto r = runnable();
if (!r.commandLineArguments.isEmpty()) if (!r.commandLineArguments.isEmpty())
r.commandLineArguments.append(QLatin1Char(' ')); r.commandLineArguments.append(QLatin1Char(' '));
r.commandLineArguments r.commandLineArguments += QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices,
+= QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, d->qmlPort); d->qmlPort);
runner->start(device(), r); runner->start(device(), r);
} }

View File

@@ -60,8 +60,7 @@ public:
LinuxDeviceDebugSupportPrivate(const RunConfiguration *runConfig, DebuggerRunControl *runControl) LinuxDeviceDebugSupportPrivate(const RunConfiguration *runConfig, DebuggerRunControl *runControl)
: runControl(runControl), : runControl(runControl),
qmlDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useQmlDebugger()), qmlDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useQmlDebugger()),
cppDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useCppDebugger()), cppDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useCppDebugger())
gdbServerPort(-1), qmlPort(-1)
{ {
} }
@@ -69,8 +68,8 @@ public:
bool qmlDebugging; bool qmlDebugging;
bool cppDebugging; bool cppDebugging;
QByteArray gdbserverOutput; QByteArray gdbserverOutput;
int gdbServerPort; Port gdbServerPort;
int qmlPort; Port qmlPort;
}; };
} // namespace Internal } // namespace Internal
@@ -149,7 +148,7 @@ void LinuxDeviceDebugSupport::startExecution()
command = QLatin1String("gdbserver"); command = QLatin1String("gdbserver");
args.clear(); args.clear();
args.append(QString::fromLatin1("--multi")); args.append(QString::fromLatin1("--multi"));
args.append(QString::fromLatin1(":%1").arg(d->gdbServerPort)); args.append(QString::fromLatin1(":%1").arg(d->gdbServerPort.number()));
} }
r.executable = command; r.executable = command;
r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux); r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux);

View File

@@ -116,7 +116,7 @@ RunControl *RemoteLinuxRunControlFactory::create(RunConfiguration *runConfig, Co
if (aspect->useQmlDebugger()) { if (aspect->useQmlDebugger()) {
params.qmlServerAddress = dev->sshParameters().host; params.qmlServerAddress = dev->sshParameters().host;
params.qmlServerPort = 0; // port is selected later on params.qmlServerPort = Utils::Port(); // port is selected later on
} }
if (aspect->useCppDebugger()) { if (aspect->useCppDebugger()) {
aspect->setUseMultiProcess(true); aspect->setUseMultiProcess(true);

View File

@@ -63,14 +63,15 @@ bool WinRtDebugSupport::useQmlDebugging(WinRtRunConfiguration *runConfig)
return extraAspect && extraAspect->useQmlDebugger(); return extraAspect && extraAspect->useQmlDebugger();
} }
bool WinRtDebugSupport::getFreePort(quint16 &qmlDebuggerPort, QString *errorMessage) bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage)
{ {
QTcpServer server; QTcpServer server;
if (!server.listen(QHostAddress::LocalHost, qmlDebuggerPort)) { if (!server.listen(QHostAddress::LocalHost,
qmlDebuggerPort.isValid() ? qmlDebuggerPort.number() : 0)) {
*errorMessage = tr("Not enough free ports for QML debugging."); *errorMessage = tr("Not enough free ports for QML debugging.");
return false; return false;
} }
qmlDebuggerPort = server.serverPort(); qmlDebuggerPort = Utils::Port(server.serverPort());
return true; return true;
} }
@@ -105,7 +106,7 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC
} }
if (useQmlDebugging(runConfig)) { if (useQmlDebugging(runConfig)) {
quint16 qmlDebugPort = 0; Utils::Port qmlDebugPort;
if (!getFreePort(qmlDebugPort, errorMessage)) if (!getFreePort(qmlDebugPort, errorMessage))
return 0; return 0;
params.qmlServerAddress = QHostAddress(QHostAddress::LocalHost).toString(); params.qmlServerAddress = QHostAddress(QHostAddress::LocalHost).toString();

View File

@@ -48,7 +48,7 @@ private:
WinRtDebugSupport(ProjectExplorer::RunControl *runControl, WinRtRunnerHelper *runner); WinRtDebugSupport(ProjectExplorer::RunControl *runControl, WinRtRunnerHelper *runner);
static bool useQmlDebugging(WinRtRunConfiguration *runConfig); static bool useQmlDebugging(WinRtRunConfiguration *runConfig);
static bool getFreePort(quint16 &qmlDebuggerPort, QString *errorMessage); static bool getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage);
ProjectExplorer::RunControl *m_debugRunControl; ProjectExplorer::RunControl *m_debugRunControl;
WinRtRunnerHelper *m_runner; WinRtRunnerHelper *m_runner;