Search in sources :

Example 6 with VirtualMachine

use of com.sun.jdi.VirtualMachine in project jdk8u_jdk by JetBrains.

the class ProcessAttachDebugger method main.

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 ...");
    for (ThreadReference thr : vm.allThreads()) {
        System.out.println(thr);
    }
    System.out.println("Debugger done.");
}
Also used : AttachingConnector(com.sun.jdi.connect.AttachingConnector) Connector(com.sun.jdi.connect.Connector) AttachingConnector(com.sun.jdi.connect.AttachingConnector) ThreadReference(com.sun.jdi.ThreadReference) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 7 with VirtualMachine

use of com.sun.jdi.VirtualMachine in project jdk8u_jdk by JetBrains.

the class SunCommandLineLauncher method launch.

public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws IOException, IllegalConnectorArgumentsException, VMStartException {
    VirtualMachine vm;
    String home = argument(ARG_HOME, arguments).value();
    String options = argument(ARG_OPTIONS, arguments).value();
    String mainClassAndArgs = argument(ARG_MAIN, arguments).value();
    boolean wait = ((BooleanArgumentImpl) argument(ARG_INIT_SUSPEND, arguments)).booleanValue();
    String quote = argument(ARG_QUOTE, arguments).value();
    String exe = argument(ARG_VM_EXEC, arguments).value();
    String exePath = null;
    if (quote.length() > 1) {
        throw new IllegalConnectorArgumentsException("Invalid length", ARG_QUOTE);
    }
    if ((options.indexOf("-Djava.compiler=") != -1) && (options.toLowerCase().indexOf("-djava.compiler=none") == -1)) {
        throw new IllegalConnectorArgumentsException("Cannot debug with a JIT compiler", ARG_OPTIONS);
    }
    /*
         * Start listening.
         * If we're using the shared memory transport then we pick a
         * random address rather than using the (fixed) default.
         * Random() uses System.currentTimeMillis() as the seed
         * which can be a problem on windows (many calls to
         * currentTimeMillis can return the same value), so
         * we do a few retries if we get an IOException (we
         * assume the IOException is the filename is already in use.)
         */
    TransportService.ListenKey listenKey;
    if (usingSharedMemory) {
        Random rr = new Random();
        int failCount = 0;
        while (true) {
            try {
                String address = "javadebug" + String.valueOf(rr.nextInt(100000));
                listenKey = transportService().startListening(address);
                break;
            } catch (IOException ioe) {
                if (++failCount > 5) {
                    throw ioe;
                }
            }
        }
    } else {
        listenKey = transportService().startListening();
    }
    String address = listenKey.address();
    try {
        if (home.length() > 0) {
            exePath = home + File.separator + "bin" + File.separator + exe;
        } else {
            exePath = exe;
        }
        // Quote only if necessary in case the quote arg value is bogus
        if (hasWhitespace(exePath)) {
            exePath = quote + exePath + quote;
        }
        String xrun = "transport=" + transport().name() + ",address=" + address + ",suspend=" + (wait ? 'y' : 'n');
        // Quote only if necessary in case the quote arg value is bogus
        if (hasWhitespace(xrun)) {
            xrun = quote + xrun + quote;
        }
        String command = exePath + ' ' + options + ' ' + "-Xdebug " + "-Xrunjdwp:" + xrun + ' ' + mainClassAndArgs;
        // System.err.println("Command: \"" + command + '"');
        vm = launch(tokenizeCommand(command, quote.charAt(0)), address, listenKey, transportService());
    } finally {
        transportService().stopListening(listenKey);
    }
    return vm;
}
Also used : Random(java.util.Random) IOException(java.io.IOException) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 8 with VirtualMachine

use of com.sun.jdi.VirtualMachine in project gravel by gravel-st.

the class VMAcquirer method connect.

/**
 * Call this with the localhost port to connect to.
 */
public VirtualMachine connect(int port) throws IOException {
    String strPort = Integer.toString(port);
    AttachingConnector connector = getConnector();
    try {
        VirtualMachine vm = connect(connector, strPort);
        return vm;
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalStateException(e);
    }
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) AttachingConnector(com.sun.jdi.connect.AttachingConnector) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 9 with VirtualMachine

use of com.sun.jdi.VirtualMachine in project otertool by wuntee.

the class DebuggerWorkshop method connectToRemoteVirtualMachine.

@SuppressWarnings({ "restriction", "unchecked" })
public VirtualMachine connectToRemoteVirtualMachine(String host, int port) throws IOException, IllegalConnectorArgumentsException {
    SocketAttachingConnector c = (SocketAttachingConnector) getRemoteConnector();
    Map<String, Connector.Argument> arguments = c.defaultArguments();
    Connector.Argument hostnameArgument = arguments.get("hostname");
    hostnameArgument.setValue(host);
    Connector.Argument portArgument = arguments.get("port");
    portArgument.setValue(String.valueOf(port));
    arguments.put("hostname", hostnameArgument);
    arguments.put("port", portArgument);
    VirtualMachine vm = c.attach(arguments);
    return (vm);
}
Also used : SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) Connector(com.sun.jdi.connect.Connector) SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 10 with VirtualMachine

use of com.sun.jdi.VirtualMachine in project intellij-community by JetBrains.

the class JumpToTypeSourceAction method getObjectType.

@Nullable
private static ReferenceType getObjectType(@NotNull ReferenceType ref) {
    if (!(ref instanceof ArrayType)) {
        return ref;
    }
    final String elementTypeName = ref.name().replace("[]", "");
    final VirtualMachine vm = ref.virtualMachine();
    final List<ReferenceType> referenceTypes = vm.classesByName(elementTypeName);
    if (referenceTypes.size() == 1) {
        return referenceTypes.get(0);
    }
    return null;
}
Also used : ArrayType(com.sun.jdi.ArrayType) ReferenceType(com.sun.jdi.ReferenceType) VirtualMachine(com.sun.jdi.VirtualMachine) Nullable(org.jetbrains.annotations.Nullable)

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