Search in sources :

Example 1 with DebugEnvironment

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

the class DebuggerPanelsManager method attachVirtualMachine.

@Nullable
public RunContentDescriptor attachVirtualMachine(DebugUIEnvironment environment) throws ExecutionException {
    final DebugEnvironment modelEnvironment = environment.getEnvironment();
    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(myProject).attachVirtualMachine(modelEnvironment);
    if (debuggerSession == null) {
        return null;
    }
    XDebugSession debugSession = XDebuggerManager.getInstance(myProject).startSessionAndShowTab(modelEnvironment.getSessionName(), environment.getReuseContent(), new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull XDebugSession session) {
            return JavaDebugProcess.create(session, debuggerSession);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DebugEnvironment(com.intellij.debugger.DebugEnvironment) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DebugEnvironment

use of com.intellij.debugger.DebugEnvironment 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 3 with DebugEnvironment

use of com.intellij.debugger.DebugEnvironment 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 4 with DebugEnvironment

use of com.intellij.debugger.DebugEnvironment 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)

Example 5 with DebugEnvironment

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

the class JavaDebuggerLauncherImpl method startDebugSession.

@Override
public void startDebugSession(@NotNull JavaDebugConnectionData info, @NotNull ExecutionEnvironment executionEnvironment, @NotNull RemoteServer<?> server) throws ExecutionException {
    final Project project = executionEnvironment.getProject();
    final DebuggerPanelsManager manager = DebuggerPanelsManager.getInstance(project);
    final JavaDebugServerModeHandler serverModeHandler = info.getServerModeHandler();
    boolean serverMode = serverModeHandler != null;
    final RemoteConnection remoteConnection = new RemoteConnection(true, info.getHost(), String.valueOf(info.getPort()), serverMode);
    DebugEnvironment debugEnvironment = new RemoteServerDebugEnvironment(project, remoteConnection, executionEnvironment.getRunProfile());
    DebugUIEnvironment debugUIEnvironment = new RemoteServerDebugUIEnvironment(debugEnvironment, executionEnvironment);
    RunContentDescriptor debugContentDescriptor = manager.attachVirtualMachine(debugUIEnvironment);
    LOG.assertTrue(debugContentDescriptor != null);
    ProcessHandler processHandler = debugContentDescriptor.getProcessHandler();
    LOG.assertTrue(processHandler != null);
    if (serverMode) {
        serverModeHandler.attachRemote();
        DebuggerManager.getInstance(executionEnvironment.getProject()).addDebugProcessListener(processHandler, new DebugProcessListener() {

            public void processDetached(DebugProcess process, boolean closedByUser) {
                try {
                    serverModeHandler.detachRemote();
                } catch (ExecutionException e) {
                    LOG.info(e);
                }
            }
        });
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaDebugServerModeHandler(com.intellij.remoteServer.runtime.deployment.debug.JavaDebugServerModeHandler) Project(com.intellij.openapi.project.Project) DebugProcess(com.intellij.debugger.engine.DebugProcess) DebugProcessListener(com.intellij.debugger.engine.DebugProcessListener) DebuggerPanelsManager(com.intellij.debugger.ui.DebuggerPanelsManager) RemoteDebugProcessHandler(com.intellij.debugger.engine.RemoteDebugProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionException(com.intellij.execution.ExecutionException) DebugEnvironment(com.intellij.debugger.DebugEnvironment) DebugUIEnvironment(com.intellij.debugger.DebugUIEnvironment)

Aggregations

DebugEnvironment (com.intellij.debugger.DebugEnvironment)5 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)3 ExecutionException (com.intellij.execution.ExecutionException)3 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)3 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)3 XDebugSession (com.intellij.xdebugger.XDebugSession)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 DebugProcess (com.intellij.debugger.engine.DebugProcess)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 XDebugProcess (com.intellij.xdebugger.XDebugProcess)2 DebugUIEnvironment (com.intellij.debugger.DebugUIEnvironment)1 DebugProcessListener (com.intellij.debugger.engine.DebugProcessListener)1 RemoteDebugProcessHandler (com.intellij.debugger.engine.RemoteDebugProcessHandler)1 RemoteStateState (com.intellij.debugger.engine.RemoteStateState)1 DebuggerPanelsManager (com.intellij.debugger.ui.DebuggerPanelsManager)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionResult (com.intellij.execution.ExecutionResult)1