Search in sources :

Example 6 with EvaluationContextImpl

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

the class FieldDescriptorImpl method getModifier.

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

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
            FieldDescriptorImpl fieldDescriptor = FieldDescriptorImpl.this;
            final Field field = fieldDescriptor.getField();
            if (!field.isStatic()) {
                final ObjectReference object = fieldDescriptor.getObject();
                if (object != null) {
                    set(expression, callback, debuggerContext, new SetValueRunnable() {

                        public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                            object.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
                            update(debuggerContext);
                        }

                        public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                            return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().classLoader());
                        }
                    });
                }
            } else {
                // field is static
                ReferenceType refType = field.declaringType();
                if (refType instanceof ClassType) {
                    final ClassType classType = (ClassType) refType;
                    set(expression, callback, debuggerContext, new SetValueRunnable() {

                        public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                            classType.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
                            update(debuggerContext);
                        }

                        public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                            return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().classLoader());
                        }
                    });
                }
            }
        }
    };
}
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)

Example 7 with EvaluationContextImpl

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

the class ArrayElementDescriptorImpl method getModifier.

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

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final ArrayElementDescriptorImpl elementDescriptor = ArrayElementDescriptorImpl.this;
            final ArrayReference array = elementDescriptor.getArray();
            if (array != null) {
                if (VirtualMachineProxyImpl.isCollected(array)) {
                    // will only be the case if debugger does not use ObjectReference.disableCollection() because of Patches.IBM_JDK_DISABLE_COLLECTION_BUG
                    Messages.showWarningDialog(getProject(), DebuggerBundle.message("evaluation.error.array.collected") + "\n" + DebuggerBundle.message("warning.recalculate"), DebuggerBundle.message("title.set.value"));
                    //node.getParent().calcValue();
                    return;
                }
                final ArrayType arrType = (ArrayType) array.referenceType();
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                set(expression, callback, debuggerContext, new SetValueRunnable() {

                    public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                        array.setValue(elementDescriptor.getIndex(), preprocessValue(evaluationContext, newValue, arrType.componentType()));
                        update(debuggerContext);
                    }

                    public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                        return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, arrType.classLoader());
                    }
                });
            }
        }
    };
}
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)

Example 8 with EvaluationContextImpl

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

the class JavaStackFrame method buildVariables.

// copied from FrameVariablesTree
private void buildVariables(DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @NotNull DebugProcessImpl debugProcess, XValueChildrenList children, ObjectReference thisObjectReference, Location location) throws EvaluateException {
    final Set<String> visibleLocals = new HashSet<>();
    if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
        if (thisObjectReference != null && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
            final ReferenceType thisRefType = thisObjectReference.referenceType();
            if (thisRefType instanceof ClassType && location != null && thisRefType.equals(location.declaringType()) && thisRefType.name().contains("$")) {
                // makes sense for nested classes only
                for (Field field : thisRefType.fields()) {
                    if (DebuggerUtils.isSynthetic(field) && StringUtil.startsWith(field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
                        final FieldDescriptorImpl fieldDescriptor = myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
                        children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
                        visibleLocals.add(fieldDescriptor.calcValueName());
                    }
                }
            }
        }
    }
    boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
    if (evaluationContext == null) {
        return;
    }
    try {
        if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) {
            // optimization
            superBuildVariables(evaluationContext, children);
        } else {
            final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
            final Map<String, LocalVariableProxyImpl> visibleVariables = ContainerUtil.map2Map(getVisibleVariables(), var -> Pair.create(var.name(), var));
            Pair<Set<String>, Set<TextWithImports>> usedVars = EMPTY_USED_VARS;
            if (sourcePosition != null) {
                usedVars = ApplicationManager.getApplication().runReadAction(new Computable<Pair<Set<String>, Set<TextWithImports>>>() {

                    @Override
                    public Pair<Set<String>, Set<TextWithImports>> compute() {
                        return findReferencedVars(ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition);
                    }
                });
            }
            // add locals
            if (myAutoWatchMode) {
                for (String var : usedVars.first) {
                    LocalVariableProxyImpl local = visibleVariables.get(var);
                    if (local != null) {
                        children.add(JavaValue.create(myNodeManager.getLocalVariableDescriptor(null, local), evaluationContext, myNodeManager));
                    }
                }
            } else {
                superBuildVariables(evaluationContext, children);
            }
            final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
            evalContextCopy.setAutoLoadClasses(false);
            if (sourcePosition != null) {
                Set<TextWithImports> extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext);
                // add extra vars
                addToChildrenFrom(extraVars, children, evaluationContext);
            }
            // add expressions
            addToChildrenFrom(usedVars.second, children, evalContextCopy);
        }
    } catch (EvaluateException e) {
        if (e.getCause() instanceof AbsentInformationException) {
            children.add(LOCAL_VARIABLES_INFO_UNAVAILABLE_MESSAGE_NODE);
            // trying to collect values from variable slots
            try {
                for (Map.Entry<DecompiledLocalVariable, Value> entry : LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess, true).entrySet()) {
                    children.add(JavaValue.create(myNodeManager.getArgumentValueDescriptor(null, entry.getKey(), entry.getValue()), evaluationContext, myNodeManager));
                }
            } catch (Exception ex) {
                LOG.info(ex);
            }
        } else {
            throw e;
        }
    }
}
Also used : LocalVariableProxyImpl(com.intellij.debugger.jdi.LocalVariableProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Example 9 with EvaluationContextImpl

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

the class ValueDescriptorImpl method getValue.

@Override
public Value getValue() {
    // to keep temporary objects
    if (Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
        final EvaluationContextImpl evalContext = myStoredEvaluationContext;
        if (evalContext != null && !evalContext.getSuspendContext().isResumed() && myValue instanceof ObjectReference && VirtualMachineProxyImpl.isCollected((ObjectReference) myValue)) {
            final Semaphore semaphore = new Semaphore();
            semaphore.down();
            evalContext.getDebugProcess().getManagerThread().invoke(new SuspendContextCommandImpl(evalContext.getSuspendContext()) {

                @Override
                public void contextAction() throws Exception {
                    // re-setting the context will cause value recalculation
                    try {
                        setContext(myStoredEvaluationContext);
                    } finally {
                        semaphore.up();
                    }
                }

                @Override
                protected void commandCancelled() {
                    semaphore.up();
                }
            });
            semaphore.waitFor();
        }
    }
    assertValueReady();
    return myValue;
}
Also used : EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) Semaphore(com.intellij.util.concurrency.Semaphore) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 10 with EvaluationContextImpl

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

the class DebuggerTreeNodeImpl method calcValue.

public void calcValue() {
    final DebuggerContextImpl context = getTree().getDebuggerContext();
    update(context, () -> {
        EvaluationContextImpl evaluationContext = context.createEvaluationContext();
        getDescriptor().setContext(evaluationContext);
        getDescriptor().updateRepresentation(evaluationContext, new DescriptorLabelListener() {

            @Override
            public void labelChanged() {
                updateCaches();
                DebuggerTreeNodeImpl.this.labelChanged();
            }
        });
        childrenChanged(true);
    }, false);
}
Also used : EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) DescriptorLabelListener(com.intellij.debugger.ui.tree.render.DescriptorLabelListener)

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