Search in sources :

Example 41 with EvaluateException

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

the class ThrowEvaluator method evaluate.

@Override
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    ObjectReference exception = (ObjectReference) myExceptionEvaluator.evaluate(context);
    EvaluateException ex = new EvaluateException(DebuggerBundle.message("evaluation.error.method.exception", exception.referenceType().name()));
    ex.setTargetException(exception);
    throw ex;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ObjectReference(com.sun.jdi.ObjectReference)

Example 42 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException 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 43 with EvaluateException

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

the class CompilingEvaluatorImpl method compile.

@Override
@NotNull
protected Collection<ClassObject> compile(@Nullable JavaSdkVersion debuggeeVersion) throws EvaluateException {
    if (myCompiledClasses == null) {
        Module module = ReadAction.compute(() -> ModuleUtilCore.findModuleForPsiElement(myPsiContext));
        List<String> options = new ArrayList<>();
        options.add("-encoding");
        options.add("UTF-8");
        List<File> platformClasspath = new ArrayList<>();
        List<File> classpath = new ArrayList<>();
        AnnotationProcessingConfiguration profile = null;
        if (module != null) {
            assert myProject.equals(module.getProject()) : module + " is from another project";
            profile = CompilerConfiguration.getInstance(myProject).getAnnotationProcessingConfiguration(module);
            ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
            for (String s : rootManager.orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) {
                classpath.add(new File(s));
            }
            for (String s : rootManager.orderEntries().compileOnly().sdkOnly().getPathsList().getPathList()) {
                platformClasspath.add(new File(s));
            }
        }
        JavaBuilder.addAnnotationProcessingOptions(options, profile);
        Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
        JavaSdkVersion buildRuntimeVersion = runtime.getSecond();
        // if compiler or debuggee version or both are unknown, let source and target be the compiler's defaults
        if (buildRuntimeVersion != null && debuggeeVersion != null) {
            JavaSdkVersion minVersion = buildRuntimeVersion.ordinal() > debuggeeVersion.ordinal() ? debuggeeVersion : buildRuntimeVersion;
            String sourceOption = getSourceOption(minVersion.getMaxLanguageLevel());
            options.add("-source");
            options.add(sourceOption);
            options.add("-target");
            options.add(sourceOption);
        }
        CompilerManager compilerManager = CompilerManager.getInstance(myProject);
        File sourceFile = null;
        try {
            sourceFile = generateTempSourceFile(compilerManager.getJavacCompilerWorkingDir());
            File srcDir = sourceFile.getParentFile();
            List<File> sourcePath = Collections.emptyList();
            Set<File> sources = Collections.singleton(sourceFile);
            myCompiledClasses = compilerManager.compileJavaCode(options, platformClasspath, classpath, Collections.emptyList(), sourcePath, sources, srcDir);
        } catch (CompilationException e) {
            StringBuilder res = new StringBuilder("Compilation failed:\n");
            for (CompilationException.Message m : e.getMessages()) {
                if (m.getCategory() == CompilerMessageCategory.ERROR) {
                    res.append(m.getText()).append("\n");
                }
            }
            throw new EvaluateException(res.toString());
        } catch (Exception e) {
            throw new EvaluateException(e.getMessage());
        } finally {
            if (sourceFile != null) {
                FileUtil.delete(sourceFile);
            }
        }
    }
    return myCompiledClasses;
}
Also used : CompilationException(com.intellij.openapi.compiler.CompilationException) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) CompilerManager(com.intellij.openapi.compiler.CompilerManager) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) AnnotationProcessingConfiguration(org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration) CompilationException(com.intellij.openapi.compiler.CompilationException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) IOException(java.io.IOException) PrepareFailedException(com.intellij.refactoring.extractMethod.PrepareFailedException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with EvaluateException

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

the class DebuggerTreeNodeExpression method castToRuntimeType.

public static PsiExpression castToRuntimeType(PsiExpression expression, Value value) throws EvaluateException {
    if (!(value instanceof ObjectReference)) {
        return expression;
    }
    ReferenceType valueType = ((ObjectReference) value).referenceType();
    if (valueType == null) {
        return expression;
    }
    Project project = expression.getProject();
    PsiType type = RuntimeTypeEvaluator.getCastableRuntimeType(project, value);
    if (type == null) {
        return expression;
    }
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
    String typeName = type.getCanonicalText();
    try {
        PsiParenthesizedExpression parenthExpression = (PsiParenthesizedExpression) elementFactory.createExpressionFromText("((" + typeName + ")expression)", null);
        //noinspection ConstantConditions
        ((PsiTypeCastExpression) parenthExpression.getExpression()).getOperand().replace(expression);
        Set<String> imports = expression.getUserData(ADDITIONAL_IMPORTS_KEY);
        if (imports == null) {
            imports = new SmartHashSet<>();
        }
        imports.add(typeName);
        parenthExpression.putUserData(ADDITIONAL_IMPORTS_KEY, imports);
        return parenthExpression;
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("error.invalid.type.name", typeName), e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ObjectReference(com.sun.jdi.ObjectReference) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ReferenceType(com.sun.jdi.ReferenceType)

Example 45 with EvaluateException

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

the class NodeDescriptorImpl method updateRepresentationNoNotify.

protected void updateRepresentationNoNotify(EvaluationContextImpl context, DescriptorLabelListener labelListener) {
    try {
        try {
            myEvaluateException = null;
            myLabel = calcRepresentation(context, labelListener);
        } catch (InconsistentDebugInfoException e) {
            throw new EvaluateException(DebuggerBundle.message("error.inconsistent.debug.info"));
        } catch (InvalidStackFrameException e) {
            throw new EvaluateException(DebuggerBundle.message("error.invalid.stackframe"));
        } catch (VMDisconnectedException e) {
            throw e;
        } catch (RuntimeException e) {
            if (e.getCause() instanceof InterruptedException) {
                throw e;
            }
            LOG.error(e);
            throw new EvaluateException("Internal error, see logs for more details");
        }
    } catch (EvaluateException e) {
        setFailed(e);
    }
}
Also used : VMDisconnectedException(com.sun.jdi.VMDisconnectedException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) InconsistentDebugInfoException(com.sun.jdi.InconsistentDebugInfoException) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException)

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