Search in sources :

Example 6 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.

the class JavaValue method calculateEvaluationExpression.

@NotNull
@Override
public Promise<XExpression> calculateEvaluationExpression() {
    if (evaluationExpression != null) {
        return Promise.resolve(evaluationExpression);
    } else {
        final AsyncPromise<XExpression> res = new AsyncPromise<>();
        myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {

            @Override
            public Priority getPriority() {
                return Priority.HIGH;
            }

            @Override
            public void contextAction() throws Exception {
                evaluationExpression = ApplicationManager.getApplication().runReadAction(new Computable<XExpression>() {

                    @Override
                    public XExpression compute() {
                        try {
                            PsiElement psiExpression = getDescriptor().getTreeEvaluation(JavaValue.this, getDebuggerContext());
                            if (psiExpression != null) {
                                XExpression res = TextWithImportsImpl.toXExpression(new TextWithImportsImpl(psiExpression));
                                // add runtime imports if any
                                Set<String> imports = psiExpression.getUserData(DebuggerTreeNodeExpression.ADDITIONAL_IMPORTS_KEY);
                                if (imports != null && res != null) {
                                    if (res.getCustomInfo() != null) {
                                        imports.add(res.getCustomInfo());
                                    }
                                    res = new XExpressionImpl(res.getExpression(), res.getLanguage(), StringUtil.join(imports, ","), res.getMode());
                                }
                                return res;
                            }
                        } catch (EvaluateException e) {
                            LOG.info(e);
                        }
                        return null;
                    }
                });
                res.setResult(evaluationExpression);
            }
        });
        return res;
    }
}
Also used : Set(java.util.Set) XExpressionImpl(com.intellij.xdebugger.impl.breakpoints.XExpressionImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) XExpression(com.intellij.xdebugger.XExpression) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.

the class LambdaAsyncMethodFilter method onReached.

@Override
public int onReached(SuspendContextImpl context, RequestHint hint) {
    try {
        StackFrameProxyImpl proxy = context.getFrameProxy();
        if (proxy != null) {
            Value lambdaReference = ContainerUtil.getOrElse(proxy.getArgumentValues(), myParamNo, null);
            if (lambdaReference instanceof ObjectReference) {
                final SourcePosition pos = myMethodFilter.getBreakpointPosition();
                if (pos != null) {
                    Project project = context.getDebugProcess().getProject();
                    long lambdaId = ((ObjectReference) lambdaReference).uniqueID();
                    StepIntoBreakpoint breakpoint = new LambdaInstanceBreakpoint(project, lambdaId, pos, myMethodFilter);
                    ClassInstanceMethodFilter.setUpStepIntoBreakpoint(context, breakpoint, hint);
                    return RequestHint.RESUME;
                }
            }
        }
    } catch (EvaluateException ignore) {
    }
    return RequestHint.STOP;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) Project(com.intellij.openapi.project.Project) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ObjectReference(com.sun.jdi.ObjectReference) SourcePosition(com.intellij.debugger.SourcePosition) Value(com.sun.jdi.Value) StepIntoBreakpoint(com.intellij.debugger.ui.breakpoints.StepIntoBreakpoint)

Example 8 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.

the class RequestHint method getNextStepDepth.

public int getNextStepDepth(final SuspendContextImpl context) {
    try {
        final StackFrameProxyImpl frameProxy = context.getFrameProxy();
        // smart step feature stop check
        if (myMethodFilter != null && frameProxy != null && !(myMethodFilter instanceof BreakpointStepMethodFilter) && myMethodFilter.locationMatches(context.getDebugProcess(), frameProxy.location()) && !isTheSameFrame(context)) {
            myTargetMethodMatched = true;
            return myMethodFilter.onReached(context, this);
        }
        if ((myDepth == StepRequest.STEP_OVER || myDepth == StepRequest.STEP_INTO) && myPosition != null) {
            SourcePosition locationPosition = ContextUtil.getSourcePosition(context);
            if (locationPosition != null) {
                Integer resultDepth = ApplicationManager.getApplication().runReadAction(new Computable<Integer>() {

                    public Integer compute() {
                        if (myPosition.getFile().equals(locationPosition.getFile()) && isTheSameFrame(context) && !mySteppedOut) {
                            return isOnTheSameLine(locationPosition) ? myDepth : STOP;
                        }
                        return null;
                    }
                });
                if (resultDepth != null) {
                    return resultDepth.intValue();
                }
            }
        }
        // Now check filters
        final DebuggerSettings settings = DebuggerSettings.getInstance();
        if ((myMethodFilter != null || (settings.SKIP_SYNTHETIC_METHODS && !myIgnoreFilters)) && frameProxy != null) {
            final Location location = frameProxy.location();
            if (location != null) {
                if (DebuggerUtils.isSynthetic(location.method())) {
                    return myDepth;
                }
            }
        }
        if (!myIgnoreFilters) {
            if (settings.SKIP_GETTERS) {
                boolean isGetter = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                    public Boolean compute() {
                        PsiElement contextElement = ContextUtil.getContextElement(context);
                        return contextElement != null && DebuggerUtils.isInsideSimpleGetter(contextElement);
                    }
                }).booleanValue();
                if (isGetter) {
                    return StepRequest.STEP_OUT;
                }
            }
            if (frameProxy != null) {
                if (settings.SKIP_CONSTRUCTORS) {
                    final Location location = frameProxy.location();
                    if (location != null) {
                        final Method method = location.method();
                        if (method != null && method.isConstructor()) {
                            return StepRequest.STEP_OUT;
                        }
                    }
                }
                if (settings.SKIP_CLASSLOADERS) {
                    final Location location = frameProxy.location();
                    if (location != null && DebuggerUtilsEx.isAssignableFrom("java.lang.ClassLoader", location.declaringType())) {
                        return StepRequest.STEP_OUT;
                    }
                }
            }
            for (ExtraSteppingFilter filter : ExtraSteppingFilter.EP_NAME.getExtensions()) {
                try {
                    if (filter.isApplicable(context))
                        return filter.getStepRequestDepth(context);
                } catch (Exception | AssertionError e) {
                    LOG.error(e);
                }
            }
        }
        // smart step feature
        if (myMethodFilter != null && !mySteppedOut) {
            return StepRequest.STEP_OUT;
        }
    } catch (VMDisconnectedException ignored) {
    } catch (EvaluateException e) {
        LOG.error(e);
    }
    return STOP;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) DebuggerSettings(com.intellij.debugger.settings.DebuggerSettings) Method(com.sun.jdi.Method) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) SourcePosition(com.intellij.debugger.SourcePosition) Computable(com.intellij.openapi.util.Computable) PsiElement(com.intellij.psi.PsiElement) Location(com.sun.jdi.Location)

Example 9 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.

the class ClassLoadingUtils method defineClass.

public static void defineClass(String name, byte[] bytes, EvaluationContext context, DebugProcess process, ClassLoaderReference classLoader) throws EvaluateException {
    try {
        VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl) process.getVirtualMachineProxy();
        Method defineMethod = ((ClassType) classLoader.referenceType()).concreteMethodByName("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;");
        StringReference nameObj = proxy.mirrorOf(name);
        DebuggerUtilsEx.keep(nameObj, context);
        process.invokeMethod(context, classLoader, defineMethod, Arrays.asList(nameObj, mirrorOf(bytes, context, process), proxy.mirrorOf(0), proxy.mirrorOf(bytes.length)));
    } catch (Exception e) {
        throw new EvaluateException("Error during class " + name + " definition: " + e, e);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) IOException(java.io.IOException)

Example 10 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.

the class DebuggerContextImpl method createEvaluationContext.

@Nullable
public EvaluationContextImpl createEvaluationContext() {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    StackFrameProxyImpl frameProxy = getFrameProxy();
    ObjectReference objectReference;
    try {
        objectReference = frameProxy != null ? frameProxy.thisObject() : null;
    } catch (EvaluateException e) {
        LOG.info(e);
        objectReference = null;
    }
    SuspendContextImpl context = getSuspendContext();
    return context != null ? new EvaluationContextImpl(context, frameProxy, objectReference) : null;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) ObjectReference(com.sun.jdi.ObjectReference) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)62 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)13 NotNull (org.jetbrains.annotations.NotNull)12 Nullable (org.jetbrains.annotations.Nullable)12 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)11 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)10 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)10 SourcePosition (com.intellij.debugger.SourcePosition)8 JavaValue (com.intellij.debugger.engine.JavaValue)8 JavaValueModifier (com.intellij.debugger.engine.JavaValueModifier)6 Value (com.sun.jdi.Value)6 Project (com.intellij.openapi.project.Project)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 Method (com.sun.jdi.Method)5 ObjectReference (com.sun.jdi.ObjectReference)5 TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)4 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)4 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)4 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)3 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)3