Search in sources :

Example 1 with EvaluationContextImpl

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

the class JavaStackFrame method buildVariablesThreadAction.

// copied from DebuggerTree
private void buildVariablesThreadAction(DebuggerContextImpl debuggerContext, XValueChildrenList children, XCompositeNode node) {
    try {
        final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext();
        if (evaluationContext == null) {
            return;
        }
        if (!debuggerContext.isEvaluationPossible()) {
            node.setErrorMessage(MessageDescriptor.EVALUATION_NOT_POSSIBLE.getLabel());
        //myChildren.add(myNodeManager.createNode(MessageDescriptor.EVALUATION_NOT_POSSIBLE, evaluationContext));
        }
        final Location location = myDescriptor.getLocation();
        final ObjectReference thisObjectReference = myDescriptor.getThisObject();
        if (thisObjectReference != null) {
            ValueDescriptorImpl thisDescriptor = myNodeManager.getThisDescriptor(null, thisObjectReference);
            children.add(JavaValue.create(thisDescriptor, evaluationContext, myNodeManager));
        } else if (location != null) {
            StaticDescriptorImpl staticDecriptor = myNodeManager.getStaticDescriptor(myDescriptor, location.declaringType());
            if (staticDecriptor.isExpandable()) {
                children.addTopGroup(new JavaStaticGroup(staticDecriptor, evaluationContext, myNodeManager));
            }
        }
        DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess == null) {
            return;
        }
        // add last method return value if any
        final Pair<Method, Value> methodValuePair = debugProcess.getLastExecutedMethod();
        if (methodValuePair != null && myDescriptor.getUiIndex() == 0) {
            ValueDescriptorImpl returnValueDescriptor = myNodeManager.getMethodReturnValueDescriptor(myDescriptor, methodValuePair.getFirst(), methodValuePair.getSecond());
            children.add(JavaValue.create(returnValueDescriptor, evaluationContext, myNodeManager));
        }
        // add context exceptions
        Set<ObjectReference> exceptions = new HashSet<>();
        for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) {
            Event debugEvent = pair.getSecond();
            if (debugEvent instanceof ExceptionEvent) {
                ObjectReference exception = ((ExceptionEvent) debugEvent).exception();
                if (exception != null) {
                    exceptions.add(exception);
                }
            }
        }
        exceptions.forEach(e -> children.add(JavaValue.create(myNodeManager.getThrownExceptionObjectDescriptor(myDescriptor, e), evaluationContext, myNodeManager)));
        try {
            buildVariables(debuggerContext, evaluationContext, debugProcess, children, thisObjectReference, location);
        //if (classRenderer.SORT_ASCENDING) {
        //  Collections.sort(myChildren, NodeManagerImpl.getNodeComparator());
        //}
        } catch (EvaluateException e) {
            node.setErrorMessage(e.getMessage());
        //myChildren.add(myNodeManager.createMessageNode(new MessageDescriptor(e.getMessage())));
        }
    } catch (InvalidStackFrameException e) {
        LOG.info(e);
    //myChildren.clear();
    //notifyCancelled();
    } catch (InternalException e) {
        if (e.errorCode() == 35) {
            node.setErrorMessage(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage()));
        //myChildren.add(
        //  myNodeManager.createMessageNode(new MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage()))));
        } else {
            throw e;
        }
    }
}
Also used : ExceptionEvent(com.sun.jdi.event.ExceptionEvent) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) Event(com.sun.jdi.event.Event) ExceptionEvent(com.sun.jdi.event.ExceptionEvent)

Example 2 with EvaluationContextImpl

use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl 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)

Example 3 with EvaluationContextImpl

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

the class ValueDescriptorImpl method setValueLabel.

@Override
public void setValueLabel(@NotNull String label) {
    label = myFullValue ? label : DebuggerUtilsEx.truncateString(label);
    Value value = myValueReady ? getValue() : null;
    NodeRendererImpl lastRenderer = (NodeRendererImpl) getLastRenderer();
    EvaluationContextImpl evalContext = myStoredEvaluationContext;
    String labelId = myValueReady && evalContext != null && lastRenderer != null && !evalContext.getSuspendContext().isResumed() ? lastRenderer.getIdLabel(value, evalContext.getDebugProcess()) : null;
    myValueText = label;
    myIdLabel = isShowIdLabel() ? labelId : null;
}
Also used : EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl)

Example 4 with EvaluationContextImpl

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

the class EvaluationDescriptor method calcValue.

public final Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
    try {
        PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(() -> {
        });
        EvaluationContextImpl thisEvaluationContext = getEvaluationContext(evaluationContext);
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position);
        ExpressionEvaluator evaluator = ReadAction.compute(() -> {
            PsiCodeFragment code = getEvaluationCode(thisEvaluationContext);
            try {
                return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position);
            } catch (UnsupportedExpressionException ex) {
                ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code);
                if (eval != null) {
                    return eval;
                }
                throw ex;
            }
        });
        if (!thisEvaluationContext.getDebugProcess().isAttached()) {
            throw EvaluateExceptionUtil.PROCESS_EXITED;
        }
        StackFrameProxyImpl frameProxy = thisEvaluationContext.getFrameProxy();
        if (frameProxy == null) {
            throw EvaluateExceptionUtil.NULL_STACK_FRAME;
        }
        Value value = evaluator.evaluate(thisEvaluationContext);
        DebuggerUtilsEx.keep(value, thisEvaluationContext);
        myModifier = evaluator.getModifier();
        setLvalue(myModifier != null);
        return value;
    } catch (final EvaluateException ex) {
        throw new EvaluateException(ex.getLocalizedMessage(), ex);
    } catch (ObjectCollectedException ex) {
        throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
    }
}
Also used : StackFrameContext(com.intellij.debugger.engine.StackFrameContext) Modifier(com.intellij.debugger.engine.evaluation.expression.Modifier) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) ContextUtil(com.intellij.debugger.engine.ContextUtil) DebuggerUtilsEx(com.intellij.debugger.impl.DebuggerUtilsEx) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) ReadAction(com.intellij.openapi.application.ReadAction) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) XValueModifier(com.intellij.xdebugger.frame.XValueModifier) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) UnsupportedExpressionException(com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier) EvaluateExceptionUtil(com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil) JavaValue(com.intellij.debugger.engine.JavaValue) Nullable(org.jetbrains.annotations.Nullable) DebuggerContext(com.intellij.debugger.DebuggerContext) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) com.sun.jdi(com.sun.jdi) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SourcePosition(com.intellij.debugger.SourcePosition) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) SourcePosition(com.intellij.debugger.SourcePosition) JavaValue(com.intellij.debugger.engine.JavaValue) UnsupportedExpressionException(com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)

Example 5 with EvaluationContextImpl

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

the class EvaluationDescriptor method getModifier.

@Override
public XValueModifier getModifier(JavaValue value) {
    return new JavaValueModifier(value) {

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final EvaluationDescriptor evaluationDescriptor = EvaluationDescriptor.this;
            if (evaluationDescriptor.canSetValue()) {
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                set(expression, callback, debuggerContext, new SetValueRunnable() {

                    public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                        final Modifier modifier = evaluationDescriptor.getModifier();
                        modifier.setValue(preprocessValue(evaluationContext, newValue, modifier.getExpectedType()));
                        update(debuggerContext);
                    }

                    public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                        return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, evaluationContext.getClassLoader());
                    }
                });
            }
        }
    };
}
Also used : NotNull(org.jetbrains.annotations.NotNull) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) JavaValue(com.intellij.debugger.engine.JavaValue) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Modifier(com.intellij.debugger.engine.evaluation.expression.Modifier) XValueModifier(com.intellij.xdebugger.frame.XValueModifier) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier)

Aggregations

EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)14 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)12 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)7 JavaValue (com.intellij.debugger.engine.JavaValue)6 JavaValueModifier (com.intellij.debugger.engine.JavaValueModifier)6 NotNull (org.jetbrains.annotations.NotNull)6 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)3 SourcePosition (com.intellij.debugger.SourcePosition)2 TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)2 Modifier (com.intellij.debugger.engine.evaluation.expression.Modifier)2 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)2 LocalVariableProxyImpl (com.intellij.debugger.jdi.LocalVariableProxyImpl)2 XValueModifier (com.intellij.xdebugger.frame.XValueModifier)2 Nullable (org.jetbrains.annotations.Nullable)2 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 DebuggerContext (com.intellij.debugger.DebuggerContext)1 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1 ContextUtil (com.intellij.debugger.engine.ContextUtil)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 StackFrameContext (com.intellij.debugger.engine.StackFrameContext)1