IDEA-153426 Debugging streams and lamdas: debugger enters unexpectedly java.util...
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 22 Mar 2016 15:50:40 +0000 (18:50 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 22 Mar 2016 15:51:59 +0000 (18:51 +0300)
java/debugger/impl/src/com/intellij/debugger/engine/ActionMethodFilter.java
java/debugger/impl/src/com/intellij/debugger/engine/ClassInstanceMethodFilter.java
java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java
java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java
java/debugger/impl/src/com/intellij/debugger/engine/RequestHint.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java

index 37f3adaf2e96f3aa2e5233db8dd8228472dde0f1..e33c14ca1d2bc576adda0793d8370d20e1d31e75 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,5 +19,5 @@ package com.intellij.debugger.engine;
  * @author egor
  */
 public interface ActionMethodFilter {
-  int onReached(SuspendContextImpl context);
+  int onReached(SuspendContextImpl context, RequestHint hint);
 }
index 9f760da9e0c8a5e84661b598ba5c8a864f8c9af2..d5cdc618b87def0c89cb00628df8e9bbe8a48cdd 100644 (file)
@@ -43,7 +43,7 @@ public class ClassInstanceMethodFilter extends ConstructorStepMethodFilter imple
   }
 
   @Override
-  public int onReached(SuspendContextImpl context) {
+  public int onReached(SuspendContextImpl context, RequestHint hint) {
     StackFrameProxyImpl proxy = context.getFrameProxy();
     if (proxy != null) {
       try {
@@ -58,6 +58,7 @@ public class ClassInstanceMethodFilter extends ConstructorStepMethodFilter imple
             breakpoint.setInstanceFiltersEnabled(true);
             breakpoint.setSuspendPolicy(context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD ? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL);
             breakpoint.createRequest(debugProcess);
+            breakpoint.setRequestHint(hint);
             debugProcess.setRunToCursorBreakpoint(breakpoint);
             return RequestHint.RESUME;
           }
index 6da59a74e04dea35720ad192c86e9a242c085b5d..d5194f3a821f5d4708fbee3283a047794edb35f0 100644 (file)
@@ -23,7 +23,6 @@ import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
 import com.intellij.debugger.engine.requests.LocatableEventRequestor;
 import com.intellij.debugger.engine.requests.MethodReturnValueWatcher;
 import com.intellij.debugger.impl.DebuggerSession;
-import com.intellij.debugger.impl.DebuggerUtilsEx;
 import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
 import com.intellij.debugger.jdi.VirtualMachineProxyImpl;
 import com.intellij.debugger.requests.Requestor;
@@ -39,8 +38,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.registry.Registry;
-import com.intellij.ui.classFilter.ClassFilter;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.breakpoints.XBreakpoint;
 import com.intellij.xdebugger.impl.XDebugSessionImpl;
@@ -55,8 +52,6 @@ import com.sun.jdi.request.ThreadDeathRequest;
 import com.sun.jdi.request.ThreadStartRequest;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.List;
-
 /**
  * @author lex
  */
@@ -435,11 +430,7 @@ public class DebugProcessEvents extends DebugProcessImpl {
           XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(message, MessageType.INFO).notify(project);
         }
         if (hint.wasStepTargetMethodMatched() && hint.isResetIgnoreFilters()) {
-          List<ClassFilter> activeFilters = getActiveFilters();
-          String currentClassName = getCurrentClassName(suspendContext.getThread());
-          if (currentClassName == null || !DebuggerUtilsEx.isFiltered(currentClassName, activeFilters)) {
-            mySession.resetIgnoreStepFiltersFlag();
-          }
+          checkPositionNotFiltered(suspendContext.getThread(), filters -> mySession.resetIgnoreStepFiltersFlag());
         }
       }
     }
index ed576232fad2acfbe223b981fe353a476a8630f7..a5176129fb11903b16550824c8cc0d546a915eb8 100644 (file)
@@ -65,10 +65,7 @@ import com.intellij.psi.PsiManager;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.ui.classFilter.ClassFilter;
 import com.intellij.ui.classFilter.DebuggerClassFilterProvider;
-import com.intellij.util.Alarm;
-import com.intellij.util.EventDispatcher;
-import com.intellij.util.ReflectionUtil;
-import com.intellij.util.StringBuilderSpinAllocator;
+import com.intellij.util.*;
 import com.intellij.util.concurrency.Semaphore;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.containers.HashMap;
@@ -398,17 +395,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
       EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager();
       StepRequest stepRequest = requestManager.createStepRequest(stepThreadReference, size, depth);
       if (!(hint != null && hint.isIgnoreFilters()) /*&& depth == StepRequest.STEP_INTO*/) {
-        List<ClassFilter> activeFilters = getActiveFilters();
-
-        if (!activeFilters.isEmpty()) {
-          final String currentClassName = getCurrentClassName(stepThread);
-          if (currentClassName == null || !DebuggerUtilsEx.isFiltered(currentClassName, activeFilters)) {
-            // add class filters
-            for (ClassFilter filter : activeFilters) {
-              stepRequest.addClassExclusionFilter(filter.getPattern());
-            }
-          }
-        }
+        checkPositionNotFiltered(stepThread, filters -> filters.forEach(f -> stepRequest.addClassExclusionFilter(f.getPattern())));
       }
 
       // suspend policy to match the suspend policy of the context:
@@ -429,8 +416,18 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
     }
   }
 
+  public void checkPositionNotFiltered(ThreadReferenceProxyImpl thread, Consumer<List<ClassFilter>> action) {
+    List<ClassFilter> activeFilters = getActiveFilters();
+    if (!activeFilters.isEmpty()) {
+      String currentClassName = getCurrentClassName(thread);
+      if (currentClassName == null || !DebuggerUtilsEx.isFiltered(currentClassName, activeFilters)) {
+        action.consume(activeFilters);
+      }
+    }
+  }
+
   @NotNull
-  static List<ClassFilter> getActiveFilters() {
+  private static List<ClassFilter> getActiveFilters() {
     List<ClassFilter> activeFilters = new ArrayList<>();
     DebuggerSettings settings = DebuggerSettings.getInstance();
     if (settings.TRACING_FILTERS_ENABLED) {
@@ -1588,6 +1585,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb
       if (myBreakpoint != null) {
         myBreakpoint.setSuspendPolicy(suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL);
         myBreakpoint.createRequest(suspendContext.getDebugProcess());
+        myBreakpoint.setRequestHint(hint);
         setRunToCursorBreakpoint(myBreakpoint);
       }
       doStep(suspendContext, stepThread, myStepSize, StepRequest.STEP_INTO, hint);
index ae14c8cb3cf98dd2f9d3a57cfb4f38ebfb60f2e0..c2fae7ccd820a98fd40ce579fd39ebaf02241d0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -187,9 +187,9 @@ public class RequestHint {
     }
   }
 
-  private static int reached(MethodFilter filter, SuspendContextImpl context) {
+  private int reached(MethodFilter filter, SuspendContextImpl context) {
     if (filter instanceof ActionMethodFilter) {
-      return ((ActionMethodFilter)filter).onReached(context);
+      return ((ActionMethodFilter)filter).onReached(context, this);
     }
     return STOP;
   }
index dc5dc1e705679bdce1e0ffa971e10100edd0414f..463f2287aab99c325ee6baaf360e26bdf9aba62d 100644 (file)
 package com.intellij.debugger.ui.breakpoints;
 
 import com.intellij.debugger.SourcePosition;
-import com.intellij.debugger.engine.BreakpointStepMethodFilter;
-import com.intellij.debugger.engine.CompoundPositionManager;
-import com.intellij.debugger.engine.DebugProcessImpl;
-import com.intellij.debugger.engine.LambdaMethodFilter;
+import com.intellij.debugger.engine.*;
 import com.intellij.debugger.engine.evaluation.EvaluateException;
+import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
 import com.intellij.debugger.engine.requests.RequestManagerImpl;
 import com.intellij.debugger.impl.DebuggerUtilsEx;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.util.containers.MultiMap;
 import com.sun.jdi.*;
+import com.sun.jdi.event.LocatableEvent;
 import com.sun.jdi.request.BreakpointRequest;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -40,8 +39,8 @@ import java.util.List;
  */
 public class StepIntoBreakpoint extends RunToCursorBreakpoint {
   private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.StepIntoBreakpoint");
-  @NotNull
-  private final BreakpointStepMethodFilter myFilter;
+  @NotNull private final BreakpointStepMethodFilter myFilter;
+  @Nullable private RequestHint myHint;
 
   StepIntoBreakpoint(@NotNull Project project, @NotNull SourcePosition pos, @NotNull BreakpointStepMethodFilter filter) {
     super(project, pos, false);
@@ -137,4 +136,22 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint {
     }
     return null;
   }
+
+  @Override
+  public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event)
+    throws EventProcessingException {
+    boolean res = super.processLocatableEvent(action, event);
+    if (res && myHint != null && myHint.isResetIgnoreFilters()) {
+      SuspendContextImpl context = action.getSuspendContext();
+      if (context != null) {
+        DebugProcessImpl process = context.getDebugProcess();
+        process.checkPositionNotFiltered(context.getThread(), f -> process.getSession().resetIgnoreStepFiltersFlag());
+      }
+    }
+    return res;
+  }
+
+  public void setRequestHint(RequestHint hint) {
+    myHint = hint;
+  }
 }