diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java index 21b9d8be2867..06a6864adb63 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java @@ -1,5 +1,7 @@ package com.jetbrains.python.debugger.pydev; +import com.google.common.base.Function; +import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -202,6 +204,17 @@ public class MultiProcessDebugger implements ProcessDebugger { return debugger; } else { + // thread is not found in registry - lets search for it in attached debuggers + + for (ProcessDebugger d : myOtherDebuggers) { + for (PyThreadInfo thread : d.getThreads()) { + if (threadId.equals(thread.getId())) { + return d; + } + } + } + + //if not found then return main debugger return myMainDebugger; } } @@ -240,37 +253,48 @@ public class MultiProcessDebugger implements ProcessDebugger { @Override public Collection getThreads() { - List threads = Lists.newArrayList(myMainDebugger.getThreads()); - - List result = Lists.newArrayList(); - cleanOtherDebuggers(); - collectAndRegisterOtherDebuggersThreads(threads); //we don't register mainDebugger as it is default if there is no mapping - + List threads = collectAllThreads(); if (myOtherDebuggers.size() > 0) { //here we add process id to thread name in case there are more then one process - threads = addProcessIdToThreadName(threads, result); + return Collections.unmodifiableCollection(Collections2.transform(threads, new Function() { + @Override + public PyThreadInfo apply(PyThreadInfo t) { + String threadName = ThreadRegistry.threadName(t.getName(), t.getId()); + PyThreadInfo newThread = + new PyThreadInfo(t.getId(), threadName, t.getFrames(), + t.getStopReason(), + t.getMessage()); + newThread.updateState(t.getState(), t.getFrames()); + return newThread; + } + })); + } + else { + return Collections.unmodifiableCollection(threads); } - - return Collections.unmodifiableCollection(threads); } - private static List addProcessIdToThreadName(List threads, List result) { - for (PyThreadInfo t : threads) { - String threadName = ThreadRegistry.threadName(t.getName(), t.getId()); - PyThreadInfo newThread = - new PyThreadInfo(t.getId(), threadName, t.getFrames(), - t.getStopReason(), - t.getMessage()); - newThread.updateState(t.getState(), t.getFrames()); - result.add(newThread); + private List collectAllThreads() { + List result = Lists.newArrayList(); + + result.addAll(myMainDebugger.getThreads()); + + //collect threads and add them to registry to faster access + //we don't register mainDebugger as it is default if there is no mapping + for (RemoteDebugger d : myOtherDebuggers) { + result.addAll(d.getThreads()); + for (PyThreadInfo t : d.getThreads()) { + myThreadRegistry.register(t.getId(), d); + } } - threads = result; - return threads; + + return result; } + private void cleanOtherDebuggers() { synchronized (myOtherDebuggers) { removeDisconnected(getOtherDebuggers()); @@ -299,15 +323,6 @@ public class MultiProcessDebugger implements ProcessDebugger { } } - private void collectAndRegisterOtherDebuggersThreads(List threads) { - for (RemoteDebugger d : getOtherDebuggers()) { - threads.addAll(d.getThreads()); - for (PyThreadInfo t : d.getThreads()) { - myThreadRegistry.register(t.getId(), d); - } - } - } - private ArrayList getOtherDebuggers() { synchronized (myOtherDebuggers) { return Lists.newArrayList(myOtherDebuggers);