use of com.sun.jdi.ThreadReference in project gravel by gravel-st.
the class VMTargetRemoteTest method testEvaluate.
@Test
public void testEvaluate() throws Throwable {
ObjectReference promise = remote.evaluateForked("3+4");
ThreadReference thread = ((ThreadReference) remote.invokeMethod(promise, "thread"));
Value result1 = remote.invokeMethod(promise, "result");
Value ex = remote.invokeMethod(promise, "throwable");
printThreadState();
VMTargetStarter.sleep(100);
printThreadState();
boolean isFinished = ((BooleanValue) remote.invokeMethod(promise, "isFinished")).booleanValue();
assertTrue(isFinished);
ObjectReference result = (ObjectReference) remote.invokeMethod(promise, "result");
IntegerValue intValue = (IntegerValue) remote.invokeMethod(result, "intValue");
assertEquals(7, intValue.intValue());
}
use of com.sun.jdi.ThreadReference in project gravel by gravel-st.
the class VMTargetRemoteTest method printThreadState.
private void printThreadState() {
System.out.println();
List<ThreadReference> allThreads = remote.vm().allThreads();
for (ThreadReference threadReference : allThreads) {
System.out.println(threadReference + " isSuspended: " + threadReference.isSuspended() + " suspendCount: " + threadReference.suspendCount());
}
}
use of com.sun.jdi.ThreadReference in project gravel by gravel-st.
the class VMRemoteInstance method invoke.
private Value invoke(ObjectReference receiver, Method method, Value... arguments) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
String args = ArrayExtensions.join_with_(arguments, new Block1<String, Value>() {
@Override
public String value_(Value arg) {
return arg.toString();
}
}, ", ");
System.out.print("" + debugPort() + " Invoking " + receiver + ">>" + method.name() + "(" + args + ")");
List<ThreadReference> suspendedThreads = OrderedCollectionExtensions.select_(receiver.virtualMachine().allThreads(), new Predicate1<ThreadReference>() {
@Override
public boolean value_(ThreadReference arg1) {
return arg1.isSuspended();
}
});
Value result = receiver.invokeMethod(bootThread(), method, Arrays.asList(arguments), 0);
System.out.println(" -> " + result);
List<ThreadReference> allThreads = receiver.virtualMachine().allThreads();
for (ThreadReference threadReference : allThreads) {
if (suspendedThreads.contains(threadReference)) {
System.out.println("- Keep suspended: " + threadReference + " suspendCount: " + threadReference.suspendCount());
} else {
System.out.println("--------- Resume: " + threadReference + " suspendCount: " + threadReference.suspendCount());
threadReference.resume();
}
}
return result;
}
use of com.sun.jdi.ThreadReference in project jdk8u_jdk by JetBrains.
the class LambdaStepTest method runTests.
/********** test core **********/
protected void runTests() throws Exception {
// ## Normal instance method
BreakpointEvent bpe = startTo("LambdaStepTestTarg", "instanceTest", "()V");
ThreadReference thread = bpe.thread();
// step over allocation
StepEvent se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into test();
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
StackFrame frame = se.thread().frame(0);
LocalVariable lv = frame.visibleVariableByName("from");
System.out.println(lv);
StringReference sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("test")) {
throw new Exception("Unexpected variable value in instanceTest: " + sr.value());
}
// ## Lambda method
bpe = resumeTo("LambdaStepTestTarg", "lambdaTest", "()V");
thread = bpe.thread();
// step over allocation
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into run() of the lambda
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
frame = se.thread().frame(0);
lv = frame.visibleVariableByName("from");
System.out.println(lv);
sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("lambda")) {
throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
}
// ## Default method
bpe = resumeTo("LambdaStepTestTarg", "defaultTest", "()V");
thread = bpe.thread();
// step over allocation
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into defaultMethod()
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
frame = se.thread().frame(0);
lv = frame.visibleVariableByName("from");
System.out.println(lv);
sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("default")) {
throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
}
/*
* resume the target listening for events
*/
listenUntilVMDisconnect();
}
use of com.sun.jdi.ThreadReference in project jdk8u_jdk by JetBrains.
the class ProcessAttachDebugger method main.
public static void main(String[] main_args) throws Exception {
String pid = main_args[0];
// find ProcessAttachingConnector
List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors();
AttachingConnector ac = null;
for (AttachingConnector c : l) {
if (c.name().equals("com.sun.jdi.ProcessAttach")) {
ac = c;
break;
}
}
if (ac == null) {
throw 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);
System.out.println("Attached! Now listing threads ...");
for (ThreadReference thr : vm.allThreads()) {
System.out.println(thr);
}
System.out.println("Debugger done.");
}
Aggregations