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;
}
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);
}
}
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);
}
}
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;
}
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());
}
Aggregations