Search in sources :

Example 1 with StackFrameProxyImpl

use of com.intellij.debugger.jdi.StackFrameProxyImpl in project intellij-community by JetBrains.

the class StackCapturingLineBreakpoint method processLocatableEvent.

@Override
public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException {
    SuspendContextImpl suspendContext = action.getSuspendContext();
    if (suspendContext != null) {
        ThreadReferenceProxyImpl thread = suspendContext.getThread();
        if (thread != null) {
            DebugProcessImpl process = suspendContext.getDebugProcess();
            try {
                StackFrameProxyImpl frameProxy = ContainerUtil.getFirstItem(thread.forceFrames());
                if (frameProxy != null) {
                    Map<Object, List<StackFrameItem>> stacks = process.getUserData(CAPTURED_STACKS);
                    if (stacks == null) {
                        stacks = new CapturedStacksMap();
                        process.putUserData(CAPTURED_STACKS, Collections.synchronizedMap(stacks));
                    }
                    Value key = myCaptureEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frameProxy));
                    if (key instanceof ObjectReference) {
                        List<StackFrameItem> frames = StackFrameItem.createFrames(suspendContext, true);
                        if (frames.size() > MAX_STACK_LENGTH) {
                            frames = frames.subList(0, MAX_STACK_LENGTH);
                        }
                        stacks.put(getKey((ObjectReference) key), frames);
                    }
                }
            } catch (EvaluateException e) {
                LOG.debug(e);
                process.printToConsole(DebuggerBundle.message("error.unable.to.evaluate.capture.expression", e.getMessage()) + "\n");
            }
        }
    }
    return false;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StackFrameItem(com.intellij.debugger.memory.utils.StackFrameItem)

Example 2 with StackFrameProxyImpl

use of com.intellij.debugger.jdi.StackFrameProxyImpl in project intellij-community by JetBrains.

the class Breakpoint method processLocatableEvent.

@Override
public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException {
    SuspendContextImpl context = action.getSuspendContext();
    if (!isValid()) {
        context.getDebugProcess().getRequestsManager().deleteRequest(this);
        return false;
    }
    String title = DebuggerBundle.message("title.error.evaluating.breakpoint.condition");
    try {
        StackFrameProxyImpl frameProxy = context.getThread().frame(0);
        if (frameProxy == null) {
            // might be if the thread has been collected
            return false;
        }
        EvaluationContextImpl evaluationContext = new EvaluationContextImpl(context, frameProxy, getThisObject(context, event));
        if (!evaluateCondition(evaluationContext, event)) {
            return false;
        }
        title = DebuggerBundle.message("title.error.evaluating.breakpoint.action");
        runAction(evaluationContext, event);
    } catch (final EvaluateException ex) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            System.out.println(ex.getMessage());
            return false;
        }
        throw new EventProcessingException(title, ex.getMessage(), ex);
    }
    return true;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl)

Example 3 with StackFrameProxyImpl

use of com.intellij.debugger.jdi.StackFrameProxyImpl in project intellij-community by JetBrains.

the class Breakpoint method evaluateCondition.

public boolean evaluateCondition(final EvaluationContextImpl context, LocatableEvent event) throws EvaluateException {
    DebugProcessImpl debugProcess = context.getDebugProcess();
    if (isCountFilterEnabled() && !isConditionEnabled()) {
        debugProcess.getVirtualMachineProxy().suspend();
        debugProcess.getRequestsManager().deleteRequest(this);
        createRequest(debugProcess);
        debugProcess.getVirtualMachineProxy().resume();
    }
    if (isInstanceFiltersEnabled()) {
        Value value = context.getThisObject();
        if (value != null) {
            // non-static
            ObjectReference reference = (ObjectReference) value;
            if (!hasObjectID(reference.uniqueID())) {
                return false;
            }
        }
    }
    if (isClassFiltersEnabled() && !typeMatchesClassFilters(calculateEventClass(context, event), getClassFilters(), getClassExclusionFilters())) {
        return false;
    }
    if (isConditionEnabled()) {
        TextWithImports condition = getCondition();
        if (condition.isEmpty()) {
            return true;
        }
        StackFrameProxyImpl frame = context.getFrameProxy();
        if (frame != null) {
            Location location = frame.location();
            if (location != null) {
                ThreeState result = debugProcess.getPositionManager().evaluateCondition(context, frame, location, condition.getText());
                if (result != ThreeState.UNSURE) {
                    return result == ThreeState.YES;
                }
            }
        }
        try {
            SourcePosition contextSourcePosition = ContextUtil.getSourcePosition(context);
            ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, () -> {
                // IMPORTANT: calculate context psi element basing on the location where the exception
                // has been hit, not on the location where it was set. (For line breakpoints these locations are the same, however,
                // for method, exception and field breakpoints these locations differ)
                PsiElement contextElement = ContextUtil.getContextElement(contextSourcePosition);
                // as a last resort
                PsiElement contextPsiElement = contextElement != null ? contextElement : getEvaluationElement();
                return EvaluatorCache.cacheOrGet("ConditionEvaluator", event.request(), contextPsiElement, condition, () -> createExpressionEvaluator(myProject, contextPsiElement, contextSourcePosition, condition, this::createConditionCodeFragment));
            });
            if (!DebuggerUtilsEx.evaluateBoolean(evaluator, context)) {
                return false;
            }
        } catch (EvaluateException ex) {
            if (ex.getCause() instanceof VMDisconnectedException) {
                return false;
            }
            throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.failed.evaluating.breakpoint.condition", condition, ex.getMessage()));
        }
    }
    if (isCountFilterEnabled() && isConditionEnabled()) {
        Long hitCount = ObjectUtils.notNull((Long) event.request().getProperty(HIT_COUNTER), 0L) + 1;
        event.request().putProperty(HIT_COUNTER, hitCount);
        return hitCount % getCountFilter() == 0;
    }
    return true;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) ThreeState(com.intellij.util.ThreeState) PsiElement(com.intellij.psi.PsiElement)

Example 4 with StackFrameProxyImpl

use of com.intellij.debugger.jdi.StackFrameProxyImpl 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 5 with StackFrameProxyImpl

use of com.intellij.debugger.jdi.StackFrameProxyImpl 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)

Aggregations

StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)21 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)14 Nullable (org.jetbrains.annotations.Nullable)6 SourcePosition (com.intellij.debugger.SourcePosition)5 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)5 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)4 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)4 Project (com.intellij.openapi.project.Project)4 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)3 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)3 Location (com.sun.jdi.Location)3 ObjectReference (com.sun.jdi.ObjectReference)3 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)2 DebuggerUtilsEx (com.intellij.debugger.impl.DebuggerUtilsEx)2 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)2 Computable (com.intellij.openapi.util.Computable)2 com.intellij.psi (com.intellij.psi)2 PsiElement (com.intellij.psi.PsiElement)2 ThreeState (com.intellij.util.ThreeState)2 Method (com.sun.jdi.Method)2