Search in sources :

Example 31 with EvaluateException

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

the class StackTraceElementObjectRenderer method getFullValueEvaluator.

@Nullable
@Override
public XFullValueEvaluator getFullValueEvaluator(final EvaluationContextImpl evaluationContext, final ValueDescriptorImpl valueDescriptor) {
    return new JavaValue.JavaFullValueEvaluator(DebuggerBundle.message("message.node.navigate"), evaluationContext) {

        @Override
        public void evaluate(@NotNull XFullValueEvaluationCallback callback) {
            Value value = valueDescriptor.getValue();
            ClassType type = ((ClassType) value.type());
            Method toString = type.concreteMethodByName("toString", "()Ljava/lang/String;");
            if (toString != null) {
                try {
                    Value res = evaluationContext.getDebugProcess().invokeMethod(evaluationContext, (ObjectReference) value, toString, Collections.emptyList());
                    if (res instanceof StringReference) {
                        callback.evaluated("");
                        final String line = ((StringReference) res).value();
                        ApplicationManager.getApplication().runReadAction(() -> {
                            ExceptionFilter filter = new ExceptionFilter(evaluationContext.getDebugProcess().getSession().getSearchScope());
                            Filter.Result result = filter.applyFilter(line, line.length());
                            if (result != null) {
                                final HyperlinkInfo info = result.getFirstHyperlinkInfo();
                                if (info != null) {
                                    DebuggerUIUtil.invokeLater(() -> info.navigate(valueDescriptor.getProject()));
                                }
                            }
                        });
                    }
                } catch (EvaluateException e) {
                    LOG.info("Exception while getting stack info", e);
                }
            }
        }

        @Override
        public boolean isShowValuePopup() {
            return false;
        }
    };
}
Also used : ExceptionFilter(com.intellij.execution.filters.ExceptionFilter) NotNull(org.jetbrains.annotations.NotNull) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ExceptionFilter(com.intellij.execution.filters.ExceptionFilter) Filter(com.intellij.execution.filters.Filter) JavaValue(com.intellij.debugger.engine.JavaValue) Nullable(org.jetbrains.annotations.Nullable)

Example 32 with EvaluateException

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

the class ToStringRenderer method calcLabel.

@Override
public String calcLabel(final ValueDescriptor valueDescriptor, EvaluationContext evaluationContext, final DescriptorLabelListener labelListener) throws EvaluateException {
    final Value value = valueDescriptor.getValue();
    BatchEvaluator.getBatchEvaluator(evaluationContext.getDebugProcess()).invoke(new ToStringCommand(evaluationContext, value) {

        @Override
        public void evaluationResult(String message) {
            valueDescriptor.setValueLabel(StringUtil.notNullize(message));
            labelListener.labelChanged();
        }

        @Override
        public void evaluationError(String message) {
            final String msg = value != null ? message + " " + DebuggerBundle.message("evaluation.error.cannot.evaluate.tostring", value.type().name()) : message;
            valueDescriptor.setValueLabelFailed(new EvaluateException(msg, null));
            labelListener.labelChanged();
        }
    });
    return XDebuggerUIConstants.COLLECTING_DATA_MESSAGE;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Value(com.sun.jdi.Value)

Example 33 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException in project smali by JesusFreke.

the class LazyValue method getNullableValue.

@Nullable
protected T getNullableValue(boolean allowNull) {
    if (value == null) {
        try {
            if (evaluationContext == null) {
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(project).getContext();
                evaluationContext = debuggerContext.createEvaluationContext();
                if (evaluationContext == null) {
                    if (!allowNull) {
                        throw new IllegalStateException("Can't create evaluation context");
                    }
                    return null;
                }
            }
            value = SmaliCodeFragmentFactory.evaluateRegister(evaluationContext, method, registerNumber, type);
            evaluationContext = null;
        } catch (EvaluateException ex) {
            if (!allowNull) {
                throw new IllegalStateException(ex);
            }
            return null;
        }
    }
    return (T) value;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Nullable(javax.annotation.Nullable)

Example 34 with EvaluateException

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

the class BitmapEvaluatorProvider method getBitmapFromDrawable.

@Nullable
private Value getBitmapFromDrawable(@NotNull ObjectReference bitmapDrawable) {
    try {
        DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess();
        Method getBitmapMethod = DebuggerUtils.findMethod(bitmapDrawable.referenceType(), "getBitmap", "()Landroid/graphics/Bitmap;");
        if (getBitmapMethod == null) {
            return null;
        }
        return debugProcess.invokeMethod(myEvaluationContext, bitmapDrawable, getBitmapMethod, Collections.emptyList());
    } catch (EvaluateException ignored) {
        return null;
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with EvaluateException

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

the class DynamicResourceIdResolver method getAndroidResourceName.

@Nullable
@Override
public String getAndroidResourceName(int resId) {
    String id = myDelegate.getAndroidResourceName(resId);
    if (id != null) {
        return id;
    }
    DebugProcess debugProcess = myContext.getDebugProcess();
    VirtualMachineProxyImpl vmProxy = (VirtualMachineProxyImpl) debugProcess.getVirtualMachineProxy();
    List<ReferenceType> classes = vmProxy.classesByName(CLASS_RESOURCES);
    if (classes.isEmpty()) {
        LOG.warn(CLASS_RESOURCES + " class not loaded?");
        return null;
    }
    if (classes.size() != 1) {
        LOG.warn("Expected a single Resource class loaded, but found " + classes.size());
    }
    ReferenceType resourcesClassType = classes.get(0);
    Method getResourceNameMethod = DebuggerUtils.findMethod(resourcesClassType, "getResourceName", "(I)Ljava/lang/String;");
    if (getResourceNameMethod == null) {
        LOG.warn("Unable to locate getResourceName(int id) in class " + resourcesClassType.name());
        return null;
    }
    List<ObjectReference> instances = resourcesClassType.instances(10);
    if (instances.isEmpty()) {
        LOG.warn("No instances of Resource class found");
        return null;
    }
    List args = Collections.singletonList(DebuggerUtilsEx.createValue(vmProxy, "int", resId));
    for (ObjectReference ref : instances) {
        try {
            Value value = debugProcess.invokeMethod(myContext, ref, getResourceNameMethod, args);
            if (value instanceof StringReference) {
                StringReference nameRef = (StringReference) value;
                return nameRef.value();
            }
        } catch (EvaluateException e) {
            ObjectReference exception = e.getExceptionFromTargetVM();
            // do not log Resources$NotFoundException
            if (exception == null || !DebuggerUtils.instanceOf(exception.type(), "android.content.res.Resources$NotFoundException")) {
                LOG.warn("Unexpected error while invoking Resources.getResourceName()", e);
            // continue and try this on other object references
            }
        }
    }
    return null;
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) List(java.util.List) 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