From 0df0f8e50748d0937f7a22a8ccee1e30c3bf85cf Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Thu, 15 Oct 2020 14:45:31 +0300 Subject: [PATCH] [debugger] merged `stashAndReattach` and `reattach` functions into one `reattach(keepCurrentVM)` GitOrigin-RevId: 27db572b02c73500fcf85ae05ffc978f358e8958 --- .../debugger/engine/DebugProcessImpl.java | 55 +++++++------------ .../JavaTestFrameworkDebuggerRunner.java | 2 +- .../execution/ForkedDebuggerThread.java | 2 +- 3 files changed, 23 insertions(+), 36 deletions(-) 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 498bf872d74e..57a8d4f7cfbc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -91,7 +91,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import static com.intellij.execution.configurations.RemoteConnection.*; +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); @@ -930,12 +930,6 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } } - protected void stashProcess(boolean closedByUser) { - detachProcess(closedByUser, vmData -> { - myStashedVirtualMachines.addFirst(vmData); - }); - } - protected void closeProcess(boolean closedByUser) { detachProcess(closedByUser, vmData -> { //if (DebuggerSettings.getInstance().UNMUTE_ON_STOP) { @@ -2024,27 +2018,32 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } public void reattach(final DebugEnvironment environment) { - reattach(environment, () -> {}); + reattach(environment, false, () -> {}); } - public void reattach(final DebugEnvironment environment, Runnable vmReadyCallback) { - reattach(environment, ReattachType.SEQUENCE, vmReadyCallback); - } - - public void stashAndReattach(final DebugEnvironment environment, Runnable vmReadyCallback) { - reattach(environment, ReattachType.STASH, vmReadyCallback); + public void reattach(final DebugEnvironment environment, boolean keepCurrentVM, Runnable vmReadyCallback) { + reattach(environment, () -> { + if (keepCurrentVM) { + detachProcess(false, vmData -> { + myStashedVirtualMachines.addFirst(vmData); + }); + } else { + closeProcess(false); + } + }, vmReadyCallback); } private void unstashAndReattach() { VirtualMachineData vmData = myStashedVirtualMachines.pollFirst(); if (vmData != null && vmData.vm != null) { - reattach(vmData.connection, ReattachType.UNSTASH, () -> { + reattach(vmData.connection, () -> {}, () -> { afterProcessStarted(() -> getManagerThread().schedule(new DebuggerCommandImpl() { @Override protected void action() { try { commitVM(vmData.vm.getVirtualMachine()); - } catch (VMDisconnectedException e) { + } + catch (VMDisconnectedException e) { fail(); } } @@ -2053,29 +2052,21 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } } - private void reattach(DebugEnvironment environment, ReattachType type, Runnable vmReadyCallback) { - reattach(environment.getRemoteConnection(), type, () -> { + private void reattach(DebugEnvironment environment, Runnable detachVm, Runnable vmReadyCallback) { + reattach(environment.getRemoteConnection(), detachVm, () -> { createVirtualMachine(environment); vmReadyCallback.run(); }); } - private void reattach(RemoteConnection connection, ReattachType type, Runnable attachVm) { + private void reattach(RemoteConnection connection, Runnable detachVm, Runnable attachVm) { if (!myIsStopped.get()) { getManagerThread().schedule(new DebuggerCommandImpl() { @Override protected void action() { - if (!myConnection.getConnectionMode().equals(ConnectionMode.FAKE_SERVER)) { - switch (type) { - case SEQUENCE: - closeProcess(false); - break; - case STASH: - stashProcess(false); - break; - case UNSTASH: - break; - } + ConnectionMode connectionMode = myConnection.getConnectionMode(); + if (!ConnectionMode.FAKE_SERVER.equals(connectionMode)) { + detachVm.run(); } getManagerThread().processRemaining(); doReattach(); @@ -2453,10 +2444,6 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } } - private enum ReattachType { - SEQUENCE, STASH, UNSTASH - } - private static class VirtualMachineData { public final VirtualMachineProxyImpl vm; public final RemoteConnection connection; diff --git a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkDebuggerRunner.java b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkDebuggerRunner.java index 13332fcc389e..c5eebda0e16b 100644 --- a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkDebuggerRunner.java +++ b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkDebuggerRunner.java @@ -56,7 +56,7 @@ public abstract class JavaTestFrameworkDebuggerRunner extends GenericDebuggerRun if (process == null) break; final RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(read), true); final DebugEnvironment env = new DefaultDebugEnvironment(environment, state, connection, true); - ((DebugProcessImpl)process).reattach(env, () -> { + ((DebugProcessImpl)process).reattach(env, false, () -> { try { accept.getOutputStream().write(0); } diff --git a/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ForkedDebuggerThread.java b/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ForkedDebuggerThread.java index 0745ff8fefd0..54f40053feb9 100644 --- a/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ForkedDebuggerThread.java +++ b/java/execution/impl/src/com/intellij/openapi/externalSystem/service/execution/ForkedDebuggerThread.java @@ -213,7 +213,7 @@ class ForkedDebuggerThread extends Thread { RemoteConnection connection = runConfiguration.createRemoteConnection(); DebugEnvironment environment = new DefaultDebugEnvironment(myMainExecutionEnvironment, myMainRunnableState, connection, true); ApplicationManager.getApplication().invokeAndWait(() -> { - ((DebugProcessImpl)debugProcess).stashAndReattach(environment, () -> callback.accept(debugProcess)); + ((DebugProcessImpl)debugProcess).reattach(environment, true, () -> callback.accept(debugProcess)); }); } }