From c84e71cbc588059bb32623ce37538526ea12fe1c Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Thu, 15 Oct 2020 19:41:39 +0300 Subject: [PATCH] [debugger] added stub debugger remote connection GitOrigin-RevId: d1b3f67fd880540a4e2a65e2694b270ec92e42a8 --- .../debugger/engine/DebugProcessImpl.java | 40 +++++++++---------- .../debugger/engine/RemoteConnectionStub.kt | 9 +++++ .../debugger/impl/DebuggerSession.java | 14 ++++--- .../debugger/impl/DebuggerUtilsImpl.java | 12 +++++- .../messages/JavaDebuggerBundle.properties | 3 +- .../ExternalSystemTaskDebugRunner.java | 10 ++--- .../configurations/RemoteConnection.java | 19 ++------- 7 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 java/debugger/impl/src/com/intellij/debugger/engine/RemoteConnectionStub.kt diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index 57a8d4f7cfbc..c951bd854308 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -91,8 +91,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import static com.intellij.execution.configurations.RemoteConnection.ConnectionMode; - public abstract class DebugProcessImpl extends UserDataHolderBase implements DebugProcess { private static final Logger LOG = Logger.getInstance(DebugProcessImpl.class); @@ -912,19 +910,21 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb getManagerThread().close(); } finally { - VirtualMachineData vmData = new VirtualMachineData(myVirtualMachineProxy, myConnection); - myVirtualMachineProxy = null; - myPositionManager = CompoundPositionManager.EMPTY; - myReturnValueWatcher = null; - myNodeRenderersMap.clear(); - myRenderers.clear(); - DebuggerUtils.cleanupAfterProcessFinish(this); - myState.compareAndSet(State.DETACHING, State.DETACHED); - try { - myDebugProcessDispatcher.getMulticaster().processDetached(this, closedByUser); - } - finally { - callback.accept(vmData); + if (!(myConnection instanceof RemoteConnectionStub)) { + VirtualMachineData vmData = new VirtualMachineData(myVirtualMachineProxy, myConnection); + myVirtualMachineProxy = null; + myPositionManager = CompoundPositionManager.EMPTY; + myReturnValueWatcher = null; + myNodeRenderersMap.clear(); + myRenderers.clear(); + DebuggerUtils.cleanupAfterProcessFinish(this); + myState.compareAndSet(State.DETACHING, State.DETACHED); + try { + myDebugProcessDispatcher.getMulticaster().processDetached(this, closedByUser); + } + finally { + callback.accept(vmData); + } } } } @@ -2064,10 +2064,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb getManagerThread().schedule(new DebuggerCommandImpl() { @Override protected void action() { - ConnectionMode connectionMode = myConnection.getConnectionMode(); - if (!ConnectionMode.FAKE_SERVER.equals(connectionMode)) { - detachVm.run(); - } + detachVm.run(); getManagerThread().processRemaining(); doReattach(); } @@ -2102,8 +2099,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb myConnection = environment.getRemoteConnection(); // in client mode start target process before the debugger to reduce polling - ConnectionMode connectionMode = myConnection.getConnectionMode(); - if (connectionMode.equals(ConnectionMode.SERVER)) { + if (!(myConnection instanceof RemoteConnectionStub) && myConnection.isServerMode()) { createVirtualMachine(environment); } @@ -2131,7 +2127,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb throw e; } - if (connectionMode.equals(ConnectionMode.CLIENT)) { + if (!(myConnection instanceof RemoteConnectionStub) && !myConnection.isServerMode()) { createVirtualMachine(environment); } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/RemoteConnectionStub.kt b/java/debugger/impl/src/com/intellij/debugger/engine/RemoteConnectionStub.kt new file mode 100644 index 000000000000..12f8e130d206 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/engine/RemoteConnectionStub.kt @@ -0,0 +1,9 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.debugger.engine + +import com.intellij.execution.configurations.RemoteConnection +import org.jetbrains.annotations.ApiStatus + +@ApiStatus.Internal +class RemoteConnectionStub(useSockets: Boolean, hostName: String, address: String, serverMode: Boolean +) : RemoteConnection(useSockets, hostName, address, serverMode) diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java index 7fed0f28020e..0ecbee4fb328 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java @@ -262,8 +262,7 @@ public final class DebuggerSession implements AbstractDebuggerSession { return JavaDebuggerBundle.message("status.app.running"); case WAITING_ATTACH: RemoteConnection connection = getProcess().getConnection(); - return JavaDebuggerBundle.message(connection.isServerMode() ? "status.listening" : "status.connecting", - DebuggerUtilsImpl.getConnectionDisplayName(connection)); + return DebuggerUtilsImpl.getConnectionWaitStatus(connection); case PAUSED: return JavaDebuggerBundle.message("status.paused"); case WAIT_EVALUATION: @@ -434,10 +433,15 @@ public final class DebuggerSession implements AbstractDebuggerSession { private void attach() throws ExecutionException { RemoteConnection remoteConnection = myDebugEnvironment.getRemoteConnection(); + myDebugProcess.attachVirtualMachine(myDebugEnvironment, this); - getContextManager().setState(SESSION_EMPTY_CONTEXT, State.WAITING_ATTACH, Event.START_WAIT_ATTACH, - JavaDebuggerBundle.message("status.waiting.attach", - DebuggerUtilsImpl.getConnectionDisplayName(remoteConnection))); + + StringBuilder description = new StringBuilder(JavaDebuggerBundle.message("status.waiting.attach")); + if (!(remoteConnection instanceof RemoteConnectionStub)) { + String connectionName = DebuggerUtilsImpl.getConnectionDisplayName(remoteConnection); + description.append("; ").append(JavaDebuggerBundle.message("status.waiting.attach.address", connectionName)); + } + getContextManager().setState(SESSION_EMPTY_CONTEXT, State.WAITING_ATTACH, Event.START_WAIT_ATTACH, description.toString()); } private class MyDebugProcessListener extends DebugProcessAdapterImpl { diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java index a24e43bd9747..59f2b29b1e1d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java @@ -30,6 +30,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.PsiJavaParserFacadeImpl; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.rt.execution.CommandLineWrapper; +import com.intellij.util.ObjectUtils; import com.intellij.util.SmartList; import com.intellij.util.io.URLUtil; import com.intellij.util.net.NetUtils; @@ -241,7 +242,16 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ return defaultValue; } - public static String getConnectionDisplayName(RemoteConnection connection) { + public static @NlsContexts.Label String getConnectionWaitStatus(@NotNull RemoteConnection connection) { + String connectionName = ObjectUtils.doIfNotNull(connection, DebuggerUtilsImpl::getConnectionDisplayName); + return connection instanceof RemoteConnectionStub + ? JavaDebuggerBundle.message("status.waiting.attach") + : connection.isServerMode() + ? JavaDebuggerBundle.message("status.listening", connectionName) + : JavaDebuggerBundle.message("status.connecting", connectionName); + } + + public static String getConnectionDisplayName(@NotNull RemoteConnection connection) { if (connection instanceof PidRemoteConnection) { return "pid " + ((PidRemoteConnection)connection).getPid(); } diff --git a/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties b/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties index 1af5c85f9ae8..f065f44ac726 100644 --- a/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties +++ b/java/debugger/openapi/resources/messages/JavaDebuggerBundle.properties @@ -80,7 +80,8 @@ error.unknown.host=Cannot connect to remote process. Host is unknown error.unknown.host.with.address=Cannot connect to remote process. Host is unknown ({0}) error.cannot.open.debugger.port=Unable to open debugger port error.exception.while.connecting=Error connecting to remote process.\nException occurred: {0}\nException message: {1} -status.waiting.attach=Debugger is waiting for application to start; debug address: {0} +status.waiting.attach=Debugger is waiting for application to start +status.waiting.attach.address=debug address: {0} status.listening=Listening to the connection, address: {0} status.connecting=Connecting to the target VM, address: {0} status.app.running=The application is running diff --git a/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java b/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java index d24d014d2a90..909b823e5f27 100644 --- a/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java +++ b/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java @@ -21,6 +21,7 @@ import com.intellij.debugger.DebuggerManagerEx; import com.intellij.debugger.DefaultDebugEnvironment; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.JavaDebugProcess; +import com.intellij.debugger.engine.RemoteConnectionStub; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.impl.GenericDebuggerRunner; import com.intellij.execution.DefaultExecutionResult; @@ -34,7 +35,6 @@ import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.ui.ExecutionConsole; import com.intellij.execution.ui.RunContentDescriptor; -import com.intellij.ide.ui.EditorOptionsTopHitProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.xdebugger.XDebugProcess; @@ -47,8 +47,6 @@ import org.jetbrains.annotations.Nullable; import java.net.ServerSocket; -import static com.intellij.execution.configurations.RemoteConnection.*; - /** * @author Denis Zhdanov */ @@ -130,8 +128,10 @@ public class ExternalSystemTaskDebugRunner extends GenericDebuggerRunner { private XDebugProcess jvmProcessToDebug(@NotNull XDebugSession session, ExternalSystemRunnableState state, @NotNull ExecutionEnvironment env) throws ExecutionException { - ConnectionMode connectionMode = state.isDebugServerProcess() ? ConnectionMode.SERVER : ConnectionMode.FAKE_SERVER; - RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(state.getDebugPort()), connectionMode); + String debugPort = String.valueOf(state.getDebugPort()); + RemoteConnection connection = state.isDebugServerProcess() + ? new RemoteConnection(true, "127.0.0.1", debugPort, true) + : new RemoteConnectionStub(true, "127.0.0.1", debugPort, true); DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, DebugEnvironment.LOCAL_START_TIMEOUT); final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment); diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/RemoteConnection.java b/java/execution/openapi/src/com/intellij/execution/configurations/RemoteConnection.java index cceb89af202a..094c813b8c6c 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/RemoteConnection.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/RemoteConnection.java @@ -10,7 +10,7 @@ import java.net.UnknownHostException; public class RemoteConnection { private boolean myUseSockets; - private ConnectionMode myConnectionMode; + private boolean myServerMode; private String myApplicationHostName; private String myApplicationAddress; @@ -21,12 +21,8 @@ public class RemoteConnection { public static final String ONUNCAUGHT = ",onuncaught="; public RemoteConnection(boolean useSockets, String hostName, String address, boolean serverMode) { - this(useSockets, hostName, address, serverMode ? ConnectionMode.SERVER : ConnectionMode.CLIENT); - } - - public RemoteConnection(boolean useSockets, String hostName, String address, ConnectionMode connectionMode) { myUseSockets = useSockets; - myConnectionMode = connectionMode; + myServerMode = serverMode; myApplicationHostName = hostName; myDebuggerHostName = hostName; myApplicationAddress = address; @@ -37,13 +33,8 @@ public class RemoteConnection { return myUseSockets; } - public ConnectionMode getConnectionMode() { - return myConnectionMode; - } - public boolean isServerMode() { - return myConnectionMode.equals(ConnectionMode.SERVER) - || myConnectionMode.equals(ConnectionMode.FAKE_SERVER); + return myServerMode; } public void setUseSockets(boolean useSockets) { @@ -51,7 +42,7 @@ public class RemoteConnection { } public void setServerMode(boolean serverMode) { - myConnectionMode = serverMode ? ConnectionMode.SERVER : ConnectionMode.CLIENT; + myServerMode = serverMode; } /** @@ -163,6 +154,4 @@ public class RemoteConnection { } return result; } - - public enum ConnectionMode {SERVER, FAKE_SERVER, CLIENT} }