use of com.sun.jdi.connect.AttachingConnector in project jdk8u_jdk by JetBrains.
the class RunToExit method main.
/*
* - pick a TCP port
* - Launch a server debuggee: server=y,suspend=y,address=${port}
* - run it to VM death
* - verify we saw no error
*/
public static void main(String[] args) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the server debuggee
Process process = launch(address, "Exit0");
// wait for the debugge to be ready
while (!ready) {
try {
Thread.sleep(1000);
} catch (Exception ee) {
throw ee;
}
}
// attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg = (Connector.IntegerArgument) conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event : evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
int exitCode = process.waitFor();
// if the server debuggee ran cleanly, we assume we were clean
if (exitCode == 0 && error_seen == 0) {
System.out.println("Test passed - server debuggee cleanly terminated");
} else {
throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
}
}
Aggregations