Suspend new threads if the current session is suspended in "All" suspend policy (PY-2431)

Sometimes the notification about new threads may come slow from the Python side. We should check if the current session is suspended in the "Suspend all threads" mode and suspend new thread, which hasn't been suspended.
This commit is contained in:
Elizaveta Shashkova
2016-06-14 18:42:03 +03:00
parent 04f7fb1fce
commit 64117a08a4
3 changed files with 38 additions and 2 deletions
@@ -35,5 +35,7 @@ public interface IPyDebugProcess extends PyFrameAccessor {
void suspendAllOtherThreads(PyThreadInfo thread);
boolean isSuspendedOnAllThreadsPolicy();
XDebugSession getSession();
}
@@ -572,6 +572,11 @@ public class RemoteDebugger implements ProcessDebugger {
final PyThreadInfo thread = parseThreadEvent(frame);
if (!thread.isPydevThread()) { // ignore pydevd threads
myThreads.put(thread.getId(), thread);
if (myDebugProcess.getSession().isSuspended() && myDebugProcess.isSuspendedOnAllThreadsPolicy()) {
// Sometimes the notification about new threads may come slow from the Python side. We should check if
// the current session is suspended in the "Suspend all threads" mode and suspend new thread, which hasn't been suspended
suspendThread(thread.getId());
}
}
break;
}
@@ -501,9 +501,38 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
}
public void suspendAllOtherThreads(PyThreadInfo thread) {
if (thread.getStopReason() == AbstractCommand.SET_BREAKPOINT) { // add check for breakpoint setting
myDebugger.suspendOtherThreads(thread);
myDebugger.suspendOtherThreads(thread);
}
/**
* Check if there is the thread suspended on the breakpoint with "Suspend all" policy
*
* @return true if this thread exists
*/
@Override
public boolean isSuspendedOnAllThreadsPolicy() {
if (getSession().isSuspended()) {
for (PyThreadInfo threadInfo : getThreads()) {
final List<PyStackFrameInfo> frames = threadInfo.getFrames();
if ((threadInfo.getState() == PyThreadInfo.State.SUSPENDED) && (frames != null)) {
XBreakpoint<?> breakpoint = null;
if (threadInfo.isStopOnBreakpoint()) {
final PySourcePosition position = frames.get(0).getPosition();
breakpoint = myRegisteredBreakpoints.get(position);
}
else if (threadInfo.isExceptionBreak()) {
String exceptionName = threadInfo.getMessage();
if (exceptionName != null) {
breakpoint = myRegisteredExceptionBreakpoints.get(exceptionName);
}
}
if ((breakpoint != null) && (breakpoint.getSuspendPolicy() == SuspendPolicy.ALL)) {
return true;
}
}
}
}
return false;
}
private void passToAllThreads(final ResumeOrStepCommand.Mode mode) {