From dddc3401308e12a5cb21755058f1eb1ee512ada8 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 20 Jul 2017 14:23:31 -0700 Subject: [PATCH] Fix Debug in Container - on Windows (possibly Mac as well), we can't use the ip of the Container to contact the gdbserver as this address may be hidden from the host behind a VM - instead use the localhost port that the tcp/2345 is mapped to which the Docker machine etc.. forwards back - fix this in ContainerLaunchConfigurationDelegate Change-Id: I9f85bf0d0d9dec183c504ba4fb7adc55d4a038bb --- .../ContainerLaunchConfigurationDelegate.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java index 4f74b99ab7d..ae11435556f 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java @@ -37,6 +37,7 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.linuxtools.docker.core.IDockerContainerInfo; import org.eclipse.linuxtools.docker.core.IDockerNetworkSettings; +import org.eclipse.linuxtools.docker.core.IDockerPortBinding; import org.eclipse.linuxtools.docker.ui.launch.ContainerLauncher; import org.eclipse.linuxtools.docker.ui.launch.IContainerLaunchListener; @@ -93,6 +94,14 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate return null; } + public Map> getPorts() { + if (info != null) { + IDockerNetworkSettings networkSettings = info.networkSettings(); + return networkSettings.ports(); + } + return null; + } + public IDockerContainerInfo getContainerInfo() { return info; } @@ -268,10 +277,29 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE); - wc.setAttribute(IGDBLaunchConfigurationConstants.ATTR_HOST, - job.getIpAddress()); - wc.setAttribute(IGDBLaunchConfigurationConstants.ATTR_PORT, - gdbserverPortNumber); + if (job.getPorts() != null) { + Map> hostPorts = job + .getPorts(); + List bindingList = hostPorts + .get(gdbserverPortNumber + "/tcp"); //$NON-NLS-1$ + if (bindingList != null && !bindingList.isEmpty()) { + IDockerPortBinding firstBinding = bindingList + .get(0); + wc.setAttribute( + IGDBLaunchConfigurationConstants.ATTR_HOST, + "localhost"); //$NON-NLS-1$ + wc.setAttribute( + IGDBLaunchConfigurationConstants.ATTR_PORT, + firstBinding.hostPort()); + } + } else { + wc.setAttribute( + IGDBLaunchConfigurationConstants.ATTR_HOST, + job.getIpAddress()); + wc.setAttribute( + IGDBLaunchConfigurationConstants.ATTR_PORT, + gdbserverPortNumber); + } wc.doSave(); try { super.launch(configuration, mode, launch, monitor);