Search in sources :

Example 1 with IllegalConnectorArgumentsException

use of com.sun.jdi.connect.IllegalConnectorArgumentsException in project che by eclipse.

the class JavaDebugger method connect.

/**
     * Attach to a JVM that is already running at specified host.
     *
     * @throws DebuggerException
     *         when connection to Java VM is not established
     */
private void connect() throws DebuggerException {
    final String connectorName = "com.sun.jdi.SocketAttach";
    AttachingConnector connector = connector(connectorName);
    if (connector == null) {
        throw new DebuggerException(String.format("Unable connect to target Java VM. Requested connector '%s' not found. ", connectorName));
    }
    Map<String, Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(host);
    ((Connector.IntegerArgument) arguments.get("port")).setValue(port);
    int attempt = 0;
    for (; ; ) {
        try {
            Thread.sleep(2000);
            vm = connector.attach(arguments);
            vm.suspend();
            break;
        } catch (UnknownHostException | IllegalConnectorArgumentsException e) {
            throw new DebuggerException(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            if (++attempt > 10) {
                throw new DebuggerException(e.getMessage(), e);
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
            }
        } catch (InterruptedException ignored) {
        }
    }
    eventsCollector = new EventsCollector(vm.eventQueue(), this);
    LOG.debug("Connect {}:{}", host, port);
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) UnknownHostException(java.net.UnknownHostException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) AttachingConnector(com.sun.jdi.connect.AttachingConnector) IOException(java.io.IOException) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint)

Example 2 with IllegalConnectorArgumentsException

use of com.sun.jdi.connect.IllegalConnectorArgumentsException 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 3 with IllegalConnectorArgumentsException

use of com.sun.jdi.connect.IllegalConnectorArgumentsException in project HotswapAgent by HotswapProjects.

the class JDIRedefiner method connect.

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);
    }
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) Argument(com.sun.jdi.connect.Connector.Argument) AttachingConnector(com.sun.jdi.connect.AttachingConnector) VirtualMachineManager(com.sun.jdi.VirtualMachineManager)

Example 4 with IllegalConnectorArgumentsException

use of com.sun.jdi.connect.IllegalConnectorArgumentsException 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 5 with IllegalConnectorArgumentsException

use of com.sun.jdi.connect.IllegalConnectorArgumentsException in project jdk8u_jdk by JetBrains.

the class SimpleLaunchingConnector method launch.

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);
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) TransportService(com.sun.jdi.connect.spi.TransportService) Connection(com.sun.jdi.connect.spi.Connection)

Aggregations

IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)5 AttachingConnector (com.sun.jdi.connect.AttachingConnector)3 VirtualMachine (com.sun.jdi.VirtualMachine)2 IOException (java.io.IOException)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)1 Method (com.sun.jdi.Method)1 StackFrame (com.sun.jdi.StackFrame)1 Value (com.sun.jdi.Value)1 VirtualMachineManager (com.sun.jdi.VirtualMachineManager)1 Connector (com.sun.jdi.connect.Connector)1 Argument (com.sun.jdi.connect.Connector.Argument)1 Connection (com.sun.jdi.connect.spi.Connection)1 TransportService (com.sun.jdi.connect.spi.TransportService)1 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)1 EventSet (com.sun.jdi.event.EventSet)1 EventRequestManager (com.sun.jdi.request.EventRequestManager)1 SocketAttachingConnector (com.sun.tools.jdi.SocketAttachingConnector)1 UnknownHostException (java.net.UnknownHostException)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1