@Nullable
  protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
                                                      @NotNull ExecutionEnvironment env,
                                                      RemoteConnection connection,
                                                      long pollTimeout) throws ExecutionException {
    DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollTimeout);
    DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
    if (debuggerSession == null) {
      return null;
    }

    AtomicReference<ExecutionException> ex = new AtomicReference<>();
    AtomicReference<RunContentDescriptor> result = new AtomicReference<>();
    ApplicationManager.getApplication().invokeAndWait(() -> {
      try {
        DebugProcessImpl debugProcess = debuggerSession.getProcess();
        result.set(XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
          @Override
          @NotNull
          public XDebugProcess start(@NotNull XDebugSession session) {
            XDebugSessionImpl sessionImpl = (XDebugSessionImpl)session;
            ExecutionResult executionResult = debugProcess.getExecutionResult();
            sessionImpl.addExtraActions(executionResult.getActions());
            if (executionResult instanceof DefaultExecutionResult) {
              sessionImpl.addRestartActions(((DefaultExecutionResult)executionResult).getRestartActions());
            }
            return JavaDebugProcess.create(session, debuggerSession);
          }
        }).getRunContentDescriptor());
      }
      catch (ProcessCanceledException ignored) {
      }
      catch (ExecutionException e) {
        ex.set(e);
      }
    }, ModalityState.any());
    if (ex.get() != null) throw ex.get();
    return result.get();
  }
@Nullable
  protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
                                                      @NotNull ExecutionEnvironment env,
                                                      RemoteConnection connection,
                                                      long pollTimeout)