Search in sources :

Example 1 with LocalVariable

use of com.sun.jdi.LocalVariable 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 2 with LocalVariable

use of com.sun.jdi.LocalVariable in project che by eclipse.

the class JdiStackFrameImpl method getLocalVariables.

@Override
public JdiLocalVariable[] getLocalVariables() throws DebuggerException {
    if (localVariables == null) {
        try {
            List<LocalVariable> targetVariables = stackFrame.visibleVariables();
            localVariables = new JdiLocalVariable[targetVariables.size()];
            int i = 0;
            for (LocalVariable var : targetVariables) {
                localVariables[i++] = new JdiLocalVariableImpl(stackFrame, var);
            }
        } catch (AbsentInformationException e) {
            throw new DebuggerAbsentInformationException(e.getMessage(), e);
        } catch (InvalidStackFrameException | NativeMethodException e) {
            throw new DebuggerException(e.getMessage(), e);
        }
    }
    return localVariables;
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) LocalVariable(com.sun.jdi.LocalVariable) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)

Example 3 with LocalVariable

use of com.sun.jdi.LocalVariable in project che by eclipse.

the class Evaluator method getLocalVariable.

public ExpressionValue getLocalVariable(String text) {
    ExpressionValue value = null;
    try {
        StackFrame frame = thread.frame(0);
        LocalVariable var = frame.visibleVariableByName(text);
        if (var != null) {
            value = new LocalValue(thread, var);
        }
    } catch (IncompatibleThreadStateException | AbsentInformationException | InvalidStackFrameException | NativeMethodException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
    LOG.debug("GET local variable {} {} ", text, value);
    return value;
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) AbsentInformationException(com.sun.jdi.AbsentInformationException) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException)

Example 4 with LocalVariable

use of com.sun.jdi.LocalVariable in project otertool by wuntee.

the class Testing method printBreakpointData.

public static void printBreakpointData(BreakpointEvent e) throws IncompatibleThreadStateException, AbsentInformationException {
    System.out.println(e.location());
    System.out.println("Line number: " + e.location().lineNumber());
    System.out.println("Code index: " + e.location().codeIndex());
    try {
        System.out.println("SourceName: " + e.location().sourceName());
    } catch (AbsentInformationException e1) {
        System.out.println("SourceName: UNAVAILABLE");
    }
    System.out.println("Declaration type: " + e.location().declaringType());
    System.out.println("Method: " + e.location().method());
    System.out.println("Stack frames:");
    for (StackFrame sf : e.thread().frames()) {
        System.out.println("\t" + sf.toString());
        System.out.println("\t   Visible Variables:");
        for (LocalVariable lv : sf.visibleVariables()) {
            System.out.println("\t\t--");
            System.out.println("\t\tName: " + lv.name());
            System.out.println("\t\tType: " + lv.typeName());
            Value lvValue = sf.getValue(lv);
            if (lvValue != null) {
                System.out.println("\t\tValue: " + lvValue);
                System.out.println("\t\tValue Type:" + lvValue.type());
                System.out.println("\t\ttoString: " + lv);
            }
        }
        System.out.println("\t   Argument Values:");
        for (Value lv : sf.getArgumentValues()) {
            System.out.println("\t\t--");
            System.out.println("\t\t" + lv.toString());
        }
    }
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) Value(com.sun.jdi.Value)

Aggregations

LocalVariable (com.sun.jdi.LocalVariable)4 AbsentInformationException (com.sun.jdi.AbsentInformationException)3 StackFrame (com.sun.jdi.StackFrame)3 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)2 NativeMethodException (com.sun.jdi.NativeMethodException)2 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)1 StringReference (com.sun.jdi.StringReference)1 ThreadReference (com.sun.jdi.ThreadReference)1 Value (com.sun.jdi.Value)1 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)1 StepEvent (com.sun.jdi.event.StepEvent)1 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)1 DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)1