Search in sources :

Example 11 with VirtualMachine

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");
    }
}
Also used : AttachingConnector(com.sun.jdi.connect.AttachingConnector) Connector(com.sun.jdi.connect.Connector) AttachingConnector(com.sun.jdi.connect.AttachingConnector) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) Map(java.util.Map) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 12 with VirtualMachine

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();
    }
}
Also used : VMDeathEvent(com.sun.jdi.event.VMDeathEvent) EventSet(com.sun.jdi.event.EventSet) ThreadReference(com.sun.jdi.ThreadReference) EventQueue(com.sun.jdi.event.EventQueue) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) ClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) ClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent) Event(com.sun.jdi.event.Event) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) VirtualMachine(com.sun.jdi.VirtualMachine)

Aggregations

VirtualMachine (com.sun.jdi.VirtualMachine)12 Connector (com.sun.jdi.connect.Connector)6 AttachingConnector (com.sun.jdi.connect.AttachingConnector)5 IOException (java.io.IOException)4 Map (java.util.Map)3 ThreadReference (com.sun.jdi.ThreadReference)2 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 EventSet (com.sun.jdi.event.EventSet)2 SocketAttachingConnector (com.sun.tools.jdi.SocketAttachingConnector)2 ServerSocket (java.net.ServerSocket)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 ArrayType (com.sun.jdi.ArrayType)1 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)1 Method (com.sun.jdi.Method)1 ReferenceType (com.sun.jdi.ReferenceType)1 StackFrame (com.sun.jdi.StackFrame)1 VMDisconnectedException (com.sun.jdi.VMDisconnectedException)1 Value (com.sun.jdi.Value)1 VirtualMachineManager (com.sun.jdi.VirtualMachineManager)1