[debugger] added stub debugger remote connection

GitOrigin-RevId: d1b3f67fd880540a4e2a65e2694b270ec92e42a8
This commit is contained in:
Sergei Vorobyov
2020-10-19 15:48:09 +00:00
committed by intellij-monorepo-bot
parent 0df0f8e507
commit c84e71cbc5
7 changed files with 58 additions and 49 deletions
@@ -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);
}
@@ -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)
@@ -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 {
@@ -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();
}
@@ -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
@@ -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);
@@ -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=<y/n>";
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}
}