use of com.sun.jdi.VirtualMachine 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.VirtualMachine in project intellij-community by JetBrains.
the class DefaultSyntheticProvider method checkIsSynthetic.
public static boolean checkIsSynthetic(@NotNull TypeComponent typeComponent) {
String name = typeComponent.name();
if (DebuggerUtilsEx.isLambdaName(name)) {
return false;
} else {
if (DebuggerUtilsEx.isLambdaClassName(typeComponent.declaringType().name())) {
return true;
}
}
VirtualMachine machine = typeComponent.virtualMachine();
if (machine != null && machine.canGetSyntheticAttribute()) {
return typeComponent.isSynthetic();
} else {
return name.contains("$");
}
}
use of com.sun.jdi.VirtualMachine 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.VirtualMachine in project jdk8u_jdk by JetBrains.
the class ExclusiveBind method main.
/*
* - pick a TCP port
* - Launch a debuggee in server=y,suspend=y,address=${port}
* - Launch a second debuggee in server=y,suspend=n with the same port
* - Second debuggee should fail with an error (address already in use)
* - For clean-up we attach to the first debuggee and resume it.
*/
public static void main(String[] args) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the first debuggee
ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
// start the debuggee and wait for the "ready" message
Process p = ProcessTools.startProcess("process1", process1, line -> line.equals("Listening for transport dt_socket at address: " + address), Math.round(5000 * Utils.TIMEOUT_FACTOR), TimeUnit.MILLISECONDS);
// launch a second debuggee with the same address
ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");
// get exit status from second debuggee
int exitCode = ProcessTools.startProcess("process2", process2).waitFor();
// clean-up - attach to first debuggee and resume it
AttachingConnector conn = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg = (Connector.IntegerArgument) conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
vm.resume();
// if the second debuggee ran to completion then we've got a problem
if (exitCode == 0) {
throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
} else {
System.out.println("Test passed - second debuggee correctly failed to bind");
}
}
use of com.sun.jdi.VirtualMachine in project jdk8u_jdk by JetBrains.
the class BadHandshakeTest method main.
/*
* - pick a TCP port
* - Launch a server debuggee: server=y,suspend=y,address=${port}
* - run it to VM death
* - verify we saw no error
*/
public static void main(String[] args) throws Exception {
int port = Utils.getFreePort();
String address = String.valueOf(port);
// launch the server debuggee
Process process = launch(address, "Exit0");
if (process == null) {
throw new RuntimeException("Unable to start debugee");
}
// Connect to the debuggee and handshake with garbage
Socket s = new Socket(InetAddress.getLocalHost(), port);
s.getOutputStream().write("Here's a poke in the eye".getBytes("UTF-8"));
s.close();
// Re-connect and to a partial handshake - don't disconnect
s = new Socket(InetAddress.getLocalHost(), port);
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
// attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg = (Connector.IntegerArgument) conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event : evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
process.waitFor();
}
Aggregations