Search in sources :

Example 1 with ObjectReference

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

the class JdiStackFrameImpl method getFields.

@Override
public JdiField[] getFields() throws DebuggerException {
    if (fields == null) {
        try {
            ObjectReference object = stackFrame.thisObject();
            if (object == null) {
                ReferenceType type = stackFrame.location().declaringType();
                List<Field> fs = stackFrame.location().declaringType().allFields();
                fields = new JdiField[fs.size()];
                int i = 0;
                for (Field f : fs) {
                    fields[i++] = new JdiFieldImpl(f, type);
                }
            } else {
                List<Field> fs = object.referenceType().allFields();
                fields = new JdiField[fs.size()];
                int i = 0;
                for (Field f : fs) {
                    fields[i++] = new JdiFieldImpl(f, object);
                }
            }
            Arrays.sort(fields);
        } catch (InvalidStackFrameException e) {
            throw new DebuggerException(e.getMessage(), e);
        }
    }
    return fields;
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) ReferenceType(com.sun.jdi.ReferenceType)

Example 2 with ObjectReference

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

the class Evaluator method invokeMethod.

public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
    if (!(value instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ObjectReference object = (ObjectReference) value;
    ReferenceType type = object.referenceType();
    List<Method> methods = type.methodsByName(name);
    Method method = findMethod(methods, arguments);
    if (method == null) {
        throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
    }
    try {
        return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
    } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
}
Also used : ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) ObjectReference(com.sun.jdi.ObjectReference) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) InvocationException(com.sun.jdi.InvocationException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) InvalidTypeException(com.sun.jdi.InvalidTypeException)

Example 3 with ObjectReference

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

the class Evaluator method operation.

public ExpressionValue operation(ExpressionValue leftExpression, ExpressionValue rightExpression, int op) {
    if (JavaParser.ASSIGN == op) {
        leftExpression.setValue(rightExpression.getValue());
        return leftExpression;
    }
    Value leftValue = leftExpression.getValue();
    Value rightValue = rightExpression.getValue();
    if (leftValue instanceof StringReference || rightValue instanceof StringReference) {
        if (JavaParser.PLUS == op) {
            return value(valueToString(leftValue) + valueToString(rightValue));
        }
    }
    if (leftValue instanceof ObjectReference || rightValue instanceof ObjectReference) {
        switch(op) {
            case JavaParser.EQUAL:
                return value(leftValue != null ? leftValue.equals(rightValue) : rightValue == null);
            case JavaParser.NOT_EQUAL:
                return value(!(leftValue != null ? leftValue.equals(rightValue) : rightValue == null));
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (leftValue == null || rightValue == null) {
        // Neither one is object and operation is not assignation.
        throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
    PrimitiveValue lp = (PrimitiveValue) leftValue;
    PrimitiveValue rp = (PrimitiveValue) rightValue;
    if (lp instanceof BooleanValue && rp instanceof BooleanValue) {
        switch(op) {
            case JavaParser.LOGICAL_AND:
                return value(lp.booleanValue() && rp.booleanValue());
            case JavaParser.LOGICAL_OR:
                return value(lp.booleanValue() || rp.booleanValue());
            case JavaParser.EQUAL:
                return value(lp.booleanValue() == rp.booleanValue());
            case JavaParser.NOT_EQUAL:
                return value(lp.booleanValue() != rp.booleanValue());
            case JavaParser.OR:
                return value(lp.booleanValue() | rp.booleanValue());
            case JavaParser.XOR:
                return value(lp.booleanValue() ^ rp.booleanValue());
            case JavaParser.AND:
                return value(lp.booleanValue() & rp.booleanValue());
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() | rp.booleanValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() ^ rp.booleanValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() & rp.booleanValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.EQUAL:
            return value(lp.doubleValue() == rp.doubleValue());
        case JavaParser.NOT_EQUAL:
            return value(lp.doubleValue() != rp.doubleValue());
        case JavaParser.GREATER_THAN:
            return value(lp.doubleValue() > rp.doubleValue());
        case JavaParser.LESS_THAN:
            return value(lp.doubleValue() < rp.doubleValue());
        case JavaParser.GREATER_OR_EQUAL:
            return value(lp.doubleValue() >= rp.doubleValue());
        case JavaParser.LESS_OR_EQUAL:
            return value(lp.doubleValue() <= rp.doubleValue());
    }
    if (lp instanceof DoubleValue || rp instanceof DoubleValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.doubleValue() + rp.doubleValue());
            case JavaParser.MINUS:
                return value(lp.doubleValue() - rp.doubleValue());
            case JavaParser.STAR:
                return value(lp.doubleValue() * rp.doubleValue());
            case JavaParser.DIV:
                return value(lp.doubleValue() / rp.doubleValue());
            case JavaParser.MOD:
                return value(lp.doubleValue() % rp.doubleValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() + rp.doubleValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() - rp.doubleValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() * rp.doubleValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() / rp.doubleValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() % rp.doubleValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof FloatValue || rp instanceof FloatValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.floatValue() + rp.floatValue());
            case JavaParser.MINUS:
                return value(lp.floatValue() - rp.floatValue());
            case JavaParser.STAR:
                return value(lp.floatValue() * rp.floatValue());
            case JavaParser.DIV:
                return value(lp.floatValue() / rp.floatValue());
            case JavaParser.MOD:
                return value(lp.floatValue() % rp.floatValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() + rp.floatValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() - rp.floatValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() / rp.floatValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() % rp.floatValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof LongValue || rp instanceof LongValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.longValue() + rp.longValue());
            case JavaParser.MINUS:
                return value(lp.longValue() - rp.longValue());
            case JavaParser.STAR:
                return value(lp.longValue() * rp.longValue());
            case JavaParser.DIV:
                return value(lp.longValue() / rp.longValue());
            case JavaParser.MOD:
                return value(lp.longValue() % rp.longValue());
            case JavaParser.SHIFT_LEFT:
                return value(lp.longValue() << rp.longValue());
            case JavaParser.SHIFT_RIGHT:
                return value(lp.longValue() >> rp.longValue());
            case JavaParser.BIT_SHIFT_RIGHT:
                return value(lp.longValue() >>> rp.longValue());
            case JavaParser.OR:
                return value(lp.longValue() | rp.longValue());
            case JavaParser.XOR:
                return value(lp.longValue() ^ rp.longValue());
            case JavaParser.AND:
                return value(lp.longValue() & rp.longValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() + rp.longValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() - rp.longValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() / rp.longValue()));
                return leftExpression;
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() | rp.longValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() ^ rp.longValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() & rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_LEFT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() << rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >> rp.longValue()));
                return leftExpression;
            case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >>> rp.longValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.PLUS:
            return value(lp.intValue() + rp.intValue());
        case JavaParser.MINUS:
            return value(lp.intValue() - rp.intValue());
        case JavaParser.STAR:
            return value(lp.intValue() * rp.intValue());
        case JavaParser.DIV:
            return value(lp.intValue() / rp.intValue());
        case JavaParser.MOD:
            return value(lp.intValue() % rp.intValue());
        case JavaParser.SHIFT_LEFT:
            return value(lp.intValue() << rp.intValue());
        case JavaParser.SHIFT_RIGHT:
            return value(lp.intValue() >> rp.intValue());
        case JavaParser.BIT_SHIFT_RIGHT:
            return value(lp.intValue() >>> rp.intValue());
        case JavaParser.OR:
            return value(lp.intValue() | rp.intValue());
        case JavaParser.XOR:
            return value(lp.intValue() ^ rp.intValue());
        case JavaParser.AND:
            return value(lp.intValue() & rp.intValue());
        case JavaParser.PLUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() + rp.intValue()));
            return leftExpression;
        case JavaParser.MINUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() - rp.intValue()));
            return leftExpression;
        case JavaParser.STAR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() * rp.intValue()));
            return leftExpression;
        case JavaParser.DIV_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() / rp.intValue()));
            return leftExpression;
        case JavaParser.OR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() | rp.intValue()));
            return leftExpression;
        case JavaParser.XOR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() ^ rp.intValue()));
            return leftExpression;
        case JavaParser.AND_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() & rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_LEFT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() << rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >> rp.intValue()));
            return leftExpression;
        case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >>> rp.intValue()));
            return leftExpression;
        default:
            throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) IntegerValue(com.sun.jdi.IntegerValue) LongValue(com.sun.jdi.LongValue) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) FloatValue(com.sun.jdi.FloatValue) Value(com.sun.jdi.Value) LongValue(com.sun.jdi.LongValue) FloatValue(com.sun.jdi.FloatValue) StringReference(com.sun.jdi.StringReference) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 4 with ObjectReference

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

the class Evaluator method getField.

public ExpressionValue getField(Value parent, String name) {
    if (!(parent instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ExpressionValue value = null;
    try {
        ObjectReference object = (ObjectReference) parent;
        Field field = object.referenceType().fieldByName(name);
        if (field != null) {
            value = new InstanceValue(object, field);
        }
    } catch (ClassNotPreparedException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
    LOG.debug("GET field {} {} ", name, value);
    return value;
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException)

Example 5 with ObjectReference

use of com.sun.jdi.ObjectReference 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)

Aggregations

ObjectReference (com.sun.jdi.ObjectReference)23 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)5 Project (com.intellij.openapi.project.Project)5 ReferenceType (com.sun.jdi.ReferenceType)5 Value (com.sun.jdi.Value)5 Field (com.sun.jdi.Field)4 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)3 XDebugSession (com.intellij.xdebugger.XDebugSession)3 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)3 BooleanValue (com.sun.jdi.BooleanValue)3 Nullable (org.jetbrains.annotations.Nullable)3 SourcePosition (com.intellij.debugger.SourcePosition)2 MemoryViewDebugProcessData (com.intellij.debugger.memory.component.MemoryViewDebugProcessData)2 StepIntoBreakpoint (com.intellij.debugger.ui.breakpoints.StepIntoBreakpoint)2 IntegerValue (com.sun.jdi.IntegerValue)2 InvocationException (com.sun.jdi.InvocationException)2 Method (com.sun.jdi.Method)2 StringReference (com.sun.jdi.StringReference)2 ThreadReference (com.sun.jdi.ThreadReference)2 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1