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:
parent
4a447ce1a6
commit
220e0696ed
1 changed files with 51 additions and 37 deletions
|
@ -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();
|
||||||
|
@ -613,13 +614,14 @@ public class BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
||||||
|
GdbDebugOptions.trace("Forcing to not start gdbserver for this test\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,23 +632,35 @@ public class BaseTestCase {
|
||||||
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)
|
||||||
|
GdbDebugOptions.trace(line + "\n");
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.startsWith("Listening on port")) {
|
final String LISTENING_ON_PORT = "Listening on port ";
|
||||||
|
if (line.startsWith(LISTENING_ON_PORT)) {
|
||||||
|
String portString = line.substring(LISTENING_ON_PORT.length());
|
||||||
|
// make sure this is really a port number
|
||||||
|
try {
|
||||||
|
Integer.parseInt(portString);
|
||||||
|
} 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GdbDebugOptions.trace("Error while launching command: " + commandLine + "\n");
|
throw new Exception("Error while launching command for gdbserver: " + commandLine + "\n", e);
|
||||||
e.printStackTrace();
|
|
||||||
assert false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue