mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 529910 - Debugging C/C++ container apps remotely is not working
- fix ContainerLaunchConfigurationDelegate to look at whether the daemon is running remotely or locally - if running remotely, try to connect to gdbserver by using the Container ip address and the gdbserver port directly (will not work on Windows, but fixes Linux scenario) Change-Id: I9a6188d90187e2ca6ab73c8042a02b6ff29d5f2f
This commit is contained in:
parent
5728fec0cf
commit
7292fbff6d
1 changed files with 34 additions and 1 deletions
|
@ -10,11 +10,17 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.docker.launcher;
|
package org.eclipse.cdt.internal.docker.launcher;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||||
|
@ -36,6 +42,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.debug.core.ILaunchManager;
|
import org.eclipse.debug.core.ILaunchManager;
|
||||||
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
|
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
|
||||||
|
import org.eclipse.linuxtools.docker.core.Activator;
|
||||||
import org.eclipse.linuxtools.docker.core.IDockerContainerInfo;
|
import org.eclipse.linuxtools.docker.core.IDockerContainerInfo;
|
||||||
import org.eclipse.linuxtools.docker.core.IDockerNetworkSettings;
|
import org.eclipse.linuxtools.docker.core.IDockerNetworkSettings;
|
||||||
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
|
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
|
||||||
|
@ -290,6 +297,32 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
||||||
ILaunchConstants.ATTR_IMAGE, (String) null);
|
ILaunchConstants.ATTR_IMAGE, (String) null);
|
||||||
String connectionUri = configuration.getAttribute(
|
String connectionUri = configuration.getAttribute(
|
||||||
ILaunchConstants.ATTR_CONNECTION_URI, (String) "");
|
ILaunchConstants.ATTR_CONNECTION_URI, (String) "");
|
||||||
|
boolean isLocalConnection = true;
|
||||||
|
try {
|
||||||
|
Pattern ipaddrPattern = Pattern.compile(
|
||||||
|
"[a-z]*://([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)[:]*[0-9]*");
|
||||||
|
Matcher m = ipaddrPattern.matcher(connectionUri);
|
||||||
|
if (m.matches()) {
|
||||||
|
String ipaddr = m.group(1);
|
||||||
|
InetAddress addr = InetAddress.getByName(ipaddr);
|
||||||
|
if (addr.isAnyLocalAddress()
|
||||||
|
|| addr.isLoopbackAddress()) {
|
||||||
|
isLocalConnection = true;
|
||||||
|
} else {
|
||||||
|
// Check if the address is defined on any interface
|
||||||
|
try {
|
||||||
|
isLocalConnection = NetworkInterface
|
||||||
|
.getByInetAddress(addr) != null;
|
||||||
|
} catch (SocketException e) {
|
||||||
|
isLocalConnection = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
// should not happen
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
boolean keepContainer = configuration.getAttribute(
|
boolean keepContainer = configuration.getAttribute(
|
||||||
ILaunchConstants.ATTR_KEEP_AFTER_LAUNCH, false);
|
ILaunchConstants.ATTR_KEEP_AFTER_LAUNCH, false);
|
||||||
|
|
||||||
|
@ -332,7 +365,7 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
||||||
wc.setAttribute(
|
wc.setAttribute(
|
||||||
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
|
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
|
||||||
IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
|
IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
|
||||||
if (job.getPorts() != null) {
|
if (job.getPorts() != null && isLocalConnection) {
|
||||||
Map<String, List<IDockerPortBinding>> hostPorts = job
|
Map<String, List<IDockerPortBinding>> hostPorts = job
|
||||||
.getPorts();
|
.getPorts();
|
||||||
List<IDockerPortBinding> bindingList = hostPorts
|
List<IDockerPortBinding> bindingList = hostPorts
|
||||||
|
|
Loading…
Add table
Reference in a new issue