1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

Bug 532599: [tests] use os allocated port for gdbserver comms

Change-Id: I2843472de14cf767896070fcba8add508a1a9eca
This commit is contained in:
Jonah Graham 2018-03-19 13:19:17 +00:00
parent 4a447ce1a6
commit 220e0696ed

View file

@ -367,7 +367,8 @@ public class BaseTestCase {
launchAttributes.put(ATTR_DEBUG_SERVER_NAME, "gdbserver"); launchAttributes.put(ATTR_DEBUG_SERVER_NAME, "gdbserver");
launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP, true); launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP, true);
launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_HOST, "localhost"); launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_HOST, "localhost");
launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_PORT, "9999"); // Using a port of 0 here means gdbserver will allocate the port number
launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_PORT, "0");
launchAttributes.put(ITestConstants.LAUNCH_GDB_SERVER, true); launchAttributes.put(ITestConstants.LAUNCH_GDB_SERVER, true);
initializeLaunchAttributes(); initializeLaunchAttributes();
@ -612,44 +613,57 @@ public class BaseTestCase {
removeAllPlatformBreakpoints(); removeAllPlatformBreakpoints();
} }
/** /**
* This method start gdbserver on the localhost. * This method start gdbserver on the localhost. If the user specified a
* If the user specified a different host, things won't work. * different host, things won't work.
*/ */
private void launchGdbServer() { private void launchGdbServer() throws Exception {
// First check if we should not launch gdbserver even for a remote session // First check if we should not launch gdbserver even for a remote session
if (launchAttributes.get(ITestConstants.LAUNCH_GDB_SERVER).equals(false)) { if (launchAttributes.get(ITestConstants.LAUNCH_GDB_SERVER).equals(false)) {
if (GdbDebugOptions.DEBUG) GdbDebugOptions.trace("Forcing to not start gdbserver for this test\n"); if (GdbDebugOptions.DEBUG)
return; GdbDebugOptions.trace("Forcing to not start gdbserver for this test\n");
} return;
}
if (isRemoteSession()) { if (isRemoteSession()) {
if (launchAttributes.get(IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP).equals(Boolean.TRUE)) { if (launchAttributes.get(IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP).equals(Boolean.TRUE)) {
String server = (String)launchAttributes.get(ATTR_DEBUG_SERVER_NAME); String server = (String) launchAttributes.get(ATTR_DEBUG_SERVER_NAME);
String port = (String)launchAttributes.get(IGDBLaunchConfigurationConstants.ATTR_PORT); String port = (String) launchAttributes.get(IGDBLaunchConfigurationConstants.ATTR_PORT);
String program = (String)launchAttributes.get(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME); String program = (String) launchAttributes.get(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME);
String commandLine = server + " :" + port + " " + program; String commandLine = server + " :" + port + " " + program;
try { try {
if (GdbDebugOptions.DEBUG) GdbDebugOptions.trace("Starting gdbserver with command: " + commandLine + "\n"); if (GdbDebugOptions.DEBUG)
GdbDebugOptions.trace("Starting gdbserver with command: " + commandLine + "\n");
gdbserverProc = ProcessFactory.getFactory().exec(commandLine); gdbserverProc = ProcessFactory.getFactory().exec(commandLine);
Reader r = new InputStreamReader(gdbserverProc.getErrorStream()); Reader r = new InputStreamReader(gdbserverProc.getErrorStream());
BufferedReader reader = new BufferedReader(r); BufferedReader reader = new BufferedReader(r);
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if(GdbDebugOptions.DEBUG) GdbDebugOptions.trace(line + "\n"); if (GdbDebugOptions.DEBUG)
line = line.trim(); GdbDebugOptions.trace(line + "\n");
if (line.startsWith("Listening on port")) { line = line.trim();
break; final String LISTENING_ON_PORT = "Listening on port ";
} if (line.startsWith(LISTENING_ON_PORT)) {
} String portString = line.substring(LISTENING_ON_PORT.length());
} catch (Exception e) { // make sure this is really a port number
GdbDebugOptions.trace("Error while launching command: " + commandLine + "\n"); try {
e.printStackTrace(); Integer.parseInt(portString);
assert false; } catch (NumberFormatException nfe) {
} throw new Exception("Expected a number for the port gdbserver is listening to, got '"
} + portString + "'");
} }
if (GdbDebugOptions.DEBUG)
GdbDebugOptions.trace("gdbserver running and listening in port: " + portString + "\n");
launchAttributes.put(IGDBLaunchConfigurationConstants.ATTR_PORT, portString);
break;
}
}
} catch (Exception e) {
throw new Exception("Error while launching command for gdbserver: " + commandLine + "\n", e);
}
}
}
} }
/** /**