Search in sources :

Example 1 with ThreadReference

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());
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) BooleanValue(com.sun.jdi.BooleanValue) IntegerValue(com.sun.jdi.IntegerValue) IntegerValue(com.sun.jdi.IntegerValue) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) ThreadReference(com.sun.jdi.ThreadReference) Test(org.junit.Test)

Example 2 with ThreadReference

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());
    }
}
Also used : ThreadReference(com.sun.jdi.ThreadReference)

Example 3 with ThreadReference

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;
}
Also used : Value(com.sun.jdi.Value) ThreadReference(com.sun.jdi.ThreadReference)

Example 4 with ThreadReference

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();
}
Also used : BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StepEvent(com.sun.jdi.event.StepEvent) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) ThreadReference(com.sun.jdi.ThreadReference) StringReference(com.sun.jdi.StringReference)

Example 5 with ThreadReference

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.");
}
Also used : AttachingConnector(com.sun.jdi.connect.AttachingConnector) Connector(com.sun.jdi.connect.Connector) AttachingConnector(com.sun.jdi.connect.AttachingConnector) ThreadReference(com.sun.jdi.ThreadReference) VirtualMachine(com.sun.jdi.VirtualMachine)

Aggregations

ThreadReference (com.sun.jdi.ThreadReference)13 ObjectReference (com.sun.jdi.ObjectReference)3 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)2 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)2 StackCapturingLineBreakpoint (com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint)2 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 BooleanValue (com.sun.jdi.BooleanValue)2 StringReference (com.sun.jdi.StringReference)2 Value (com.sun.jdi.Value)2 VirtualMachine (com.sun.jdi.VirtualMachine)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 JobScheduler (com.intellij.concurrency.JobScheduler)1 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 ThreadReferenceProxy (com.intellij.debugger.engine.jdi.ThreadReferenceProxy)1 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)1 RequestManagerImpl (com.intellij.debugger.engine.requests.RequestManagerImpl)1 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)1 NotificationType (com.intellij.notification.NotificationType)1