use of com.sun.jdi.VirtualMachine 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");
}
}
use of com.sun.jdi.VirtualMachine in project gravel by gravel-st.
the class VMTargetStarter method createJVM.
public VMRemoteTarget createJVM() throws IOException, InterruptedException, IncompatibleThreadStateException {
Process process = startSecondJVM(VMLocalTarget.class);
sleep(90);
// connect
VirtualMachine vm = new VMAcquirer().connect(debugPort);
ClassPrepareRequest createClassPrepareRequest = vm.eventRequestManager().createClassPrepareRequest();
createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
createClassPrepareRequest.enable();
vm.resume();
List<ThreadReference> allThreads = vm.allThreads();
for (ThreadReference threadReference : allThreads) {
System.out.println(threadReference + " isSuspended: " + threadReference.isSuspended() + " suspendCount: " + threadReference.suspendCount());
}
// process events
EventQueue eventQueue = vm.eventQueue();
while (true) {
EventSet eventSet = eventQueue.remove();
for (Event event : eventSet) {
if (event instanceof ClassPrepareEvent) {
event.request().disable();
installHaltPoint(vm);
}
if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
return null;
}
if (event instanceof BreakpointEvent) {
event.request().disable();
ThreadReference thread = ((BreakpointEvent) event).thread();
return new VMRemoteTarget(process, vm, thread, debugPort);
}
}
eventSet.resume();
}
}
Aggregations