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);
}
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();
}
}
}
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);
}
}
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);
}
}
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);
}
Aggregations