Search in sources :

Example 16 with VirtualMachineProxyImpl

use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.

the class DebugProcessEvents method vmAttached.

private void vmAttached() {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    LOG.assertTrue(!isAttached());
    if (myState.compareAndSet(State.INITIAL, State.ATTACHED)) {
        final VirtualMachineProxyImpl machineProxy = getVirtualMachineProxy();
        final EventRequestManager requestManager = machineProxy.eventRequestManager();
        if (machineProxy.canGetMethodReturnValues()) {
            myReturnValueWatcher = new MethodReturnValueWatcher(requestManager);
        }
        final ThreadStartRequest threadStartRequest = requestManager.createThreadStartRequest();
        threadStartRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
        threadStartRequest.enable();
        final ThreadDeathRequest threadDeathRequest = requestManager.createThreadDeathRequest();
        threadDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
        threadDeathRequest.enable();
        // fill position managers
        ((DebuggerManagerImpl) DebuggerManager.getInstance(getProject())).getCustomPositionManagerFactories().map(factory -> factory.fun(this)).filter(Objects::nonNull).forEach(this::appendPositionManager);
        Stream.of(Extensions.getExtensions(PositionManagerFactory.EP_NAME, getProject())).map(factory -> factory.createPositionManager(this)).filter(Objects::nonNull).forEach(this::appendPositionManager);
        myDebugProcessDispatcher.getMulticaster().processAttached(this);
        createStackCapturingBreakpoints();
        // breakpoints should be initialized after all processAttached listeners work
        ApplicationManager.getApplication().runReadAction(() -> {
            XDebugSession session = getSession().getXDebugSession();
            if (session != null) {
                session.initBreakpoints();
            }
        });
        final String addressDisplayName = DebuggerBundle.getAddressDisplayName(getConnection());
        final String transportName = DebuggerBundle.getTransportName(getConnection());
        showStatusText(DebuggerBundle.message("status.connected", addressDisplayName, transportName));
        LOG.debug("leave: processVMStartEvent()");
    }
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ThreadStartRequest(com.sun.jdi.request.ThreadStartRequest) ThreadDeathRequest(com.sun.jdi.request.ThreadDeathRequest) EventRequestManager(com.sun.jdi.request.EventRequestManager) MethodReturnValueWatcher(com.intellij.debugger.engine.requests.MethodReturnValueWatcher)

Example 17 with VirtualMachineProxyImpl

use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.

the class UnaryExpressionEvaluator method evaluate.

public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    Value operand = (Value) myOperandEvaluator.evaluate(context);
    VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
    if (myOperationType == JavaTokenType.PLUS) {
        if (DebuggerUtils.isNumeric(operand)) {
            return operand;
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
    } else if (myOperationType == JavaTokenType.MINUS) {
        if (DebuggerUtils.isInteger(operand)) {
            long v = ((PrimitiveValue) operand).longValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
        }
        if (DebuggerUtils.isNumeric(operand)) {
            double v = ((PrimitiveValue) operand).doubleValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
    } else if (myOperationType == JavaTokenType.TILDE) {
        if (DebuggerUtils.isInteger(operand)) {
            long v = ((PrimitiveValue) operand).longValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, ~v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.integer.expected"));
    } else if (myOperationType == JavaTokenType.EXCL) {
        if (operand instanceof BooleanValue) {
            boolean v = ((BooleanValue) operand).booleanValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, !v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected"));
    }
    throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.operation.not.supported", myOperationText));
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 18 with VirtualMachineProxyImpl

use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.

the class CompilingEvaluator method evaluate.

@Override
public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();
    EvaluationContextImpl autoLoadContext = ((EvaluationContextImpl) evaluationContext).createEvaluationContext(evaluationContext.getThisObject());
    autoLoadContext.setAutoLoadClasses(true);
    ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process);
    autoLoadContext.setClassLoader(classLoader);
    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version));
    defineClasses(classes, autoLoadContext, process, classLoader);
    try {
        // invoke base evaluator on call code
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, new EvaluatingComputable<ExpressionEvaluator>() {

            @Override
            public ExpressionEvaluator compute() throws EvaluateException {
                TextWithImports callCode = getCallCode();
                PsiElement copyContext = myData.getAnchor();
                CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position);
            }
        });
        return evaluator.evaluate(autoLoadContext);
    } catch (Exception e) {
        throw new EvaluateException("Error during generated code invocation " + e, e);
    }
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ClassObject(com.intellij.openapi.compiler.ClassObject) ClassLoaderReference(com.sun.jdi.ClassLoaderReference) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) DebugProcess(com.intellij.debugger.engine.DebugProcess) SourcePosition(com.intellij.debugger.SourcePosition) PsiElement(com.intellij.psi.PsiElement)

Example 19 with VirtualMachineProxyImpl

use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.

the class BinaryExpressionEvaluator method evaluateOperation.

static Object evaluateOperation(final Value leftResult, final IElementType opType, final Evaluator rightOperand, final String expectedType, final EvaluationContextImpl context) throws EvaluateException {
    VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
    if (leftResult instanceof BooleanValue) {
        boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
        if (opType == JavaTokenType.OROR && v1) {
            return DebuggerUtilsEx.createValue(vm, expectedType, true);
        }
        if (opType == JavaTokenType.ANDAND && !v1) {
            return DebuggerUtilsEx.createValue(vm, expectedType, false);
        }
    }
    Value rightResult = (Value) rightOperand.evaluate(context);
    if (opType == JavaTokenType.PLUS) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 + v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            final double v1 = ((PrimitiveValue) leftResult).doubleValue();
            final double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 + v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 + v2);
        }
        if (leftResult instanceof StringReference || rightResult instanceof StringReference) {
            String v1 = DebuggerUtils.getValueAsString(context, leftResult);
            String v2 = DebuggerUtils.getValueAsString(context, rightResult);
            return vm.mirrorOf(v1 + v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "+"));
    } else if (opType == JavaTokenType.MINUS) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 - v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 - v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 - v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "-"));
    } else if (opType == JavaTokenType.ASTERISK) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 * v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 * v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 * v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "*"));
    } else if (opType == JavaTokenType.DIV) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            long v1 = ((PrimitiveValue) leftResult).longValue();
            long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 / v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 / v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 / v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "/"));
    } else if (opType == JavaTokenType.PERC) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            long v1 = ((PrimitiveValue) leftResult).longValue();
            long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 % v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 % v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 % v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "%"));
    } else if (opType == JavaTokenType.LTLT) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            if (leftResult instanceof ByteValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ByteValue) leftResult).byteValue() << v2);
            } else if (leftResult instanceof ShortValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ShortValue) leftResult).shortValue() << v2);
            } else if (leftResult instanceof IntegerValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((IntegerValue) leftResult).intValue() << v2);
            }
            return DebuggerUtilsEx.createValue(vm, expectedType, ((PrimitiveValue) leftResult).longValue() << v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            return DebuggerUtilsEx.createValue(vm, expectedType, ((CharValue) leftResult).charValue() << ((CharValue) rightResult).charValue());
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "<<"));
    } else if (opType == JavaTokenType.GTGT) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            if (leftResult instanceof ByteValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ByteValue) leftResult).byteValue() >> v2);
            } else if (leftResult instanceof ShortValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ShortValue) leftResult).shortValue() >> v2);
            } else if (leftResult instanceof IntegerValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((IntegerValue) leftResult).intValue() >> v2);
            }
            return DebuggerUtilsEx.createValue(vm, expectedType, ((PrimitiveValue) leftResult).longValue() >> v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            return DebuggerUtilsEx.createValue(vm, expectedType, ((CharValue) leftResult).charValue() >> ((CharValue) rightResult).charValue());
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", ">>"));
    } else if (opType == JavaTokenType.GTGTGT) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            if (leftResult instanceof ByteValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ByteValue) leftResult).byteValue() >>> v2);
            } else if (leftResult instanceof ShortValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((ShortValue) leftResult).shortValue() >>> v2);
            } else if (leftResult instanceof IntegerValue) {
                return DebuggerUtilsEx.createValue(vm, expectedType, ((IntegerValue) leftResult).intValue() >>> v2);
            }
            return DebuggerUtilsEx.createValue(vm, expectedType, ((PrimitiveValue) leftResult).longValue() >>> v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            return DebuggerUtilsEx.createValue(vm, expectedType, ((CharValue) leftResult).charValue() >>> ((CharValue) rightResult).charValue());
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", ">>>"));
    } else if (opType == JavaTokenType.AND) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            long v1 = ((PrimitiveValue) leftResult).longValue();
            long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 & v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 & v2);
        }
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 & v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "&"));
    } else if (opType == JavaTokenType.OR) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            long v1 = ((PrimitiveValue) leftResult).longValue();
            long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 | v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 | v2);
        }
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 | v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "|"));
    } else if (opType == JavaTokenType.XOR) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            long v1 = ((PrimitiveValue) leftResult).longValue();
            long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 ^ v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 ^ v2);
        }
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 ^ v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "^"));
    } else if (opType == JavaTokenType.EQEQ) {
        if (leftResult == null && rightResult == null) {
            return DebuggerUtilsEx.createValue(vm, expectedType, true);
        }
        if (leftResult == null) {
            return DebuggerUtilsEx.createValue(vm, expectedType, rightResult.equals(null));
        }
        if (rightResult == null) {
            return DebuggerUtilsEx.createValue(vm, expectedType, leftResult.equals(null));
        }
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 == v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 == v2);
        }
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 == v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 == v2);
        }
        if (leftResult instanceof ObjectReference && rightResult instanceof ObjectReference) {
            ObjectReference v1 = (ObjectReference) leftResult;
            ObjectReference v2 = (ObjectReference) rightResult;
            return DebuggerUtilsEx.createValue(vm, expectedType, v1.uniqueID() == v2.uniqueID());
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "=="));
    } else if (opType == JavaTokenType.OROR) {
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 || v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "||"));
    } else if (opType == JavaTokenType.ANDAND) {
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 && v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "&&"));
    } else if (opType == JavaTokenType.NE) {
        if (leftResult == null && rightResult == null)
            return DebuggerUtilsEx.createValue(vm, expectedType, false);
        if (leftResult == null)
            return DebuggerUtilsEx.createValue(vm, expectedType, !rightResult.equals(null));
        if (rightResult == null)
            return DebuggerUtilsEx.createValue(vm, expectedType, !leftResult.equals(null));
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 != v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 != v2);
        }
        if (leftResult instanceof BooleanValue && rightResult instanceof BooleanValue) {
            boolean v1 = ((PrimitiveValue) leftResult).booleanValue();
            boolean v2 = ((PrimitiveValue) rightResult).booleanValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 != v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 != v2);
        }
        if (leftResult instanceof ObjectReference && rightResult instanceof ObjectReference) {
            ObjectReference v1 = (ObjectReference) leftResult;
            ObjectReference v2 = (ObjectReference) rightResult;
            return DebuggerUtilsEx.createValue(vm, expectedType, v1.uniqueID() != v2.uniqueID());
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "!="));
    } else if (opType == JavaTokenType.LT) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 < v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 < v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 < v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "<"));
    } else if (opType == JavaTokenType.GT) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 > v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 > v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 > v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", ">"));
    } else if (opType == JavaTokenType.LE) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 <= v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 <= v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 <= v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", "<="));
    } else if (opType == JavaTokenType.GE) {
        if (DebuggerUtils.isInteger(leftResult) && DebuggerUtils.isInteger(rightResult)) {
            final long v1 = ((PrimitiveValue) leftResult).longValue();
            final long v2 = ((PrimitiveValue) rightResult).longValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 >= v2);
        }
        if (DebuggerUtils.isNumeric(leftResult) && DebuggerUtils.isNumeric(rightResult)) {
            double v1 = ((PrimitiveValue) leftResult).doubleValue();
            double v2 = ((PrimitiveValue) rightResult).doubleValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 >= v2);
        }
        if (leftResult instanceof CharValue && rightResult instanceof CharValue) {
            char v1 = ((CharValue) leftResult).charValue();
            char v2 = ((CharValue) rightResult).charValue();
            return DebuggerUtilsEx.createValue(vm, expectedType, v1 >= v2);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", ">="));
    }
    LOG.assertTrue(false);
    return null;
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl)

Example 20 with VirtualMachineProxyImpl

use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.

the class ThreadDumpAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
    final DebuggerSession session = context.getDebuggerSession();
    if (session != null && session.isAttached()) {
        final DebugProcessImpl process = context.getDebugProcess();
        process.getManagerThread().invoke(new DebuggerCommandImpl() {

            protected void action() throws Exception {
                final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy();
                vm.suspend();
                try {
                    final List<ThreadState> threads = buildThreadStates(vm);
                    ApplicationManager.getApplication().invokeLater(() -> {
                        XDebugSession xSession = session.getXDebugSession();
                        if (xSession != null) {
                            DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session);
                        }
                    }, ModalityState.NON_MODAL);
                } finally {
                    vm.resume();
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ArrayList(java.util.ArrayList) List(java.util.List) SmartList(com.intellij.util.SmartList) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Aggregations

VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)21 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)5 DebugProcess (com.intellij.debugger.engine.DebugProcess)4 XDebugSession (com.intellij.xdebugger.XDebugSession)3 Nullable (org.jetbrains.annotations.Nullable)3 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)2 Project (com.intellij.openapi.project.Project)2 Method (com.sun.jdi.Method)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SourcePosition (com.intellij.debugger.SourcePosition)1 JavaExecutionStack (com.intellij.debugger.engine.JavaExecutionStack)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 MethodReturnValueWatcher (com.intellij.debugger.engine.requests.MethodReturnValueWatcher)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 BreakpointManager (com.intellij.debugger.ui.breakpoints.BreakpointManager)1