diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java index 4f2c7fdb9ad4..eb47039e76c2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java @@ -150,17 +150,18 @@ public class ToggleFieldBreakpointAction extends AnAction { if(selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) { final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext); final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); - if (debugProcess != null) { // if there is an active debugsession + if (debugProcess != null) { // if there is an active debug session final Ref positionRef = new Ref<>(null); debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) { + @Override public Priority getPriority() { return Priority.HIGH; } + + @Override public void threadAction() { - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)); - } + ApplicationManager.getApplication().runReadAction(() -> { + positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)); }); } }); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 9e76d0157ec8..6b6bca625291 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -25,7 +25,10 @@ import com.intellij.debugger.DebuggerInvocationUtil; import com.intellij.debugger.engine.BreakpointStepMethodFilter; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.requests.RequestManagerImpl; -import com.intellij.debugger.impl.*; +import com.intellij.debugger.impl.DebuggerContextImpl; +import com.intellij.debugger.impl.DebuggerContextListener; +import com.intellij.debugger.impl.DebuggerManagerImpl; +import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -74,8 +77,8 @@ import java.util.Map; public class BreakpointManager { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.BreakpointManager"); - @NonNls private static final String MASTER_BREAKPOINT_TAGNAME = "master_breakpoint"; - @NonNls private static final String SLAVE_BREAKPOINT_TAGNAME = "slave_breakpoint"; + @NonNls private static final String MASTER_BREAKPOINT_TAG_NAME = "master_breakpoint"; + @NonNls private static final String SLAVE_BREAKPOINT_TAG_NAME = "slave_breakpoint"; @NonNls private static final String DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME = "default_suspend_policy"; @NonNls private static final String DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME = "default_condition_enabled"; @@ -144,19 +147,16 @@ public class BreakpointManager { } public void editBreakpoint(final Breakpoint breakpoint, final Editor editor) { - DebuggerInvocationUtil.swingInvokeLater(myProject, new Runnable() { - @Override - public void run() { - XBreakpoint xBreakpoint = breakpoint.myXBreakpoint; - if (xBreakpoint instanceof XLineBreakpointImpl) { - RangeHighlighter highlighter = ((XLineBreakpointImpl)xBreakpoint).getHighlighter(); - if (highlighter != null) { - GutterIconRenderer renderer = highlighter.getGutterIconRenderer(); - if (renderer != null) { - DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class).getEditBreakpointAction().editBreakpoint( - myProject, editor, breakpoint.myXBreakpoint, renderer - ); - } + DebuggerInvocationUtil.swingInvokeLater(myProject, () -> { + XBreakpoint xBreakpoint = breakpoint.myXBreakpoint; + if (xBreakpoint instanceof XLineBreakpointImpl) { + RangeHighlighter highlighter = ((XLineBreakpointImpl)xBreakpoint).getHighlighter(); + if (highlighter != null) { + GutterIconRenderer renderer = highlighter.getGutterIconRenderer(); + if (renderer != null) { + DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class).getEditBreakpointAction().editBreakpoint( + myProject, editor, breakpoint.myXBreakpoint, renderer + ); } } } @@ -242,24 +242,21 @@ public class BreakpointManager { public ExceptionBreakpoint addExceptionBreakpoint(@NotNull final String exceptionClassName, final String packageName) { ApplicationManager.getApplication().assertIsDispatchThread(); final JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); - return ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public ExceptionBreakpoint compute() { - XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() - .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); - Breakpoint javaBreakpoint = getJavaBreakpoint(xBreakpoint); - if (javaBreakpoint instanceof ExceptionBreakpoint) { - ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint)javaBreakpoint; - exceptionBreakpoint.setQualifiedName(exceptionClassName); - exceptionBreakpoint.setPackageName(packageName); - addBreakpoint(exceptionBreakpoint); - if (LOG.isDebugEnabled()) { - LOG.debug("ExceptionBreakpoint Added"); - } - return exceptionBreakpoint; + return ApplicationManager.getApplication().runWriteAction((Computable)() -> { + XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); + Breakpoint javaBreakpoint = getJavaBreakpoint(xBreakpoint); + if (javaBreakpoint instanceof ExceptionBreakpoint) { + ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint)javaBreakpoint; + exceptionBreakpoint.setQualifiedName(exceptionClassName); + exceptionBreakpoint.setPackageName(packageName); + addBreakpoint(exceptionBreakpoint); + if (LOG.isDebugEnabled()) { + LOG.debug("ExceptionBreakpoint Added"); } - return null; + return exceptionBreakpoint; } + return null; }); } @@ -279,14 +276,9 @@ public class BreakpointManager { private > XLineBreakpoint addXLineBreakpoint(Class> typeCls, Document document, final int lineIndex) { final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); final VirtualFile file = FileDocumentManager.getInstance().getFile(document); - return ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public XLineBreakpoint compute() { - return XDebuggerManager.getInstance(myProject).getBreakpointManager() - .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, - ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex)); - } - }); + return ApplicationManager.getApplication().runWriteAction((Computable)() -> XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, + ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex))); } /** @@ -317,107 +309,98 @@ public class BreakpointManager { doRead(parentNode); } else { - myStartupManager.registerPostStartupActivity(new Runnable() { - @Override - public void run() { - doRead(parentNode); - } - }); + myStartupManager.registerPostStartupActivity(() -> doRead(parentNode)); } } private void doRead(@NotNull final Element parentNode) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - @SuppressWarnings({"HardCodedStringLiteral"}) - public void run() { - final Map nameToBreakpointMap = new THashMap<>(); - try { - final List groups = parentNode.getChildren(); - for (final Object group1 : groups) { - final Element group = (Element)group1; - if (group.getName().equals(RULES_GROUP_NAME)) { - continue; - } - // skip already converted - if (group.getAttribute(CONVERTED_PARAM) != null) { - continue; - } - final String categoryName = group.getName(); - final Key breakpointCategory = BreakpointCategory.lookup(categoryName); - final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); - final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); - setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); - Element anyExceptionBreakpointGroup; - if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { - // for compatibility with previous format - anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); - //final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); - //if (factory != null) { - for (Element breakpointNode : group.getChildren("breakpoint")) { - //Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); - Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode); - breakpoint.readExternal(breakpointNode); - nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); - } - //} - } - else { - anyExceptionBreakpointGroup = group; - } + ApplicationManager.getApplication().runReadAction(() -> { + final Map nameToBreakpointMap = new THashMap<>(); + try { + final List groups = parentNode.getChildren(); + for (final Object group1 : groups) { + final Element group = (Element)group1; + if (group.getName().equals(RULES_GROUP_NAME)) { + continue; + } + // skip already converted + if (group.getAttribute(CONVERTED_PARAM) != null) { + continue; + } + final String categoryName = group.getName(); + final Key breakpointCategory = BreakpointCategory.lookup(categoryName); + final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); + final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); + setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); + Element anyExceptionBreakpointGroup; + if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { + // for compatibility with previous format + anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); + //final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); + //if (factory != null) { + for (Element breakpointNode : group.getChildren("breakpoint")) { + //Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); + Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode); + breakpoint.readExternal(breakpointNode); + nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); + } + //} + } + else { + anyExceptionBreakpointGroup = group; + } - if (anyExceptionBreakpointGroup != null) { - final Element breakpointElement = group.getChild("breakpoint"); - if (breakpointElement != null) { - XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); - JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); - XBreakpoint xBreakpoint = manager.getDefaultBreakpoint(type); - Breakpoint breakpoint = getJavaBreakpoint(xBreakpoint); - if (breakpoint != null) { - breakpoint.readExternal(breakpointElement); - addBreakpoint(breakpoint); - } + if (anyExceptionBreakpointGroup != null) { + final Element breakpointElement = group.getChild("breakpoint"); + if (breakpointElement != null) { + XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); + XBreakpoint xBreakpoint = manager.getDefaultBreakpoint(type); + Breakpoint breakpoint = getJavaBreakpoint(xBreakpoint); + if (breakpoint != null) { + breakpoint.readExternal(breakpointElement); + addBreakpoint(breakpoint); } } } } - catch (InvalidDataException ignored) { - } - - final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); - if (rulesGroup != null) { - final List rules = rulesGroup.getChildren("rule"); - for (Element rule : rules) { - // skip already converted - if (rule.getAttribute(CONVERTED_PARAM) != null) { - continue; - } - final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME); - if (master == null) { - continue; - } - final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME); - if (slave == null) { - continue; - } - final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); - if (masterBreakpoint == null) { - continue; - } - final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); - if (slaveBreakpoint == null) { - continue; - } - - boolean leaveEnabled = "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")); - XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); - dependentBreakpointManager.setMasterBreakpoint(slaveBreakpoint.myXBreakpoint, masterBreakpoint.myXBreakpoint, leaveEnabled); - //addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, leaveEnabled)); - } - } - - DebuggerInvocationUtil.invokeLater(myProject, BreakpointManager.this::updateBreakpointsUI); } + catch (InvalidDataException ignored) { + } + + final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); + if (rulesGroup != null) { + final List rules = rulesGroup.getChildren("rule"); + for (Element rule : rules) { + // skip already converted + if (rule.getAttribute(CONVERTED_PARAM) != null) { + continue; + } + final Element master = rule.getChild(MASTER_BREAKPOINT_TAG_NAME); + if (master == null) { + continue; + } + final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAG_NAME); + if (slave == null) { + continue; + } + final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); + if (masterBreakpoint == null) { + continue; + } + final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); + if (slaveBreakpoint == null) { + continue; + } + + boolean leaveEnabled = "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")); + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); + dependentBreakpointManager.setMasterBreakpoint(slaveBreakpoint.myXBreakpoint, masterBreakpoint.myXBreakpoint, leaveEnabled); + //addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, leaveEnabled)); + } + } + + DebuggerInvocationUtil.invokeLater(myProject, this::updateBreakpointsUI); }); myUIProperties.clear(); @@ -462,12 +445,7 @@ public class BreakpointManager { private > XBreakpoint createXBreakpoint(Class> typeCls) { final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); - return ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public XBreakpoint compute() { - return XDebuggerManager.getInstance(myProject).getBreakpointManager().addBreakpoint((XBreakpointType)type, type.createProperties()); - } - }); + return ApplicationManager.getApplication().runWriteAction((Computable)() -> XDebuggerManager.getInstance(myProject).getBreakpointManager().addBreakpoint((XBreakpointType)type, type.createProperties())); } private > XLineBreakpoint createXLineBreakpoint(Class> typeCls, @@ -503,11 +481,8 @@ public class BreakpointManager { if (breakpoint == null) { return; } - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint); - } + ApplicationManager.getApplication().runWriteAction(() -> { + getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint); }); } @@ -523,17 +498,12 @@ public class BreakpointManager { @NotNull public List getBreakpoints() { - return ApplicationManager.getApplication().runReadAction(new Computable>() { + return ApplicationManager.getApplication().runReadAction((Computable>)() -> ContainerUtil.mapNotNull(getXBreakpointManager().getAllBreakpoints(), new Function, Breakpoint>() { @Override - public List compute() { - return ContainerUtil.mapNotNull(getXBreakpointManager().getAllBreakpoints(), new Function, Breakpoint>() { - @Override - public Breakpoint fun(XBreakpoint xBreakpoint) { - return getJavaBreakpoint(xBreakpoint); - } - }); + public Breakpoint fun(XBreakpoint xBreakpoint) { + return getJavaBreakpoint(xBreakpoint); } - }); + })); } @Nullable diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/DebugProcessImpl.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/DebugProcessImpl.kt index 0256aeecb147..53e0bee87b67 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/DebugProcessImpl.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/DebugProcessImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.debugger import com.intellij.execution.ExecutionResult import com.intellij.execution.process.ProcessHandler +import com.intellij.openapi.application.runReadAction import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.Url import com.intellij.util.containers.ContainerUtil @@ -24,6 +25,7 @@ import com.intellij.util.io.socketConnection.ConnectionStatus import com.intellij.xdebugger.DefaultDebugProcessHandler import com.intellij.xdebugger.XDebugProcess import com.intellij.xdebugger.XDebugSession +import com.intellij.xdebugger.XDebuggerManager import com.intellij.xdebugger.breakpoints.XBreakpointHandler import com.intellij.xdebugger.breakpoints.XBreakpointType import com.intellij.xdebugger.breakpoints.XLineBreakpoint @@ -184,29 +186,60 @@ abstract class DebugProcessImpl>(session: XDebugSession, override fun checkCanInitBreakpoints(): Boolean { if (connection.state.status == ConnectionStatus.CONNECTED) { // breakpointsInitiated could be set in another thread and at this point work (init breakpoints) could be not yet performed - return setBreakpoints(false) + return initBreakpoints(false) } if (connectedListenerAdded.compareAndSet(false, true)) { connection.stateChanged { if (it.status == ConnectionStatus.CONNECTED) { - setBreakpoints(true) + initBreakpoints(true) } } } return false } - open protected fun setBreakpoints(setBreakpoints: Boolean): Boolean { - return breakpointsInitiated.compareAndSet(false, true) + protected fun initBreakpoints(setBreakpoints: Boolean): Boolean { + if (breakpointsInitiated.compareAndSet(false, true)) { + doInitBreakpoints(setBreakpoints) + return true + } + else { + return false + } + } + + protected open fun doInitBreakpoints(setBreakpoints: Boolean) { + if (setBreakpoints) { + beforeInitBreakpoints(vm!!) + runReadAction { session.initBreakpoints() } + } + } + + protected open fun beforeInitBreakpoints(vm: Vm) { + } + + protected fun addChildVm(vm: Vm) { + beforeInitBreakpoints(vm) + + val breakpointManager = XDebuggerManager.getInstance(session.project).breakpointManager + @Suppress("UNCHECKED_CAST") + for (breakpointHandler in breakpointHandlers) { + if (breakpointHandler is LineBreakpointHandler) { + val breakpoints = runReadAction { breakpointManager.getBreakpoints(breakpointHandler.breakpointTypeClass) } + for (breakpoint in breakpoints) { + breakpointHandler.manager.setBreakpoint(vm, breakpoint) + } + } + } } } @Suppress("UNCHECKED_CAST") -class LineBreakpointHandler(breakpointTypeClass: Class, *>>, private val manager: LineBreakpointManager) +class LineBreakpointHandler(breakpointTypeClass: Class, *>>, internal val manager: LineBreakpointManager) : XBreakpointHandler>(breakpointTypeClass as Class, *>>) { override fun registerBreakpoint(breakpoint: XLineBreakpoint<*>) { - manager.setBreakpoint(breakpoint) + manager.setBreakpoint(manager.debugProcess.vm!!, breakpoint) } override fun unregisterBreakpoint(breakpoint: XLineBreakpoint<*>, temporary: Boolean) { diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/LineBreakpointManager.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/LineBreakpointManager.kt index 99aa12ce5c42..405d3d82830f 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/LineBreakpointManager.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/LineBreakpointManager.kt @@ -28,38 +28,36 @@ import org.jetbrains.concurrency.Promise import org.jetbrains.concurrency.resolvedPromise import java.util.concurrent.atomic.AtomicBoolean -abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl<*>) { +abstract class LineBreakpointManager(internal val debugProcess: DebugProcessImpl<*>) { private val ideToVmBreakpoints = THashMap, MutableList>() protected val vmToIdeBreakpoints = THashMap>>() private val runToLocationBreakpoints = THashSet() private val lock = Object() - private val breakpointManager: BreakpointManager - get() = debugProcess.vm!!.breakpointManager - open fun isAnyFirstLineBreakpoint(breakpoint: Breakpoint) = false private val breakpointResolvedListenerAdded = AtomicBoolean() - fun setBreakpoint(breakpoint: XLineBreakpoint<*>) { + fun setBreakpoint(vm: Vm, breakpoint: XLineBreakpoint<*>) { val target = synchronized (lock) { ideToVmBreakpoints[breakpoint] } if (target == null) { - setBreakpoint(breakpoint, debugProcess.getLocationsForBreakpoint(breakpoint)) + setBreakpoint(vm, breakpoint, debugProcess.getLocationsForBreakpoint(breakpoint)) } else { - val breakpointManager = breakpointManager + val breakpointManager = vm.breakpointManager for (vmBreakpoint in target) { if (!vmBreakpoint.enabled) { vmBreakpoint.enabled = true - breakpointManager.flush(vmBreakpoint).rejected { debugProcess.session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, it.message) } + breakpointManager.flush(vmBreakpoint) + .rejected { debugProcess.session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, it.message) } } } } } fun removeBreakpoint(breakpoint: XLineBreakpoint<*>, temporary: Boolean): Promise<*> { - val disable = temporary && breakpointManager.getMuteMode() !== BreakpointManager.MUTE_MODE.NONE + val disable = temporary && debugProcess.vm!!.breakpointManager.getMuteMode() !== BreakpointManager.MUTE_MODE.NONE beforeBreakpointRemoved(breakpoint, disable) return doRemoveBreakpoint(breakpoint, disable) } @@ -100,7 +98,7 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< return resolvedPromise() } - val breakpointManager = breakpointManager + val breakpointManager = debugProcess.vm!!.breakpointManager val promises = SmartList>() if (disable) { for (vmBreakpoint in vmBreakpoints) { @@ -116,14 +114,14 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< return Promise.all(promises) } - fun setBreakpoint(breakpoint: XLineBreakpoint<*>, locations: List, promiseRef: Ref>? = null) { + fun setBreakpoint(vm: Vm, breakpoint: XLineBreakpoint<*>, locations: List, promiseRef: Ref>? = null) { if (locations.isEmpty()) { return } val vmBreakpoints = SmartList() for (location in locations) { - doSetBreakpoint(breakpoint, location, false, promiseRef)?.let { vmBreakpoints.add(it) } + doSetBreakpoint(vm, breakpoint, location, false, promiseRef)?.let { vmBreakpoints.add(it) } } synchronized (lock) { ideToVmBreakpoints.put(breakpoint, vmBreakpoints) @@ -133,9 +131,9 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< } } - protected fun doSetBreakpoint(breakpoint: XLineBreakpoint<*>?, location: Location, isTemporary: Boolean, promiseRef: Ref>? = null): Breakpoint? { + protected fun doSetBreakpoint(vm: Vm, breakpoint: XLineBreakpoint<*>?, location: Location, isTemporary: Boolean, promiseRef: Ref>? = null): Breakpoint? { if (breakpointResolvedListenerAdded.compareAndSet(false, true)) { - breakpointManager.addBreakpointListener(object : BreakpointListener { + vm.breakpointManager.addBreakpointListener(object : BreakpointListener { override fun resolved(breakpoint: Breakpoint) { synchronized (lock) { vmToIdeBreakpoints[breakpoint] }?.let { for (ideBreakpoint in it) { @@ -173,7 +171,7 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< } ?.let { for (ideBreakpoint in it) { - setBreakpoint(ideBreakpoint, debugProcess.getLocationsForBreakpoint(ideBreakpoint)) + setBreakpoint(vm, ideBreakpoint, debugProcess.getLocationsForBreakpoint(ideBreakpoint)) } } } @@ -217,20 +215,20 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< var array = synchronized (lock) { ideToVmBreakpoints.keys.toTypedArray() } for (breakpoint in array) { removeBreakpoint(breakpoint, false) - setBreakpoint(breakpoint) + debugProcess.vm?.let { setBreakpoint(it, breakpoint) } } } - fun removeAllBreakpoints(): org.jetbrains.concurrency.Promise<*> { + fun removeAllBreakpoints(): Promise<*> { synchronized (lock) { ideToVmBreakpoints.clear() vmToIdeBreakpoints.clear() runToLocationBreakpoints.clear() } - return breakpointManager.removeAll() + return debugProcess.vm!!.breakpointManager.removeAll() } - fun clearRunToLocationBreakpoints() { + fun clearRunToLocationBreakpoints(vm: Vm) { var breakpoints = synchronized (lock) { if (runToLocationBreakpoints.isEmpty) { return@clearRunToLocationBreakpoints @@ -240,7 +238,7 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< breakpoints } - val breakpointManager = breakpointManager + val breakpointManager = vm.breakpointManager for (breakpoint in breakpoints) { breakpointManager.remove(breakpoint) } diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt index 7c416c9af9ac..2c7204c8817f 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt @@ -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. @@ -36,20 +36,23 @@ import java.net.InetSocketAddress import java.util.concurrent.atomic.AtomicReference abstract class RemoteVmConnection : VmConnection() { + var port = -1 + private val connectCancelHandler = AtomicReference<() -> Unit>() abstract fun createBootstrap(address: InetSocketAddress, vmResult: org.jetbrains.concurrency.AsyncPromise): Bootstrap @JvmOverloads - fun open(address: InetSocketAddress, stopCondition: Condition? = null) { - setState(ConnectionStatus.WAITING_FOR_CONNECTION, "Connecting to ${address.hostName}:${address.port}") + fun open(address: InetSocketAddress, stopCondition: Condition? = null): Promise { + port = address.port + setState(ConnectionStatus.WAITING_FOR_CONNECTION, "Connecting to ${address.hostName}:${port}") + val result = AsyncPromise() val future = ApplicationManager.getApplication().executeOnPooledThread { if (Thread.interrupted()) { return@executeOnPooledThread } - val result = AsyncPromise() - connectCancelHandler.set({ result.setError("Closed explicitly") }) + connectCancelHandler.set { result.setError("Closed explicitly") } val connectionPromise = AsyncPromise() connectionPromise.rejected { result.setError(it) } @@ -70,7 +73,16 @@ abstract class RemoteVmConnection : VmConnection() { createBootstrap(address, result).connect(address, connectionPromise, maxAttemptCount = if (stopCondition == null) NettyUtil.DEFAULT_CONNECT_ATTEMPT_COUNT else -1, stopCondition = stopCondition) } - connectCancelHandler.set { future.cancel(true) } + + connectCancelHandler.set { + try { + future.cancel(true) + } + finally { + result.setError("Cancelled") + } + } + return result } protected open fun connectedAddressToPresentation(address: InetSocketAddress, vm: Vm): String = "${address.hostName}:${address.port}" diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index adee765833e3..c35e2c225079 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -548,7 +548,6 @@ js.debugger.name.mappings.by.source.code=false js.debugger.v8.log= js.debugger.wip.log= js.debugger.member.filter.prefer.vm.source=false -js.debugger.slave.node.as.thread=false js.index.node.submodules=false