do not auto-switch current suspend context if a new thread with suspenPolicy=thread hits a breakpoint (IDEA-116160)

This commit is contained in:
Eugene Zhuravlev
2013-11-24 16:57:02 +01:00
parent 49a033ae3c
commit 79ef033279
3 changed files with 49 additions and 11 deletions

View File

@@ -481,8 +481,10 @@ public class SetValueAction extends DebuggerAction {
stateManager.addListener(new DebuggerContextListener() {
public void changeEvent(DebuggerContextImpl newContext, int event) {
stateManager.removeListener(this);
editor.cancelEditing();
if (event != DebuggerSession.EVENT_THREADS_REFRESH) {
stateManager.removeListener(this);
editor.cancelEditing();
}
}
});

View File

@@ -22,6 +22,7 @@ import com.intellij.debugger.engine.events.DebuggerCommandImpl;
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.jdi.ThreadReferenceProxyImpl;
import com.intellij.debugger.jdi.VirtualMachineProxyImpl;
import com.intellij.debugger.requests.Requestor;
@@ -39,7 +40,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.xdebugger.impl.XDebugSessionImpl;
import com.sun.jdi.InternalException;
import com.sun.jdi.ThreadReference;
@@ -182,7 +182,7 @@ public class DebugProcessEvents extends DebugProcessImpl {
getManagerThread().invokeAndWait(new DebuggerCommandImpl() {
protected void action() throws Exception {
if (eventSet.suspendPolicy() == EventRequest.SUSPEND_ALL && !enableBreakpointsDuringEvaluation()) {
if (eventSet.suspendPolicy() == EventRequest.SUSPEND_ALL && !DebuggerSession.enableBreakpointsDuringEvaluation()) {
// check if there is already one request with policy SUSPEND_ALL
for (SuspendContextImpl context : getSuspendManager().getEventContexts()) {
if (context.getSuspendPolicy() == EventRequest.SUSPEND_ALL) {
@@ -420,7 +420,7 @@ public class DebugProcessEvents extends DebugProcessImpl {
final SuspendManager suspendManager = getSuspendManager();
SuspendContextImpl evaluatingContext = SuspendManagerUtil.getEvaluatingContext(suspendManager, getSuspendContext().getThread());
if (evaluatingContext != null && !enableBreakpointsDuringEvaluation()) {
if (evaluatingContext != null && !DebuggerSession.enableBreakpointsDuringEvaluation()) {
// is inside evaluation, so ignore any breakpoints
suspendManager.voteResume(suspendContext);
return;
@@ -476,10 +476,6 @@ public class DebugProcessEvents extends DebugProcessImpl {
});
}
private static boolean enableBreakpointsDuringEvaluation() {
return Registry.is("debugger.enable.breakpoints.during.evaluation");
}
private void processDefaultEvent(SuspendContextImpl suspendContext) {
preprocessEvent(suspendContext, null);
getSuspendManager().voteResume(suspendContext);

View File

@@ -21,6 +21,7 @@ import com.intellij.debugger.engine.*;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluationListener;
import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
import com.intellij.debugger.engine.jdi.StackFrameProxy;
import com.intellij.debugger.engine.requests.RequestManagerImpl;
import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
@@ -43,9 +44,11 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.PsiCompiledElement;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
@@ -284,7 +287,12 @@ public class DebuggerSession implements AbstractDebuggerSession {
public void resume() {
final SuspendContextImpl suspendContext = getSuspendContext();
if(suspendContext != null) {
mySteppingThroughThreads.clear();
if (suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL) {
mySteppingThroughThreads.clear();
}
else {
mySteppingThroughThreads.remove(suspendContext.getThread());
}
resetIgnoreStepFiltersFlag();
resumeAction(myDebugProcess.createResumeCommand(suspendContext), EVENT_RESUME);
}
@@ -408,6 +416,15 @@ public class DebuggerSession implements AbstractDebuggerSession {
LOG.debug("paused");
}
if (!shouldSetAsActiveContext(suspendContext)) {
DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() {
public void run() {
getContextManager().fireStateChanged(getContextManager().getContext(), EVENT_THREADS_REFRESH);
}
});
return;
}
ThreadReferenceProxyImpl currentThread = suspendContext.getThread();
final StackFrameContext positionContext;
@@ -503,9 +520,10 @@ public class DebuggerSession implements AbstractDebuggerSession {
else if (sourceMissing) {
// adjust position to be position of the breakpoint in order to show the real originator of the event
position = breakpointPosition;
final StackFrameProxy frameProxy = positionContext.getFrameProxy();
String className;
try {
className = positionContext.getFrameProxy().location().declaringType().name();
className = frameProxy != null? frameProxy.location().declaringType().name() : "";
}
catch (EvaluateException e) {
className = "";
@@ -527,6 +545,23 @@ public class DebuggerSession implements AbstractDebuggerSession {
});
}
private boolean shouldSetAsActiveContext(final SuspendContextImpl suspendContext) {
final ThreadReferenceProxyImpl newThread = suspendContext.getThread();
if (newThread == null || suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL || isSteppingThrough(newThread)) {
return true;
}
final SuspendContextImpl currentSuspendContext = getContextManager().getContext().getSuspendContext();
if (currentSuspendContext == null) {
return true;
}
if (enableBreakpointsDuringEvaluation()) {
final ThreadReferenceProxyImpl currentThread = currentSuspendContext.getThread();
return currentThread == null || Comparing.equal(currentThread.getThreadReference(), newThread.getThreadReference());
}
return false;
}
public void resumed(final SuspendContextImpl suspendContext) {
final SuspendContextImpl currentContext = getProcess().getSuspendManager().getPausedContext();
DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() {
@@ -626,4 +661,9 @@ public class DebuggerSession implements AbstractDebuggerSession {
});
}
}
public static boolean enableBreakpointsDuringEvaluation() {
return Registry.is("debugger.enable.breakpoints.during.evaluation");
}
}