com.intellij.debugger.impl.DebuggerSession Java Examples

The following examples show how to use com.intellij.debugger.impl.DebuggerSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlazeHotSwapManager.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
static HotSwappableDebugSession findHotSwappableBlazeDebuggerSession(Project project) {
  DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
  DebuggerSession session = debuggerManager.getContext().getDebuggerSession();
  if (session == null || !session.isAttached()) {
    return null;
  }
  JavaDebugProcess process = session.getProcess().getXdebugProcess();
  if (process == null) {
    return null;
  }
  ExecutionEnvironment env = ((XDebugSessionImpl) process.getSession()).getExecutionEnvironment();
  if (env == null || ClassFileManifestBuilder.getManifest(env) == null) {
    return null;
  }
  RunProfile runProfile = env.getRunProfile();
  if (!(runProfile instanceof BlazeCommandRunConfiguration)) {
    return null;
  }
  return new HotSwappableDebugSession(session, env, (BlazeCommandRunConfiguration) runProfile);
}
 
Example #2
Source File: BlazeHotSwapManager.java    From intellij with Apache License 2.0 5 votes vote down vote up
HotSwappableDebugSession(
    DebuggerSession session,
    ExecutionEnvironment env,
    BlazeCommandRunConfiguration blazeRunConfig) {
  this.session = session;
  this.env = env;
  this.blazeRunConfig = blazeRunConfig;
}
 
Example #3
Source File: BlazeHotSwapManager.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void processException(
    Throwable e, DebuggerSession session, HotSwapProgress progress) {
  if (e.getMessage() != null) {
    progress.addMessage(session, MessageCategory.ERROR, e.getMessage());
  }
  if (e instanceof ProcessCanceledException) {
    progress.addMessage(
        session, MessageCategory.INFORMATION, DebuggerBundle.message("error.operation.canceled"));
  } else {
    logger.warn(e);
    progress.addMessage(session, MessageCategory.ERROR, "Error reloading classes");
  }
}
 
Example #4
Source File: MultiRunDebuggerSessionListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionCreated(DebuggerSession session) {
  if (reattachingListener != null) {
    return;
  }
  reattachingListener = new ReattachJvmProcessListener(debugEnvironment, executionEnvironment);
  session.getProcess().addDebugProcessListener(reattachingListener);
}
 
Example #5
Source File: MultiRunDebuggerSessionListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionRemoved(DebuggerSession session) {
  if (reattachingListener != null) {
    session.getProcess().removeDebugProcessListener(reattachingListener);
    reattachingListener = null;
  }
  stopListening();
}
 
Example #6
Source File: RoboVmRunner.java    From robovm-idea with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
                                                    @NotNull ExecutionEnvironment env,
                                                    RemoteConnection connection,
                                                    boolean pollConnection) throws ExecutionException {
    DebugEnvironment environment = new DefaultDebugUIEnvironment(env, state, connection, pollConnection).getEnvironment();
    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
    if (debuggerSession == null) {
        return null;
    }

    final DebugProcessImpl debugProcess = debuggerSession.getProcess();
    if (debugProcess.isDetached() || debugProcess.isDetaching()) {
        debuggerSession.dispose();
        return null;
    }
    // optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
    // which is an expensive operation when executed first time
    debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);

    return 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());
                sessionImpl.addExtraStopActions(((DefaultExecutionResult)executionResult).getAdditionalStopActions());
            }
            return JavaDebugProcess.create(session, debuggerSession);
        }
    }).getRunContentDescriptor();
}
 
Example #7
Source File: TestExecutionState.java    From buck with Apache License 2.0 4 votes vote down vote up
private void attachDebugger(String title, String port) {
  final RemoteConnection remoteConnection =
      new RemoteConnection(/* useSockets */ true, "localhost", port, /* serverMode */ false);
  final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
  final String name = title + " debugger (" + port + ")";
  final ConfigurationFactory cfgFactory =
      ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
  RunnerAndConfigurationSettings runSettings =
      RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
  final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
  final ExecutionEnvironment env =
      new ExecutionEnvironmentBuilder(mProject, debugExecutor)
          .runProfile(runSettings.getConfiguration())
          .build();
  final int pollTimeout = 3000;
  final DebugEnvironment environment =
      new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);

  ApplicationManager.getApplication()
      .invokeLater(
          () -> {
            try {
              final DebuggerSession debuggerSession =
                  DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
              if (debuggerSession == null) {
                return;
              }
              XDebuggerManager.getInstance(mProject)
                  .startSessionAndShowTab(
                      name,
                      null,
                      new XDebugProcessStarter() {
                        @Override
                        @NotNull
                        public XDebugProcess start(@NotNull XDebugSession session) {
                          return JavaDebugProcess.create(session, debuggerSession);
                        }
                      });
            } catch (ExecutionException e) {
              LOG.error(
                  "failed to attach to debugger on port "
                      + port
                      + " with polling timeout "
                      + pollTimeout);
            }
          });
}