@Nullable
  public ExecutionResult attachVirtualMachine(@NotNull DebugEnvironment environment,
                                              @NotNull DebuggerSession session) throws ExecutionException {
    mySession = session;
    myWaitFor.down();

    LOG.assertTrue(isInInitialState());

    myConnection = environment.getRemoteConnection();

    // in client mode start target process before the debugger to reduce polling
    if (!(myConnection instanceof RemoteConnectionStub) &&
        !(myConnection instanceof DelayedRemoteConnection) &&
        myConnection.isServerMode()) {
      createVirtualMachine(environment);
      if (myIsFailed.get()) {
        myExecutionResult = null;
        return null;
      }
    }

    ExecutionResult executionResult;
    try {
      synchronized (myProcessListeners) {
        executionResult = environment.createExecutionResult();
        myExecutionResult = executionResult;
        if (executionResult == null) {
          fail();
          return null;
        }
        for (ProcessListener processListener : myProcessListeners) {
          executionResult.getProcessHandler().addProcessListener(processListener);
        }
        myProcessListeners.clear();
        if (!myTextBeforeStart.isEmpty()) {
          printToConsoleImpl(myTextBeforeStart.toString());
          myTextBeforeStart.setLength(0);
        }
      }
    }
    catch (ExecutionException e) {
      fail();
      throw e;
    }

    if (myConnection instanceof DelayedRemoteConnection) {
      ((DelayedRemoteConnection)myConnection).setAttachRunnable(() -> createVirtualMachine(environment));
    }
    else if (!(myConnection instanceof RemoteConnectionStub) && !myConnection.isServerMode()) {
      createVirtualMachine(environment);
      if (myIsFailed.get()) {
        myExecutionResult = null;
        return null;
      }
    }

    return executionResult;
  }
@Nullable
  public ExecutionResult attachVirtualMachine(@NotNull DebugEnvironment environment,
                                              @NotNull DebuggerSession session)