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); } }
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) }); }
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) }); }
/** * Launch a debuggee in suspend mode. * @see {@link #launch(VirtualMachineManager, String, String, String, String, String)} */ public static IDebugSession launch(VirtualMachineManager vmManager, String mainClass, String programArguments, String vmArguments, List<String> modulePaths, List<String> classPaths, String cwd, String[] envVars) throws IOException, IllegalConnectorArgumentsException, VMStartException { return DebugUtility.launch(vmManager, mainClass, programArguments, vmArguments, String.join(File.pathSeparator, modulePaths), String.join(File.pathSeparator, classPaths), cwd, envVars); }
public PermissionDebugger attach() throws IOException, IllegalConnectorArgumentsException { VirtualMachineManager vmm = Bootstrap.virtualMachineManager(); List<AttachingConnector> connectors = vmm.attachingConnectors(); AttachingConnector connector = connectors .stream() .filter(c -> c.transport().name().equals(transport)) .findFirst() .orElseThrow( () -> new IOException(String.format("Failed to find transport %s", transport))); Map<String, Argument> map = connector.defaultArguments(); Argument portArg = map.get(PORT_KEY); portArg.setValue(port); map.put(PORT_KEY, portArg); vm = connector.attach(map); return this; }
protected VirtualMachine launch(String[] commandArray, String address, TransportService.ListenKey listenKey, TransportService ts) throws IOException, VMStartException { Helper helper = new Helper(commandArray, address, listenKey, ts); helper.launchAndAccept(); VirtualMachineManager manager = Bootstrap.virtualMachineManager(); return manager.createVirtualMachine(helper.connection(), helper.process()); }
public static VirtualMachineManager virtualMachineManager() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { JDIPermission vmmPermission = new JDIPermission("virtualMachineManager"); sm.checkPermission(vmmPermission); } synchronized (lock) { if (vmm == null) { vmm = new VirtualMachineManagerImpl(); } } return vmm; }
@Override public synchronized VirtualMachineManager getVirtualMachineManager() { if (vmManager == null) { vmManager = new AdvancedVirtualMachineManager(); } return vmManager; }
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) }); }
@Test public void test() { VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager(); List<Connector> allConnectors = virtualMachineManager.allConnectors(); List<VirtualMachine> connectedVirtualMachines = virtualMachineManager.connectedVirtualMachines(); System.out.println(allConnectors); System.out.println(connectedVirtualMachines); }
private AttachingConnector getConnector() { VirtualMachineManager vmManager = Bootstrap.virtualMachineManager(); for (Connector connector : vmManager.attachingConnectors()) { if ("com.sun.jdi.SocketAttach".equals(connector.name())) { return (AttachingConnector) connector; } } throw new IllegalStateException(); }
public static VirtualMachineManager virtualMachineManager() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { JDIPermission vmmPermission = new JDIPermission("virtualMachineManager"); sm.checkPermission(vmmPermission); } synchronized (lock) { if (vmm == null) { vmm = new F3VirtualMachineManager(); } } return vmm; }
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(); }
public static JPDASupport attach (String mainClass, String[] args, File[] classPath) throws IOException, DebuggerStartException { Process process = launchVM (mainClass, args, classPath, "", true); String line = readLine (process.getInputStream ()); int port = Integer.parseInt (line.substring (line.lastIndexOf (':') + 1).trim ()); ProcessIO pio = new ProcessIO (process); pio.go (); VirtualMachineManager vmm = Bootstrap.virtualMachineManager(); List aconnectors = vmm.attachingConnectors(); AttachingConnector connector = null; for (Iterator i = aconnectors.iterator(); i.hasNext();) { AttachingConnector ac = (AttachingConnector) i.next(); Transport t = ac.transport (); if (t != null && t.name().equals("dt_socket")) { connector = ac; break; } } if (connector == null) throw new RuntimeException ("No attaching socket connector available"); JPDADebugger jpdaDebugger = JPDADebugger.attach ( "localhost", port, createServices () ); return new JPDASupport (jpdaDebugger); }
public List<VirtualMachine> connectedVirtualMachines() { VirtualMachineManager pvmm = Bootstrap.virtualMachineManager(); return F3Wrapper.wrapVirtualMachines(pvmm.connectedVirtualMachines()); }
public VirtualMachine createVirtualMachine(Connection connection, Process process) throws IOException { VirtualMachineManager pvmm = Bootstrap.virtualMachineManager(); return F3Wrapper.wrap(pvmm.createVirtualMachine(connection, process)); }
public VirtualMachine createVirtualMachine(Connection connection) throws IOException { VirtualMachineManager pvmm = Bootstrap.virtualMachineManager(); return F3Wrapper.wrap(pvmm.createVirtualMachine(connection)); }
VirtualMachineImpl(VirtualMachineManager manager, Connection connection, Process process, int sequenceNumber) { super(null); // Can't use super(this) vm = this; this.vmManager = (VirtualMachineManagerImpl)manager; this.process = process; this.sequenceNumber = sequenceNumber; /* Create ThreadGroup to be used by all threads servicing * this VM. */ threadGroupForJDI = new ThreadGroup(vmManager.mainGroupForJDI(), "JDI [" + this.hashCode() + "]"); /* * Set up a thread to communicate with the target VM over * the specified transport. */ target = new TargetVM(this, connection); /* * Set up a thread to handle events processed internally * the JDI implementation. */ EventQueueImpl internalEventQueue = new EventQueueImpl(this, target); new InternalEventHandler(this, internalEventQueue); /* * Initialize client access to event setting and handling */ eventQueue = new EventQueueImpl(this, target); eventRequestManager = new EventRequestManagerImpl(this); target.start(); /* * Many ids are variably sized, depending on target VM. * Find out the sizes right away. */ JDWP.VirtualMachine.IDSizes idSizes; try { idSizes = JDWP.VirtualMachine.IDSizes.process(vm); } catch (JDWPException exc) { throw exc.toJDIException(); } sizeofFieldRef = idSizes.fieldIDSize; sizeofMethodRef = idSizes.methodIDSize; sizeofObjectRef = idSizes.objectIDSize; sizeofClassRef = idSizes.referenceTypeIDSize; sizeofFrameRef = idSizes.frameIDSize; sizeofModuleRef = idSizes.objectIDSize; /** * Set up requests needed by internal event handler. * Make sure they are distinguished by creating them with * an internal event request manager. * * Warning: create events only with SUSPEND_NONE policy. * In the current implementation other policies will not * be handled correctly when the event comes in. (notfiySuspend() * will not be properly called, and if the event is combined * with external events in the same set, suspend policy is not * correctly determined for the internal vs. external event sets) */ internalEventRequestManager = new EventRequestManagerImpl(this); EventRequest er = internalEventRequestManager.createClassPrepareRequest(); er.setSuspendPolicy(EventRequest.SUSPEND_NONE); er.enable(); er = internalEventRequestManager.createClassUnloadRequest(); er.setSuspendPolicy(EventRequest.SUSPEND_NONE); er.enable(); /* * Tell other threads, notably TargetVM, that initialization * is complete. */ notifyInitCompletion(); }
/** * Attach to an existing debuggee VM. * @param vmManager * the virtual machine manager * @param hostName * the machine where the debuggee VM is launched on * @param port * the debug port that the debuggee VM exposed * @param attachTimeout * the timeout when attaching to the debuggee VM * @return an instance of IDebugSession * @throws IOException * when unable to attach. * @throws IllegalConnectorArgumentsException * when one of the connector arguments is invalid. */ public static IDebugSession attach(VirtualMachineManager vmManager, String hostName, int port, int attachTimeout) throws IOException, IllegalConnectorArgumentsException { List<AttachingConnector> connectors = vmManager.attachingConnectors(); AttachingConnector connector = connectors.get(0); Map<String, Argument> arguments = connector.defaultArguments(); arguments.get(HOSTNAME).setValue(hostName); arguments.get(PORT).setValue(String.valueOf(port)); arguments.get(TIMEOUT).setValue(String.valueOf(attachTimeout)); return new DebugSession(connector.attach(arguments)); }
/** * Get a VirtualMachineManager whose default launching connector is an instance of * org.f3.jdi.connect.F3LaunchingConnector. This VirtualMachineManager will be aware * of all the connectors in F3-JDI as well as the connectors in the normal JDI implementation. * * @return a VirtualMachineManager */ public static VirtualMachineManager virtualMachineManager() { return F3VirtualMachineManager.virtualMachineManager(); }
/** * Redirects initialization of JDI implementation to * @link org.apache.harmony.tools.internal.jdi.Bootstrap#virtualMachineManager(). * * @return instance of VirtualMachineManager created by JDI implementation */ static public VirtualMachineManager virtualMachineManager() { return org.apache.harmony.tools.internal.jdi.Bootstrap.virtualMachineManager(); }