From 0a42be5bfe9dccc0354266b24b8602a397ce2773 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 22 Feb 2016 12:48:26 +0100 Subject: [PATCH] init debug NodeJs child processes as threads --- platform/built-in-server/src/net.kt | 7 ---- .../src/com/intellij/util/net/net.kt | 22 +++++++++++++ ...t.java => ScriptRegExpBreakpointTarget.kt} | 0 .../jetbrains/debugger/DebugProcessImpl.kt | 33 +++++++++++++++++-- .../debugger/LineBreakpointManager.kt | 4 +-- .../util/resources/misc/registry.properties | 1 + 6 files changed, 55 insertions(+), 12 deletions(-) delete mode 100644 platform/built-in-server/src/net.kt create mode 100644 platform/platform-impl/src/com/intellij/util/net/net.kt rename platform/script-debugger/backend/src/org/jetbrains/debugger/{ScriptRegExpBreakpointTarget.java => ScriptRegExpBreakpointTarget.kt} (100%) diff --git a/platform/built-in-server/src/net.kt b/platform/built-in-server/src/net.kt deleted file mode 100644 index 64cbc78e096c..000000000000 --- a/platform/built-in-server/src/net.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.intellij.util.net - -import java.net.InetAddress -import java.net.InetSocketAddress - -@JvmOverloads -fun loopbackSocketAddress(port: Int = -1) = InetSocketAddress(InetAddress.getLoopbackAddress(), if (port == -1) NetUtils.findAvailableSocketPort() else port) \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/util/net/net.kt b/platform/platform-impl/src/com/intellij/util/net/net.kt new file mode 100644 index 000000000000..72590470d044 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/util/net/net.kt @@ -0,0 +1,22 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.net + +import java.net.InetAddress +import java.net.InetSocketAddress + +@JvmOverloads +fun loopbackSocketAddress(port: Int = -1) = InetSocketAddress(InetAddress.getLoopbackAddress(), if (port == -1) NetUtils.findAvailableSocketPort() else port) \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptRegExpBreakpointTarget.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptRegExpBreakpointTarget.kt similarity index 100% rename from platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptRegExpBreakpointTarget.java rename to platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptRegExpBreakpointTarget.kt 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 7978189bbdbd..0256aeecb147 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 @@ -24,7 +24,9 @@ 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.breakpoints.* +import com.intellij.xdebugger.breakpoints.XBreakpointHandler +import com.intellij.xdebugger.breakpoints.XBreakpointType +import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider import com.intellij.xdebugger.stepping.XSmartStepIntoHandler import org.jetbrains.concurrency.Promise @@ -47,6 +49,9 @@ abstract class DebugProcessImpl>(session: XDebugSession, var processBreakpointConditionsAtIdeSide: Boolean = false + private val connectedListenerAdded = AtomicBoolean() + private val breakpointsInitiated = AtomicBoolean() + private val _breakpointHandlers: Array> by lazy(LazyThreadSafetyMode.NONE) { createBreakpointHandlers() } init { @@ -174,10 +179,32 @@ abstract class DebugProcessImpl>(session: XDebugSession, open fun getLocationsForBreakpoint(breakpoint: XLineBreakpoint<*>): List = throw UnsupportedOperationException() override fun isLibraryFrameFilterSupported() = true + + // todo make final (go plugin compatibility) + 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) + } + + if (connectedListenerAdded.compareAndSet(false, true)) { + connection.stateChanged { + if (it.status == ConnectionStatus.CONNECTED) { + setBreakpoints(true) + } + } + } + return false + } + + open protected fun setBreakpoints(setBreakpoints: Boolean): Boolean { + return breakpointsInitiated.compareAndSet(false, true) + } } -class LineBreakpointHandler(breakpointTypeClass: Class>, private val manager: LineBreakpointManager) - : XBreakpointHandler>(breakpointTypeClass as Class, out XBreakpointProperties<*>>>) { +@Suppress("UNCHECKED_CAST") +class LineBreakpointHandler(breakpointTypeClass: Class, *>>, private val manager: LineBreakpointManager) + : XBreakpointHandler>(breakpointTypeClass as Class, *>>) { override fun registerBreakpoint(breakpoint: XLineBreakpoint<*>) { manager.setBreakpoint(breakpoint) } 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 344444e70b15..99aa12ce5c42 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 @@ -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. @@ -43,7 +43,7 @@ abstract class LineBreakpointManager(private val debugProcess: DebugProcessImpl< private val breakpointResolvedListenerAdded = AtomicBoolean() fun setBreakpoint(breakpoint: XLineBreakpoint<*>) { - var target = synchronized (lock) { ideToVmBreakpoints[breakpoint] } + val target = synchronized (lock) { ideToVmBreakpoints[breakpoint] } if (target == null) { setBreakpoint(breakpoint, debugProcess.getLocationsForBreakpoint(breakpoint)) } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index c35e2c225079..adee765833e3 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -548,6 +548,7 @@ 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