Search in sources :

Example 6 with AttachingConnector

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");
    }
}
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)

Aggregations

AttachingConnector (com.sun.jdi.connect.AttachingConnector)6 VirtualMachine (com.sun.jdi.VirtualMachine)5 Connector (com.sun.jdi.connect.Connector)4 Map (java.util.Map)3 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)2 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 ThreadReference (com.sun.jdi.ThreadReference)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1