com.sun.jdi.connect.IllegalConnectorArgumentsException Java Examples

The following examples show how to use com.sun.jdi.connect.IllegalConnectorArgumentsException. 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: ChildSession.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #2
Source File: ChildSession.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #3
Source File: ChildSession.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #4
Source File: ChildSession.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #5
Source File: ChildSession.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #6
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
    // in JDK 10, the first AttachingConnector is not the one we want
    final String SUN_ATTACH_CONNECTOR = "com.sun.tools.jdi.SocketAttachingConnector";
    for (AttachingConnector con : connectors) {
        if (con.getClass().getName().equals(SUN_ATTACH_CONNECTOR)) {
            connector = con;
            break;
        }
    }
    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));
}
 
Example #7
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Launch a debuggee in suspend mode.
 * @see #launch(VirtualMachineManager, String, String, String, 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,
        String javaExec)
        throws IOException, IllegalConnectorArgumentsException, VMStartException {
    return DebugUtility.launch(vmManager,
            mainClass,
            programArguments,
            vmArguments,
            String.join(File.pathSeparator, modulePaths),
            String.join(File.pathSeparator, classPaths),
            cwd,
            envVars,
            javaExec);
}
 
Example #8
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Launch a debuggee in suspend mode.
 * @see #launch(VirtualMachineManager, String, String, 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);
}
 
Example #9
Source File: LaunchWithDebuggingDelegate.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Process launch(LaunchArguments launchArguments, IDebugAdapterContext context)
        throws IOException, IllegalConnectorArgumentsException, VMStartException {
    IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class);

    IDebugSession debugSession = DebugUtility.launch(
            vmProvider.getVirtualMachineManager(),
            launchArguments.mainClass,
            launchArguments.args,
            launchArguments.vmArgs,
            Arrays.asList(launchArguments.modulePaths),
            Arrays.asList(launchArguments.classPaths),
            launchArguments.cwd,
            LaunchRequestHandler.constructEnvironmentVariables(launchArguments),
            launchArguments.javaExec);
    context.setDebugSession(debugSession);

    logger.info("Launching debuggee VM succeeded.");
    return debugSession.process();
}
 
Example #10
Source File: JDWPAgent.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Try to get an instrumentation instance using JDWP */
public static synchronized JDWPAgent get() throws IOException, IllegalConnectorArgumentsException {
    // There can be only one
    if (instance != null) {
        return instance;
    }
    
    // Get the JDWP port
    Properties props = sun.misc.VMSupport.getAgentProperties();
    String jdwp_address = props.getProperty("sun.jdwp.listenerAddress");
    
    // If no JDWP address, then the debug argument isn't included
    if (jdwp_address == null) {
        System.err.println("Could not acquire JDWP address to attach dynamic instrumentation. "
                + "Ensure JVM runs with argument -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0");
        return null;
    }
    
    // Extract the port and return the instance;
    System.out.println("JDWPAgent started with address " + jdwp_address);
    String jdwp_port = jdwp_address.substring(jdwp_address.lastIndexOf(':') + 1);
    instance = new JDWPAgent(jdwp_port);
    return instance;
}
 
Example #11
Source File: TestJDWPAgentDebug.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testBadModification2() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException, IllegalConnectorArgumentsException {
    // Rewrite method
    DynamicModification badModification = new DynamicModification() {
        public Collection<String> affects() {
            return Lists.newArrayList(TestJDWPAgentDebug.class.getName());
        }
        public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException {
            CtClass cls = arg0.getCtClass(TestJDWPAgentDebug.class.getName());
            cls.getMethods()[0].insertBefore("definitely not code...");
        }
    };
    JDWPAgent dynamic = JDWPAgent.get();
    // Modification should just be ignored since it throws a notfoundexception
    try {
        dynamic.install(badModification);
        fail();
    } catch (CannotCompileException e) {
    }
}
 
Example #12
Source File: ChildSession.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #13
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 #14
Source File: ChildSession.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #15
Source File: ChildSession.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #16
Source File: ChildSession.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #17
Source File: ChildSession.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #18
Source File: ChildSession.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #19
Source File: ChildSession.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static private VirtualMachine generalGetVM(OutputListener diagnostics,
                                           LaunchingConnector connector,
                                           Map<String, Connector.Argument> arguments) {
    VirtualMachine vm = null;
    try {
        diagnostics.putString("Starting child.");
        vm = connector.launch(arguments);
    } catch (IOException ioe) {
        diagnostics.putString("Unable to start child: " + ioe.getMessage());
    } catch (IllegalConnectorArgumentsException icae) {
        diagnostics.putString("Unable to start child: " + icae.getMessage());
    } catch (VMStartException vmse) {
        diagnostics.putString("Unable to start child: " + vmse.getMessage() + '\n');
        dumpFailedLaunchInfo(diagnostics, vmse.process());
    }
    return vm;
}
 
Example #20
Source File: HelloWorld.java    From java-svc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws AttachException, IOException, IllegalConnectorArgumentsException {
	if (args.length != 2) {
		System.out.println("Must provide host and port!");
		System.exit(2);
	}
	String host = args[0];
	String port = args[1];
	VirtualMachine vm = null;
	try {
		vm = connect(host, port);
		vm.resume();
		System.out.println("The process at " + JdiUtils.prettyPrint(host, port) + " is running " + vm.name()
				+ " version " + vm.version());
		System.out.println("Press <enter> to quit, and to terminate the application connected to.");
		System.in.read();
		vm.exit(0);
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("Could not connect to " + JdiUtils.prettyPrint(host, port));
		System.out.println("Message was: " + e.getMessage() + "\nExiting...");
	}
}
 
Example #21
Source File: HotSwapper.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Connects to the JVM.
 *
 * @param port	the port number used for the connection to the JVM.
 */
public HotSwapper(String port)
    throws IOException, IllegalConnectorArgumentsException
{
    jvm = null;
    request = null;
    newClassFiles = null;
    trigger = new Trigger();
    AttachingConnector connector
        = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");

    Map<String,Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(HOST_NAME);
    arguments.get("port").setValue(port);
    jvm = connector.attach(arguments);
    EventRequestManager manager = jvm.eventRequestManager();
    request = methodEntryRequests(manager, TRIGGER_NAME);
}
 
Example #22
Source File: LineBreakpointTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doTestBreakpointComplete (
    int line, 
    String condition, 
    int conditionResult
) throws IOException, IllegalConnectorArgumentsException,
DebuggerStartException {
    try {
        LineBreakpoint lb = doTestBreakpoint (
            line, 
            condition, 
            conditionResult
        );
        if ( condition == null || 
             conditionResult == JPDABreakpointEvent.CONDITION_TRUE
        ) {
            support.doContinue();
            support.waitState (JPDADebugger.STATE_DISCONNECTED);
        }
        DebuggerManager.getDebuggerManager ().removeBreakpoint (lb);
    } finally {
        if (support != null) support.doFinish();
    }
}
 
Example #23
Source File: HotSwapperJpda.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Connects to the JVM.
 *
 * @param port the port number used for the connection to the JVM.
 */
public HotSwapperJpda(String port)
        throws IOException, IllegalConnectorArgumentsException {
    jvm = null;
    request = null;
    newClassFiles = null;
    trigger = new Trigger();
    AttachingConnector connector
        = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");

    Map<String,Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(HOST_NAME);
    arguments.get("port").setValue(port);
    jvm = connector.attach(arguments);
    EventRequestManager manager = jvm.eventRequestManager();
    request = methodEntryRequests(manager, TRIGGER_NAME);
}
 
Example #24
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 {
        return connect(connector, strPort);
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #25
Source File: TestJDWPAgentDebug.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testBadModification() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException, CannotCompileException, IllegalConnectorArgumentsException {
    // Rewrite method
    DynamicModification badModification = new DynamicModification() {
        public Collection<String> affects() {
            return Lists.newArrayList(TestJDWPAgentDebug.class.getName());
        }
        public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException {
            arg0.getCtClass("edu.brown.cs.systems.pivottracing.dynamicinstrumentation.NotaRealClass");
        }
    };
    JDWPAgent dynamic = JDWPAgent.get();
    // Modification should just be ignored since it throws a notfoundexception
    dynamic.install(badModification);
}
 
Example #26
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 #27
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private VirtualMachine launchTarget(String mainArgs) throws GuidanceException {
    final LaunchingConnector connector = findLaunchingConnector();
    final Map<String, Connector.Argument> arguments = connectorArguments(connector, mainArgs);
    try {
        return connector.launch(arguments);
    } catch (IOException | IllegalConnectorArgumentsException | VMStartException exc) {
        throw new GuidanceException(exc);
    }
}
 
Example #28
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine connect(AttachingConnector connector, String port)
        throws IllegalConnectorArgumentsException,
        IOException {
    Map<String, Connector.Argument> args = connector.defaultArguments();
    Connector.Argument pidArgument = args.get("port");
    args.get("hostname").setValue("localhost");
    if (pidArgument == null) {
        throw new IllegalStateException();
    }
    pidArgument.setValue(port);

    return connector.attach(args);
}
 
Example #29
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #30
Source File: SimpleLaunchingConnector.java    From jdk8u_jdk 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);
}