Search in sources :

Example 1 with DefaultDebugEnvironment

use of com.intellij.debugger.DefaultDebugEnvironment in project intellij-community by JetBrains.

the class GenericDebuggerRunner method attachVirtualMachine.

@Nullable
protected RunContentDescriptor attachVirtualMachine(RunProfileState state, @NotNull ExecutionEnvironment env, RemoteConnection connection, long pollTimeout) throws ExecutionException {
    DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollTimeout);
    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
    if (debuggerSession == null) {
        return null;
    }
    final DebugProcessImpl debugProcess = debuggerSession.getProcess();
    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());
            }
            return JavaDebugProcess.create(session, debuggerSession);
        }
    }).getRunContentDescriptor();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ExecutionResult(com.intellij.execution.ExecutionResult) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment) NotNull(org.jetbrains.annotations.NotNull) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DefaultDebugEnvironment

use of com.intellij.debugger.DefaultDebugEnvironment in project buck by facebook.

the class TestExecutionState method attachDebugger.

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);
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) RemoteStateState(com.intellij.debugger.engine.RemoteStateState) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment)

Example 3 with DefaultDebugEnvironment

use of com.intellij.debugger.DefaultDebugEnvironment in project intellij-community by JetBrains.

the class JavaTestFrameworkDebuggerRunner method createContentDescriptor.

@Nullable
@Override
protected RunContentDescriptor createContentDescriptor(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    final RunContentDescriptor res = super.createContentDescriptor(state, environment);
    final ServerSocket socket = ((JavaTestFrameworkRunnableState) state).getForkSocket();
    if (socket != null) {
        Thread thread = new Thread(getThreadName() + " debugger runner") {

            @Override
            public void run() {
                try {
                    final Socket accept = socket.accept();
                    try {
                        DataInputStream stream = new DataInputStream(accept.getInputStream());
                        try {
                            int read = stream.readInt();
                            while (read != -1) {
                                final DebugProcess process = DebuggerManager.getInstance(environment.getProject()).getDebugProcess(res.getProcessHandler());
                                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);
                                SwingUtilities.invokeLater(() -> {
                                    try {
                                        ((DebugProcessImpl) process).reattach(env);
                                        accept.getOutputStream().write(0);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                });
                                read = stream.readInt();
                            }
                        } finally {
                            stream.close();
                        }
                    } finally {
                        accept.close();
                    }
                } catch (EOFException ignored) {
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
    return res;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaTestFrameworkRunnableState(com.intellij.execution.JavaTestFrameworkRunnableState) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) EOFException(java.io.EOFException) DebugProcess(com.intellij.debugger.engine.DebugProcess) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) EOFException(java.io.EOFException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DebugEnvironment (com.intellij.debugger.DebugEnvironment)3 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)3 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 ExecutionException (com.intellij.execution.ExecutionException)2 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)2 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)2 XDebugSession (com.intellij.xdebugger.XDebugSession)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 DebugProcess (com.intellij.debugger.engine.DebugProcess)1 RemoteStateState (com.intellij.debugger.engine.RemoteStateState)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 Executor (com.intellij.execution.Executor)1 JavaTestFrameworkRunnableState (com.intellij.execution.JavaTestFrameworkRunnableState)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1