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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations