Search in sources :

Example 1 with VirtualMachine

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

the class Testing method main.

/**
	 * @param args
	 * @throws IllegalConnectorArgumentsException 
	 * @throws IOException 
	 * @throws InterruptedException 
	 * @throws IncompatibleThreadStateException 
	 * @throws AbsentInformationException 
	 */
@SuppressWarnings("restriction")
public static void main(String[] args) throws IOException, IllegalConnectorArgumentsException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException {
    SocketAttachingConnector c = (SocketAttachingConnector) getConnector();
    Map<String, Connector.Argument> arguments = c.defaultArguments();
    Connector.Argument hostnameArgument = arguments.get("hostname");
    hostnameArgument.setValue("127.0.0.1");
    Connector.Argument portArgument = arguments.get("port");
    portArgument.setValue("8603");
    arguments.put("hostname", hostnameArgument);
    arguments.put("port", portArgument);
    VirtualMachine vm = c.attach(arguments);
    EventRequestManager mgr = vm.eventRequestManager();
    for (com.sun.jdi.ReferenceType rt : vm.allClasses()) {
        if (rt.name().toLowerCase().contains("wuntee")) {
            System.out.println(rt.name());
            for (Method m : rt.allMethods()) {
                System.out.println(" -" + m.name());
                if (m.name().contains("cache")) {
                    addBreakpointToMethod(m, mgr);
                }
            }
        }
    }
    /*		for(Method m : vm.classesByName("android.content.Intent").get(0).methodsByName("<init>")){
			System.out.println("Breakpoint: " + m.toString());
			
			Location location = m.location(); 
			BreakpointRequest bpr = mgr.createBreakpointRequest(location);
			bpr.enable();
		}*/
    //addIntentBreakpoints(vm);
    com.sun.jdi.event.EventQueue q = vm.eventQueue();
    while (true) {
        EventSet es = q.remove();
        Iterator<com.sun.jdi.event.Event> it = es.iterator();
        while (it.hasNext()) {
            com.sun.jdi.event.Event e = it.next();
            BreakpointEvent bpe = (BreakpointEvent) e;
            try {
                System.out.println("Method: " + bpe.location().method().toString());
                for (StackFrame sf : bpe.thread().frames()) {
                    System.out.println("Stackframe Method: " + sf.location().method().toString());
                    System.out.println("Arguments: ");
                    for (Value lv : sf.getArgumentValues()) {
                        System.out.println("\t--");
                        System.out.println("\t" + lv.toString());
                    }
                }
            } catch (Exception ex) {
                System.out.println("Error: ");
                ex.printStackTrace();
            }
            System.out.println();
            vm.resume();
        }
    }
}
Also used : SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) Connector(com.sun.jdi.connect.Connector) EventSet(com.sun.jdi.event.EventSet) Method(com.sun.jdi.Method) SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) EventRequestManager(com.sun.jdi.request.EventRequestManager) IOException(java.io.IOException) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) AbsentInformationException(com.sun.jdi.AbsentInformationException) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StackFrame(com.sun.jdi.StackFrame) Value(com.sun.jdi.Value) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 2 with VirtualMachine

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

the class DefaultSyntheticProvider method checkIsSynthetic.

public static boolean checkIsSynthetic(@NotNull TypeComponent typeComponent) {
    String name = typeComponent.name();
    if (DebuggerUtilsEx.isLambdaName(name)) {
        return false;
    } else {
        if (DebuggerUtilsEx.isLambdaClassName(typeComponent.declaringType().name())) {
            return true;
        }
    }
    VirtualMachine machine = typeComponent.virtualMachine();
    if (machine != null && machine.canGetSyntheticAttribute()) {
        return typeComponent.isSynthetic();
    } else {
        return name.contains("$");
    }
}
Also used : VirtualMachine(com.sun.jdi.VirtualMachine)

Example 3 with VirtualMachine

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

the class ConnectionServiceWrapper method createVirtualMachine.

public VirtualMachine createVirtualMachine() throws IOException {
    try {
        final VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager();
        //noinspection HardCodedStringLiteral
        final Method method = virtualMachineManager.getClass().getMethod("createVirtualMachine", new Class[] { myDelegateClass });
        return (VirtualMachine) method.invoke(virtualMachineManager, new Object[] { myConnection });
    } catch (NoSuchMethodException | IllegalAccessException e) {
        LOG.error(e);
    } catch (InvocationTargetException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        }
        if (cause instanceof VMDisconnectedException) {
            // ignore this one
            return null;
        }
        LOG.error(e);
    }
    return null;
}
Also used : VMDisconnectedException(com.sun.jdi.VMDisconnectedException) VirtualMachineManager(com.sun.jdi.VirtualMachineManager) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 4 with VirtualMachine

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

the class ExclusiveBind method main.

/*
     * - pick a TCP port
     * - Launch a debuggee in server=y,suspend=y,address=${port}
     * - Launch a second debuggee in server=y,suspend=n with the same port
     * - Second debuggee should fail with an error (address already in use)
     * - For clean-up we attach to the first debuggee and resume it.
     */
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 first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess("process1", process1, line -> line.equals("Listening for transport dt_socket at address: " + address), Math.round(5000 * Utils.TIMEOUT_FACTOR), TimeUnit.MILLISECONDS);
    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");
    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();
    // clean-up - attach to first debuggee and resume it
    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);
    vm.resume();
    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
Also used : AttachingConnector(com.sun.jdi.connect.AttachingConnector) Connector(com.sun.jdi.connect.Connector) AttachingConnector(com.sun.jdi.connect.AttachingConnector) ServerSocket(java.net.ServerSocket) Map(java.util.Map) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 5 with VirtualMachine

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

the class BadHandshakeTest 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 {
    int port = Utils.getFreePort();
    String address = String.valueOf(port);
    // launch the server debuggee
    Process process = launch(address, "Exit0");
    if (process == null) {
        throw new RuntimeException("Unable to start debugee");
    }
    // Connect to the debuggee and handshake with garbage
    Socket s = new Socket(InetAddress.getLocalHost(), port);
    s.getOutputStream().write("Here's a poke in the eye".getBytes("UTF-8"));
    s.close();
    // Re-connect and to a partial handshake - don't disconnect
    s = new Socket(InetAddress.getLocalHost(), port);
    s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
    // 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();
    process.waitFor();
}
Also used : AttachingConnector(com.sun.jdi.connect.AttachingConnector) Connector(com.sun.jdi.connect.Connector) AttachingConnector(com.sun.jdi.connect.AttachingConnector) Map(java.util.Map) Socket(java.net.Socket) VirtualMachine(com.sun.jdi.VirtualMachine)

Aggregations

VirtualMachine (com.sun.jdi.VirtualMachine)13 Connector (com.sun.jdi.connect.Connector)7 AttachingConnector (com.sun.jdi.connect.AttachingConnector)6 IOException (java.io.IOException)4 SocketAttachingConnector (com.sun.tools.jdi.SocketAttachingConnector)3 Map (java.util.Map)3 ThreadReference (com.sun.jdi.ThreadReference)2 VirtualMachineManager (com.sun.jdi.VirtualMachineManager)2 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 EventSet (com.sun.jdi.event.EventSet)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