/** * Return the launching connector's arguments. */ static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) { Map<String,Connector.Argument> arguments = connector.defaultArguments(); for (String key : arguments.keySet()) { System.out.println(key); } Connector.Argument mainArg = (Connector.Argument)arguments.get("main"); if (mainArg == null) { throw new Error("Bad launching connector"); } mainArg.setValue(mainArgs); Connector.Argument optionsArg = (Connector.Argument)arguments.get("options"); if (optionsArg == null) { throw new Error("Bad launching connector"); } optionsArg.setValue(ARGUMENTS); return arguments; }
private static void putConnectionProperties(Session session, Map properties) { ListeningDICookie lc = session.lookupFirst(null, ListeningDICookie.class); Map<String, ? extends Connector.Argument> args = null; if (lc != null) { args = lc.getArgs(); properties.put("conn_port", lc.getPortNumber()); properties.put("conn_shmem", lc.getSharedMemoryName()); } else { AttachingDICookie ac = session.lookupFirst(null, AttachingDICookie.class); if (ac != null) { args = ac.getArgs(); properties.put("conn_host", ac.getHostName()); properties.put("conn_port", ac.getPortNumber()); properties.put("conn_shmem", ac.getSharedMemoryName()); properties.put("conn_pid", ac.getProcessID()); } } }
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; }
public static void main(String args[]) throws Exception { List<ListeningConnector> connectors = Bootstrap.virtualMachineManager().listeningConnectors(); for (ListeningConnector lc: connectors) { Map<String,Connector.Argument> cargs = lc.defaultArguments(); Connector.IntegerArgument timeout = (Connector.IntegerArgument)cargs.get("timeout"); /* * If the Connector has a argument named "timeout" then we set the timeout to 1 second * and start it listening on its default address. It should throw TranpsortTimeoutException. */ if (timeout != null) { System.out.println("Testing " + lc.name()); timeout.setValue(1000); System.out.println("Listening on: " + lc.startListening(cargs)); try { lc.accept(cargs); throw new RuntimeException("Connection accepted from some debuggee - unexpected!"); } catch (TransportTimeoutException e) { System.out.println("Timed out as expected.\n"); } lc.stopListening(cargs); } } }
/** * Return the launching connector's arguments. */ static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) { Map<String,Connector.Argument> arguments = connector.defaultArguments(); Connector.Argument mainArg = (Connector.Argument)arguments.get("main"); if (mainArg == null) { throw new Error("Bad launching connector"); } mainArg.setValue(mainArgs); Connector.Argument optionsArg = (Connector.Argument)arguments.get("options"); if (optionsArg == null) { throw new Error("Bad launching connector"); } optionsArg.setValue(ARGUMENTS); return arguments; }
private Map<String, Connector.Argument> mergeConnectorArgs(Connector connector, Map<String, String> argumentName2Value) { Map<String, Connector.Argument> arguments = connector.defaultArguments(); for (Entry<String, String> argumentEntry : argumentName2Value.entrySet()) { String name = argumentEntry.getKey(); String value = argumentEntry.getValue(); Connector.Argument argument = arguments.get(name); if (argument == null) { throw new IllegalArgumentException("Argument is not defined for connector:" + name + " -- " + connector.name()); } argument.setValue(value); } return arguments; }
public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws IOException, IllegalConnectorArgumentsException, VMStartException { String command = argument(ARG_COMMAND, arguments).value(); String address = argument(ARG_ADDRESS, arguments).value(); String quote = argument(ARG_QUOTE, arguments).value(); if (quote.length() > 1) { throw new IllegalConnectorArgumentsException("Invalid length", ARG_QUOTE); } TransportService.ListenKey listener = transportService.startListening(address); try { return launch(tokenizeCommand(command, quote.charAt(0)), address, listener, transportService); } finally { transportService.stopListening(listener); } }
public String startListening(Map<String,? extends Connector.Argument> args) throws IOException, IllegalConnectorArgumentsException { String port = argument(ARG_PORT, args).value(); String localaddr = argument(ARG_LOCALADDR, args).value(); // default to system chosen port if (port.length() == 0) { port = "0"; } if (localaddr.length() > 0) { localaddr = localaddr + ":" + port; } else { localaddr = port; } return super.startListening(localaddr, args); }
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(); }
/** * 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 arguments = connector.defaultArguments(); ((Connector.Argument) arguments.get("hostname")).setValue(HOST_NAME); ((Connector.Argument) arguments.get("port")).setValue(port); jvm = connector.attach(arguments); EventRequestManager manager = jvm.eventRequestManager(); request = methodEntryRequests(manager, TRIGGER_NAME); }
@BeforeClass public static void connect() throws Exception { SocketAttachingConnector socketConnector = null; for (Connector connector : Bootstrap.virtualMachineManager().allConnectors()) { if (connector instanceof SocketAttachingConnector) { socketConnector = (SocketAttachingConnector) connector; } } if (socketConnector == null) { throw new RuntimeException("Failed to find SocketAttachingConnector"); } Map<String, ? extends Connector.Argument> args = socketConnector.defaultArguments(); Connector.IntegerArgument port = (Connector.IntegerArgument) args.get("port"); port.setValue(PORT); Connector.StringArgument hostname = (Connector.StringArgument) args.get("hostname"); hostname.setValue("localhost"); virtualMachine = socketConnector.attach(args); }