diff options
author | Marcus Tillmanns <[email protected]> | 2023-04-05 11:15:02 +0200 |
---|---|---|
committer | Marcus Tillmanns <[email protected]> | 2023-04-06 06:58:44 +0000 |
commit | 522de9bfd7afc30ae32affa728b7e929b46ccc60 (patch) | |
tree | a9ad8758797621a797f342bb680f72861f60ba5b /src | |
parent | f5c41a7f8350f210ee2e2815bd07669c40449b83 (diff) |
Devices: Unify Port Gathering method
All devices that support it use the same mechanism to gather ports
so this patch removes the individual implementations in favor
of a single one in IDevice.cpp.
This patch also removes:
* canAutodetectPorts() as it was not used.
* Port::parseFrom...Output as they are not used anymore.
Change-Id: I8ecedec2d71e60985402387982c64311c5a651e6
Reviewed-by: hjk <[email protected]>
Reviewed-by: <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/port.cpp | 50 | ||||
-rw-r--r-- | src/libs/utils/port.h | 2 | ||||
-rw-r--r-- | src/plugins/android/androiddevice.cpp | 5 | ||||
-rw-r--r-- | src/plugins/android/androiddevice.h | 1 | ||||
-rw-r--r-- | src/plugins/docker/dockerdevice.cpp | 29 | ||||
-rw-r--r-- | src/plugins/docker/dockerdevice.h | 2 | ||||
-rw-r--r-- | src/plugins/ios/iosdevice.cpp | 6 | ||||
-rw-r--r-- | src/plugins/ios/iosdevice.h | 1 | ||||
-rw-r--r-- | src/plugins/ios/iossimulator.cpp | 5 | ||||
-rw-r--r-- | src/plugins/ios/iossimulator.h | 1 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/desktopdevice.cpp | 30 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/desktopdevice.h | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/idevice.cpp | 21 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/idevice.h | 5 | ||||
-rw-r--r-- | src/plugins/qnx/qnxdevice.cpp | 10 | ||||
-rw-r--r-- | src/plugins/remotelinux/linuxdevice.cpp | 33 | ||||
-rw-r--r-- | src/plugins/remotelinux/linuxdevice.h | 2 |
17 files changed, 23 insertions, 182 deletions
diff --git a/src/libs/utils/port.cpp b/src/libs/utils/port.cpp index ceab772b620..cf56047f3a8 100644 --- a/src/libs/utils/port.cpp +++ b/src/libs/utils/port.cpp @@ -33,56 +33,6 @@ quint16 Port::number() const QTC_ASSERT(isValid(), return -1); return quint16(m_port); } -QList<Port> Port::parseFromSedOutput(const QByteArray &output) -{ - QList<Port> ports; - const QList<QByteArray> portStrings = output.split('\n'); - for (const QByteArray &portString : portStrings) { - if (portString.size() != 4) - continue; - bool ok; - const Port port(portString.toInt(&ok, 16)); - if (ok) { - if (!ports.contains(port)) - ports << port; - } else { - qWarning("%s: Unexpected string '%s' is not a port.", - Q_FUNC_INFO, portString.data()); - } - } - return ports; -} - -QList<Port> Port::parseFromCatOutput(const QByteArray &output) -{ - // Parse something like - // sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode - // : 00000000:2717 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3995881 1 0000000000000000 100 0 0 10 0 - // : 00000000:2716 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3594482 1 0000000000000000 100 0 0 10 0 - const QRegularExpression re(".*: [[:xdigit:]]*:([[:xdigit:]]{4}).*"); - - QList<Port> ports; - const QStringList lines = QString::fromLocal8Bit(output).split('\n'); - for (const QString &line : lines) { - const QRegularExpressionMatch match = re.match(line); - if (!match.hasMatch()) - continue; - const QString portString = match.captured(1); - if (portString.size() != 4) - continue; - bool ok; - const Port port(portString.toInt(&ok, 16)); - if (ok) { - if (!ports.contains(port)) - ports << port; - } else { - qWarning("%s: Unexpected string '%s' is not a port.", - Q_FUNC_INFO, qPrintable(portString)); - } - } - return ports; -} - QList<Port> Port::parseFromNetstatOutput(const QByteArray &output) { QList<Port> ports; diff --git a/src/libs/utils/port.h b/src/libs/utils/port.h index 3202ac5f18f..a3543f72a30 100644 --- a/src/libs/utils/port.h +++ b/src/libs/utils/port.h @@ -24,8 +24,6 @@ public: QString toString() const { return QString::number(m_port); } - static QList<Port> parseFromSedOutput(const QByteArray &output); - static QList<Port> parseFromCatOutput(const QByteArray &output); static QList<Port> parseFromNetstatOutput(const QByteArray &output); friend bool operator<(const Port &p1, const Port &p2) { return p1.number() < p2.number(); } diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 6346c47d7eb..bd518a4e707 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -388,11 +388,6 @@ IDeviceWidget *AndroidDevice::createWidget() return new AndroidDeviceWidget(sharedFromThis()); } -bool AndroidDevice::canAutoDetectPorts() const -{ - return true; -} - DeviceProcessSignalOperation::Ptr AndroidDevice::signalOperation() const { return DeviceProcessSignalOperation::Ptr(new AndroidSignalOperation()); diff --git a/src/plugins/android/androiddevice.h b/src/plugins/android/androiddevice.h index 0d17c73ec81..551d39b934d 100644 --- a/src/plugins/android/androiddevice.h +++ b/src/plugins/android/androiddevice.h @@ -61,7 +61,6 @@ private: void addActionsIfNotFound(); ProjectExplorer::IDevice::DeviceInfo deviceInformation() const override; ProjectExplorer::IDeviceWidget *createWidget() override; - bool canAutoDetectPorts() const override; ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override; QUrl toolControlChannel(const ControlChannelHint &) const override; diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 4475f9fcbf3..474bc402e70 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -419,7 +419,7 @@ DockerDevice::DockerDevice(DockerSettings *settings, const DockerDeviceData &dat { setFileAccess(&d->m_fileAccess); setDisplayType(Tr::tr("Docker")); - setOsType(OsTypeOtherUnix); + setOsType(OsTypeLinux); setDefaultDisplayName(Tr::tr("Docker Image")); setupId(IDevice::ManuallyAdded); setType(Constants::DOCKER_DEVICE_TYPE); @@ -832,33 +832,6 @@ ProcessInterface *DockerDevice::createProcessInterface() const return new DockerProcessImpl(this->sharedFromThis(), d); } -bool DockerDevice::canAutoDetectPorts() const -{ - return true; -} - -PortsGatheringMethod DockerDevice::portsGatheringMethod() const -{ - return {[this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { - // We might encounter the situation that protocol is given IPv6 - // but the consumer of the free port information decides to open - // an IPv4(only) port. As a result the next IPv6 scan will - // report the port again as open (in IPv6 namespace), while the - // same port in IPv4 namespace might still be blocked, and - // re-use of this port fails. - // GDBserver behaves exactly like this. - - Q_UNUSED(protocol) - - // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6 - return {filePath("sed"), - "-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*", - CommandLine::Raw}; - }, - - &Port::parseFromSedOutput}; -}; - DeviceProcessList *DockerDevice::createProcessListModel(QObject *parent) const { return new ProcessList(sharedFromThis(), parent); diff --git a/src/plugins/docker/dockerdevice.h b/src/plugins/docker/dockerdevice.h index affe4cf2714..bd0ce29d9d4 100644 --- a/src/plugins/docker/dockerdevice.h +++ b/src/plugins/docker/dockerdevice.h @@ -73,8 +73,6 @@ public: Utils::ProcessInterface *createProcessInterface() const override; - bool canAutoDetectPorts() const override; - ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override; bool canCreateProcessModel() const override { return true; } ProjectExplorer::DeviceProcessList *createProcessListModel(QObject *parent) const override; bool hasDeviceTester() const override { return false; } diff --git a/src/plugins/ios/iosdevice.cpp b/src/plugins/ios/iosdevice.cpp index 49a07a2b101..326092fccc3 100644 --- a/src/plugins/ios/iosdevice.cpp +++ b/src/plugins/ios/iosdevice.cpp @@ -185,12 +185,6 @@ Utils::Port IosDevice::nextPort() const return Utils::Port(m_lastPort); } -bool IosDevice::canAutoDetectPorts() const -{ - return true; -} - - // IosDeviceManager IosDeviceManager::TranslationMap IosDeviceManager::translationMap() diff --git a/src/plugins/ios/iosdevice.h b/src/plugins/ios/iosdevice.h index 9f4e66c5025..ada952037d9 100644 --- a/src/plugins/ios/iosdevice.h +++ b/src/plugins/ios/iosdevice.h @@ -36,7 +36,6 @@ public: QString osVersion() const; QString cpuArchitecture() const; Utils::Port nextPort() const; - bool canAutoDetectPorts() const override; static QString name(); diff --git a/src/plugins/ios/iossimulator.cpp b/src/plugins/ios/iossimulator.cpp index b58e451400d..ceb9fd77859 100644 --- a/src/plugins/ios/iossimulator.cpp +++ b/src/plugins/ios/iossimulator.cpp @@ -66,11 +66,6 @@ Utils::Port IosSimulator::nextPort() const return Utils::Port(m_lastPort); } -bool IosSimulator::canAutoDetectPorts() const -{ - return true; -} - // IosDeviceType IosDeviceType::IosDeviceType(IosDeviceType::Type type, const QString &identifier, const QString &displayName) : diff --git a/src/plugins/ios/iossimulator.h b/src/plugins/ios/iossimulator.h index d2d69f1d0ef..988776e5086 100644 --- a/src/plugins/ios/iossimulator.h +++ b/src/plugins/ios/iossimulator.h @@ -48,7 +48,6 @@ public: ProjectExplorer::IDeviceWidget *createWidget() override; Utils::Port nextPort() const; - bool canAutoDetectPorts() const override; protected: friend class IosSimulatorFactory; diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp index 4ad0d59d328..2ac44ad6220 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp @@ -87,11 +87,6 @@ IDeviceWidget *DesktopDevice::createWidget() // range can be confusing to the user. Hence, disabling the widget for now. } -bool DesktopDevice::canAutoDetectPorts() const -{ - return true; -} - bool DesktopDevice::canCreateProcessModel() const { return true; @@ -107,31 +102,6 @@ DeviceProcessSignalOperation::Ptr DesktopDevice::signalOperation() const return DeviceProcessSignalOperation::Ptr(new DesktopProcessSignalOperation()); } -PortsGatheringMethod DesktopDevice::portsGatheringMethod() const -{ - return { - [this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { - // We might encounter the situation that protocol is given IPv6 - // but the consumer of the free port information decides to open - // an IPv4(only) port. As a result the next IPv6 scan will - // report the port again as open (in IPv6 namespace), while the - // same port in IPv4 namespace might still be blocked, and - // re-use of this port fails. - // GDBserver behaves exactly like this. - - Q_UNUSED(protocol) - - if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) - return {filePath("netstat"), {"-a", "-n"}}; - if (HostOsInfo::isLinuxHost()) - return {filePath("/bin/sh"), {"-c", "cat /proc/net/tcp*"}}; - return {}; - }, - - &Port::parseFromNetstatOutput - }; -} - QUrl DesktopDevice::toolControlChannel(const ControlChannelHint &) const { QUrl url; diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.h b/src/plugins/projectexplorer/devicesupport/desktopdevice.h index 28220f21ed6..d9cafbfda9a 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.h +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.h @@ -25,10 +25,8 @@ public: IDevice::DeviceInfo deviceInformation() const override; IDeviceWidget *createWidget() override; - bool canAutoDetectPorts() const override; bool canCreateProcessModel() const override; DeviceProcessList *createProcessListModel(QObject *parent) const override; - ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override; DeviceProcessSignalOperation::Ptr signalOperation() const override; QUrl toolControlChannel(const ControlChannelHint &) const override; bool usableAsBuildDevice() const override; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 2e4dbcef59f..b14e50ed13c 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -371,6 +371,27 @@ const QList<IDevice::DeviceAction> IDevice::deviceActions() const return d->deviceActions; } +PortsGatheringMethod IDevice::portsGatheringMethod() const +{ + return {[this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { + // We might encounter the situation that protocol is given IPv6 + // but the consumer of the free port information decides to open + // an IPv4(only) port. As a result the next IPv6 scan will + // report the port again as open (in IPv6 namespace), while the + // same port in IPv4 namespace might still be blocked, and + // re-use of this port fails. + // GDBserver behaves exactly like this. + + Q_UNUSED(protocol) + + if (filePath("/proc/net").isReadableDir()) + return {filePath("/bin/sh"), {"-c", "cat /proc/net/tcp*"}}; + + return {filePath("netstat"), {"-a", "-n"}}; + }, + &Port::parseFromNetstatOutput}; +}; + DeviceProcessList *IDevice::createProcessListModel(QObject *parent) const { Q_UNUSED(parent) diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 596637e3e08..9c2dc2122f8 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -139,10 +139,7 @@ public: void addDeviceAction(const DeviceAction &deviceAction); const QList<DeviceAction> deviceActions() const; - // Devices that can auto detect ports need not return a ports gathering method. Such devices can - // obtain a free port on demand. eg: Desktop device. - virtual bool canAutoDetectPorts() const { return false; } - virtual PortsGatheringMethod portsGatheringMethod() const { return {}; } + virtual PortsGatheringMethod portsGatheringMethod() const; virtual bool canCreateProcessModel() const { return false; } virtual DeviceProcessList *createProcessListModel(QObject *parent = nullptr) const; virtual bool hasDeviceTester() const { return false; } diff --git a/src/plugins/qnx/qnxdevice.cpp b/src/plugins/qnx/qnxdevice.cpp index e574a8eed78..49056d9ec40 100644 --- a/src/plugins/qnx/qnxdevice.cpp +++ b/src/plugins/qnx/qnxdevice.cpp @@ -78,16 +78,6 @@ public: }}); } - PortsGatheringMethod portsGatheringMethod() const final - { - return { - [this](QAbstractSocket::NetworkLayerProtocol) { - return CommandLine(filePath("netstat"), {"-na"}); - }, - &Port::parseFromNetstatOutput - }; - } - DeviceProcessSignalOperation::Ptr signalOperation() const final { return DeviceProcessSignalOperation::Ptr(new QnxDeviceProcessSignalOperation(sharedFromThis())); diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 633f46dbe0b..d01ea1be8f4 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -993,39 +993,6 @@ IDeviceWidget *LinuxDevice::createWidget() return new Internal::GenericLinuxDeviceConfigurationWidget(sharedFromThis()); } -bool LinuxDevice::canAutoDetectPorts() const -{ - return true; -} - -PortsGatheringMethod LinuxDevice::portsGatheringMethod() const -{ - return { - [this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { - // We might encounter the situation that protocol is given IPv6 - // but the consumer of the free port information decides to open - // an IPv4(only) port. As a result the next IPv6 scan will - // report the port again as open (in IPv6 namespace), while the - // same port in IPv4 namespace might still be blocked, and - // re-use of this port fails. - // GDBserver behaves exactly like this. - - Q_UNUSED(protocol) - - // We used to have - // // /proc/net/tcp* covers /proc/net/tcp and /proc/net/tcp6 - // return {filePath("sed"), - // "-e 's/.*: [[:xdigit:]]*:\\([[:xdigit:]]\\{4\\}\\).*/\\1/g' /proc/net/tcp*", - // - // here, but that doesn't pass quoting on double-remote setups. - // Chicken out by using a simpler command. - return {filePath("/bin/sh"), {"-c", "cat /proc/net/tcp*"}}; - }, - - &Port::parseFromCatOutput - }; -} - DeviceProcessList *LinuxDevice::createProcessListModel(QObject *parent) const { return new ProcessList(sharedFromThis(), parent); diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h index d9dad9ba75f..2094b426b4c 100644 --- a/src/plugins/remotelinux/linuxdevice.h +++ b/src/plugins/remotelinux/linuxdevice.h @@ -22,8 +22,6 @@ public: ProjectExplorer::IDeviceWidget *createWidget() override; - bool canAutoDetectPorts() const override; - ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override; bool canCreateProcessModel() const override { return true; } ProjectExplorer::DeviceProcessList *createProcessListModel(QObject *parent) const override; bool hasDeviceTester() const override { return true; } |