diff --git a/src/plugins/valgrind/valgrindtool.cpp b/src/plugins/valgrind/valgrindtool.cpp index 035e2cd6d61..793313397e1 100644 --- a/src/plugins/valgrind/valgrindtool.cpp +++ b/src/plugins/valgrind/valgrindtool.cpp @@ -37,6 +37,9 @@ #include #include #include +#include + +#include using namespace ProjectExplorer; using namespace RemoteLinux; @@ -65,15 +68,23 @@ Analyzer::AnalyzerStartParameters ValgrindTool::createStartParameters( qobject_cast(runConfiguration)) { ProjectExplorer::EnvironmentAspect *aspect = runConfiguration->extraAspect(); - sp.startMode = Analyzer::StartLocal; if (aspect) sp.environment = aspect->environment(); sp.workingDirectory = rc1->workingDirectory(); sp.debuggee = rc1->executable(); sp.debuggeeArgs = rc1->commandLineArguments(); sp.connParams.host = QLatin1String("localhost"); - sp.connParams.port = rc1->extraAspect() - ->qmlDebugServerPort(); + const ProjectExplorer::IDevice::ConstPtr device = + ProjectExplorer::DeviceKitInformation::device(runConfiguration->target()->kit()); + QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return sp); + Utils::TcpPortsGatherer portsGatherer; + portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol); + Utils::PortList portList = device->freePorts(); + int freePort = portsGatherer.getNextFreePort(&portList); + if (freePort == -1) + return sp; + sp.connParams.port = freePort; + sp.startMode = Analyzer::StartLocal; } else if (RemoteLinuxRunConfiguration *rc2 = qobject_cast(runConfiguration)) { sp.startMode = Analyzer::StartRemote;