com.sun.jdi.Bootstrap Java Examples

The following examples show how to use com.sun.jdi.Bootstrap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SACoreAttachingConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #2
Source File: AcceptTimeout.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
    for (ListeningConnector lc: connectors) {
        Map<String,Connector.Argument> cargs = lc.defaultArguments();
        Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");

        /*
         * If the Connector has a argument named "timeout" then we set the timeout to 1 second
         * and start it listening on its default address. It should throw TranpsortTimeoutException.
         */
        if (timeout != null) {
            System.out.println("Testing " + lc.name());
            timeout.setValue(1000);

            System.out.println("Listening on: " + lc.startListening(cargs));
            try {
                lc.accept(cargs);
                throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
            } catch (TransportTimeoutException e) {
                System.out.println("Timed out as expected.\n");
            }
            lc.stopListening(cargs);
        }
    }
}
 
Example #3
Source File: DebugSessionFactory.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
public static IDebugSession getDebugSession(String projectName, String mainClass) throws Exception {
    setupProject(projectName);
    return debugSessionMap.computeIfAbsent(projectName, (name) -> {
        String projectRoot = new File(rootPath, name).getAbsolutePath();
        try {
            final IDebugSession debugSession = DebugUtility.launch(Bootstrap.virtualMachineManager(), mainClass, "", "",
                    null, new File(projectRoot, "bin").getAbsolutePath(), null, null);
            debugSession.getEventHub().events().subscribe(debugEvent -> {
                if (debugEvent.event instanceof VMDisconnectEvent) {
                    try {
                        debugSession.getEventHub().close();
                    } catch (Exception e) {
                        // do nothing.
                    }
                }
            });
            return debugSession;
        } catch (Exception ex) {
            return null;
        }
    });
}
 
Example #4
Source File: ProcessAttachTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void tryDebug(long pid) throws IOException,
        IllegalConnectorArgumentsException {
    AttachingConnector ac = Bootstrap.virtualMachineManager().attachingConnectors()
            .stream()
            .filter(c -> c.name().equals("com.sun.jdi.ProcessAttach"))
            .findFirst()
            .orElseThrow(() -> new RuntimeException("Unable to locate ProcessAttachingConnector"));

    Map<String, Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument) args
            .get("pid");
    arg.setValue("" + pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");
    VirtualMachine vm = ac.attach(args);

    // list all threads
    System.out.println("Attached! Now listing threads ...");
    vm.allThreads().stream().forEach(System.out::println);

    System.out.println("Debugger done.");
    vm.dispose();
}
 
Example #5
Source File: SACoreAttachingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #6
Source File: AcceptTimeout.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
    for (ListeningConnector lc: connectors) {
        Map<String,Connector.Argument> cargs = lc.defaultArguments();
        Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");

        /*
         * If the Connector has a argument named "timeout" then we set the timeout to 1 second
         * and start it listening on its default address. It should throw TranpsortTimeoutException.
         */
        if (timeout != null) {
            System.out.println("Testing " + lc.name());
            timeout.setValue(1000);

            System.out.println("Listening on: " + lc.startListening(cargs));
            try {
                lc.accept(cargs);
                throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
            } catch (TransportTimeoutException e) {
                System.out.println("Timed out as expected.\n");
            }
            lc.stopListening(cargs);
        }
    }
}
 
Example #7
Source File: SADebugServerAttachingConnector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #8
Source File: SADebugServerAttachingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #9
Source File: AcceptTimeout.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
    for (ListeningConnector lc: connectors) {
        Map<String,Connector.Argument> cargs = lc.defaultArguments();
        Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");

        /*
         * If the Connector has a argument named "timeout" then we set the timeout to 1 second
         * and start it listening on its default address. It should throw TranpsortTimeoutException.
         */
        if (timeout != null) {
            System.out.println("Testing " + lc.name());
            timeout.setValue(1000);

            System.out.println("Listening on: " + lc.startListening(cargs));
            try {
                lc.accept(cargs);
                throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
            } catch (TransportTimeoutException e) {
                System.out.println("Timed out as expected.\n");
            }
            lc.stopListening(cargs);
        }
    }
}
 
Example #10
Source File: SACoreAttachingConnector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #11
Source File: AcceptTimeout.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
    for (ListeningConnector lc: connectors) {
        Map<String,Connector.Argument> cargs = lc.defaultArguments();
        Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");

        /*
         * If the Connector has a argument named "timeout" then we set the timeout to 1 second
         * and start it listening on its default address. It should throw TranpsortTimeoutException.
         */
        if (timeout != null) {
            System.out.println("Testing " + lc.name());
            timeout.setValue(1000);

            System.out.println("Listening on: " + lc.startListening(cargs));
            try {
                lc.accept(cargs);
                throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
            } catch (TransportTimeoutException e) {
                System.out.println("Timed out as expected.\n");
            }
            lc.stopListening(cargs);
        }
    }
}
 
Example #12
Source File: AcceptTimeout.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors();
    for (ListeningConnector lc: connectors) {
        Map<String,Connector.Argument> cargs = lc.defaultArguments();
        Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout");

        /*
         * If the Connector has a argument named "timeout" then we set the timeout to 1 second
         * and start it listening on its default address. It should throw TranpsortTimeoutException.
         */
        if (timeout != null) {
            System.out.println("Testing " + lc.name());
            timeout.setValue(1000);

            System.out.println("Listening on: " + lc.startListening(cargs));
            try {
                lc.accept(cargs);
                throw new RuntimeException("Connection accepted from some debuggee - unexpected!");
            } catch (TransportTimeoutException e) {
                System.out.println("Timed out as expected.\n");
            }
            lc.stopListening(cargs);
        }
    }
}
 
Example #13
Source File: SADebugServerAttachingConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #14
Source File: ProcessAttachDebugger.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #15
Source File: Trace.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a com.sun.jdi.CommandLineLaunch connector
 */
LaunchingConnector findLaunchingConnector() {
    List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
    for (Connector connector : connectors) {
        if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
            return (LaunchingConnector)connector;
        }
    }
    throw new Error("No launching connector");
}
 
Example #16
Source File: Trace.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a com.sun.jdi.CommandLineLaunch connector
 */
LaunchingConnector findLaunchingConnector() {
    List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
    for (Connector connector : connectors) {
        if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
            return (LaunchingConnector)connector;
        }
    }
    throw new Error("No launching connector");
}
 
Example #17
Source File: JDIRedefiner.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine connect(int port) throws IOException {
    VirtualMachineManager manager = Bootstrap.virtualMachineManager();

    // Find appropiate connector
    List<AttachingConnector> connectors = manager.attachingConnectors();
    AttachingConnector chosenConnector = null;
    for (AttachingConnector c : connectors) {
        if (c.transport().name().equals(TRANSPORT_NAME)) {
            chosenConnector = c;
            break;
        }
    }
    if (chosenConnector == null) {
        throw new IllegalStateException("Could not find socket connector");
    }

    // Set port argument
    AttachingConnector connector = chosenConnector;
    Map<String, Argument> defaults = connector.defaultArguments();
    Argument arg = defaults.get(PORT_ARGUMENT_NAME);
    if (arg == null) {
        throw new IllegalStateException("Could not find port argument");
    }
    arg.setValue(Integer.toString(port));

    // Attach
    try {
        System.out.println("Connector arguments: " + defaults);
        return connector.attach(defaults);
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalArgumentException("Illegal connector arguments",
                e);
    }
}
 
Example #18
Source File: ExclusiveBind.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #19
Source File: ListConnectors.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void list() {
    List<Connector> l = Bootstrap.virtualMachineManager().allConnectors();

    for(Connector c: l) {
        System.out.println(c.name());
    }
}
 
Example #20
Source File: RunToExit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #21
Source File: SimpleLaunchingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws
                          IOException,
                          IllegalConnectorArgumentsException,
                          VMStartException {

    /*
     * Get the class name that we are to execute
     */
    String className = ((StringArgumentImpl)arguments.get(ARG_NAME)).value();
    if (className.length() == 0) {
        throw new IllegalConnectorArgumentsException("class name missing", ARG_NAME);
    }

    /*
     * Listen on an emperical port; launch the debuggee; wait for
     * for the debuggee to connect; stop listening;
     */
    TransportService.ListenKey key = ts.startListening();

    String exe = System.getProperty("java.home") + File.separator + "bin" +
        File.separator + "java";
    String cmd = exe + " -Xdebug -Xrunjdwp:transport=dt_socket,timeout=15000,address=" +
        key.address() +
        " -classpath " + System.getProperty("test.classes") +
        " " + className;
    Process process = Runtime.getRuntime().exec(cmd);
    Connection conn = ts.accept(key, 30*1000, 9*1000);
    ts.stopListening(key);

    /*
     * Debugee is connected - return the virtual machine mirror
     */
    return Bootstrap.virtualMachineManager().createVirtualMachine(conn);
}
 
Example #22
Source File: SAPIDAttachingConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #23
Source File: BadHandshakeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #24
Source File: LaunchingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static LaunchingConnector findLaunchingConnector () {
    Iterator<LaunchingConnector> iter = Bootstrap.virtualMachineManager ().
        launchingConnectors ().iterator ();
    while (iter.hasNext ()) {
        LaunchingConnector lc = iter.next ();
        if (lc.name ().indexOf ("RawCommandLineLaunch") > -1)
            return lc;
    }
    return null;
}
 
Example #25
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
private AttachingConnector getConnector() {
  VirtualMachineManager vmManager = Bootstrap
      .virtualMachineManager();
  for (AttachingConnector connector : vmManager
      .attachingConnectors()) {
    if ("com.sun.jdi.SocketAttach".equals(connector
        .name())) {
      return (AttachingConnector) connector;
    }
  }
  throw new IllegalStateException();
}
 
Example #26
Source File: ProcessAttachDebugger.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example #27
Source File: ExclusiveBind.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #28
Source File: BadHandshakeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #29
Source File: RunToExit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Connector findConnector(String name) {
    List connectors = Bootstrap.virtualMachineManager().allConnectors();
    Iterator iter = connectors.iterator();
    while (iter.hasNext()) {
        Connector connector = (Connector)iter.next();
        if (connector.name().equals(name)) {
            return connector;
        }
    }
    return null;
}
 
Example #30
Source File: FieldMonitor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a com.sun.jdi.CommandLineLaunch connector
 */
static LaunchingConnector findLaunchingConnector() {
  List <Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
  Iterator <Connector> iter = connectors.iterator();
  while (iter.hasNext()) {
    Connector connector = iter.next();
    if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) {
      return (LaunchingConnector)connector;
    }
  }
  throw new Error("No launching connector");
}