use of com.sun.jdi.VirtualMachineManager in project intellij-community by JetBrains.
the class ConnectionServiceWrapper method createVirtualMachine.
public VirtualMachine createVirtualMachine() throws IOException {
try {
final VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager();
//noinspection HardCodedStringLiteral
final Method method = virtualMachineManager.getClass().getMethod("createVirtualMachine", new Class[] { myDelegateClass });
return (VirtualMachine) method.invoke(virtualMachineManager, new Object[] { myConnection });
} catch (NoSuchMethodException | IllegalAccessException e) {
LOG.error(e);
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
}
if (cause instanceof VMDisconnectedException) {
// ignore this one
return null;
}
LOG.error(e);
}
return null;
}
use of com.sun.jdi.VirtualMachineManager 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.VirtualMachineManager in project ceylon by eclipse.
the class TracerImpl method start.
public void start() throws Exception {
VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
LaunchingConnector conn = vmm.defaultConnector();
Map<String, Argument> defaultArguments = conn.defaultArguments();
defaultArguments.get("main").setValue(mainClass);
defaultArguments.get("options").setValue("-cp " + classPath);
System.out.println(defaultArguments);
vm = conn.launch(defaultArguments);
err = vm.process().getErrorStream();
out = vm.process().getInputStream();
eq = vm.eventQueue();
rm = vm.eventRequestManager();
outer: while (true) {
echo(err, System.err);
echo(out, System.out);
events = eq.remove();
for (Event event : events) {
if (event instanceof VMStartEvent) {
System.out.println(event);
break outer;
} else if (event instanceof VMDisconnectEvent || event instanceof VMDeathEvent) {
System.out.println(event);
vm = null;
rm = null;
eq = null;
break outer;
}
}
events.resume();
}
echo(err, System.err);
echo(out, System.out);
}
use of com.sun.jdi.VirtualMachineManager in project warn-report by saaavsaaa.
the class debugger method rTest.
@Test
public void rTest() throws Exception {
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors = vmm.attachingConnectors();
SocketAttachingConnector sac = null;
for (AttachingConnector ac : connectors) {
if (ac instanceof SocketAttachingConnector) {
sac = (SocketAttachingConnector) ac;
break;
}
}
if (sac == null) {
System.out.println("JDI error");
return;
}
Map arguments = sac.defaultArguments();
Connector.Argument hostArg = (Connector.Argument) arguments.get(HOST);
Connector.Argument portArg = (Connector.Argument) arguments.get(PORT);
hostArg.setValue("127.0.0.1");
portArg.setValue(String.valueOf(9999));
vm = sac.attach(arguments);
List<ReferenceType> classesByName = vm.classesByName("cn.tellwhy.DailyTest");
if (classesByName == null || classesByName.size() == 0) {
System.out.println("No class found");
return;
}
ReferenceType rt = classesByName.get(0);
List<Method> methodsByName = rt.methodsByName("daily");
if (methodsByName == null || methodsByName.size() == 0) {
System.out.println("No method found");
return;
}
Method method = methodsByName.get(0);
vm.setDebugTraceMode(VirtualMachine.TRACE_EVENTS);
vm.resume();
EventRequestManager erm = vm.eventRequestManager();
MethodEntryRequest methodEntryRequest = erm.createMethodEntryRequest();
methodEntryRequest.addClassFilter(rt);
methodEntryRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
methodEntryRequest.enable();
BreakpointRequest breakpointRequest = erm.createBreakpointRequest(method.location());
breakpointRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
breakpointRequest.enable();
eventLoop();
}
use of com.sun.jdi.VirtualMachineManager in project warn-report by saaavsaaa.
the class debugger method test.
@Test
public void test() throws VMStartException, IllegalConnectorArgumentsException, IOException {
// Debugger 通过 Bootstrap 获取唯一的虚拟机管理器
VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager();
// 虚拟机管理器将在第一次被调用时初始化可用的链接器
LaunchingConnector defaultConnector = virtualMachineManager.defaultConnector();
// 启动目标程序,连接调试器(Debugger)与目标虚拟机(VirtualMachine)
Map<String, Connector.Argument> arguments = defaultConnector.defaultArguments();
Connector.Argument arg = arguments.get("main");
arg.setValue("cn.tellwhy.DailyTest");
VirtualMachine targetVM = defaultConnector.launch(arguments);
// 获取 Mirror 对象实例的虚拟机
VirtualMachine virtualMachine = targetVM.virtualMachine();
virtualMachine.allClasses().forEach(a -> System.out.println("===============:" + a.name()));
}
Aggregations