private void reattach(RemoteConnection connection, Runnable detachVm, Runnable attachVm) {
    if (!myIsStopped.get()) {
      getManagerThread().schedule(new DebuggerCommandImpl() {
        @Override
        protected void action() {
          detachVm.run();
          getManagerThread().processRemaining();
          doReattach();
        }

        @Override
        protected void commandCancelled() {
          doReattach(); // if the original process is already finished
        }

        private void doReattach() {
          DebuggerInvocationUtil.swingInvokeLater(myProject, () -> {
            ((XDebugSessionImpl)getXdebugProcess().getSession()).reset();
            myState.set(State.INITIAL);
            myConnection = connection;
            getManagerThread().restartIfNeeded();
            attachVm.run();
          });
        }
      });
    }
  }
private void reattach(RemoteConnection connection, Runnable detachVm, Runnable attachVm)