Search in sources :

Example 1 with XDebugProcess

use of com.intellij.xdebugger.XDebugProcess in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method connectToDebugger.

private XDebugSession connectToDebugger() throws ExecutionException {
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
    final XDebugSession session = XDebuggerManager.getInstance(myProject).startSessionAndShowTab("Python Console Debugger", PythonIcons.Python.Python, null, true, new XDebugProcessStarter() {

        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PythonDebugLanguageConsoleView debugConsoleView = new PythonDebugLanguageConsoleView(myProject, mySdk);
            PyConsoleDebugProcessHandler consoleDebugProcessHandler = new PyConsoleDebugProcessHandler(myProcessHandler);
            PyConsoleDebugProcess consoleDebugProcess = new PyConsoleDebugProcess(session, serverSocket, debugConsoleView, consoleDebugProcessHandler);
            PythonDebugConsoleCommunication communication = PyDebugRunner.initDebugConsoleView(myProject, consoleDebugProcess, debugConsoleView, consoleDebugProcessHandler, session);
            communication.addCommunicationListener(new ConsoleCommunicationListener() {

                @Override
                public void commandExecuted(boolean more) {
                    session.rebuildViews();
                }

                @Override
                public void inputRequested() {
                }
            });
            myPydevConsoleCommunication.setDebugCommunication(communication);
            debugConsoleView.attachToProcess(consoleDebugProcessHandler);
            consoleDebugProcess.waitForNextConnection();
            try {
                consoleDebugProcess.connect(myPydevConsoleCommunication);
            } catch (Exception e) {
                //TODO
                LOG.error(e);
            }
            myProcessHandler.notifyTextAvailable("\nDebugger connected.\n", ProcessOutputTypes.STDERR);
            return consoleDebugProcess;
        }
    });
    return session;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConsoleCommunicationListener(com.jetbrains.python.console.pydev.ConsoleCommunicationListener) ServerSocket(java.net.ServerSocket) NotNull(org.jetbrains.annotations.NotNull) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with XDebugProcess

use of com.intellij.xdebugger.XDebugProcess in project intellij-community by JetBrains.

the class PyAttachToProcessDebugRunner method launchRemoteDebugServer.

private XDebugSession launchRemoteDebugServer() throws ExecutionException {
    final ServerSocket serverSocket;
    try {
        //noinspection SocketOpenedButNotSafelyClosed
        serverSocket = new ServerSocket(0);
    } catch (IOException e) {
        throw new ExecutionException("Failed to find free socket port", e);
    }
    PyAttachToProcessCommandLineState state = PyAttachToProcessCommandLineState.create(myProject, mySdkPath, serverSocket.getLocalPort(), myPid);
    final ExecutionResult result = state.execute(state.getEnvironment().getExecutor(), this);
    //start remote debug server
    return XDebuggerManager.getInstance(myProject).startSessionAndShowTab(String.valueOf(myPid), null, new XDebugProcessStarter() {

        @org.jetbrains.annotations.NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PyRemoteDebugProcess pyDebugProcess = new PyRemoteDebugProcess(session, serverSocket, result.getExecutionConsole(), result.getProcessHandler(), "") {

                @Override
                protected void printConsoleInfo() {
                }

                @Override
                protected String getConnectionMessage() {
                    return "Attaching to a process with PID=" + myPid;
                }

                @Override
                protected String getConnectionTitle() {
                    return "Attaching Debugger";
                }
            };
            pyDebugProcess.setPositionConverter(new PyLocalPositionConverter());
            createConsoleCommunicationAndSetupActions(myProject, result, pyDebugProcess, session);
            return pyDebugProcess;
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) ServerSocket(java.net.ServerSocket) ExecutionResult(com.intellij.execution.ExecutionResult) IOException(java.io.IOException) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) PyLocalPositionConverter(com.jetbrains.python.debugger.PyLocalPositionConverter) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) PyRemoteDebugProcess(com.jetbrains.python.debugger.PyRemoteDebugProcess)

Example 3 with XDebugProcess

use of com.intellij.xdebugger.XDebugProcess in project intellij-community by JetBrains.

the class PyDebugRunner method createSession.

protected XDebugSession createSession(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    final PythonCommandLineState pyState = (PythonCommandLineState) state;
    Sdk sdk = pyState.getSdk();
    PyDebugSessionFactory sessionCreator = PyDebugSessionFactory.findExtension(sdk);
    if (sessionCreator != null) {
        return sessionCreator.createSession(pyState, environment);
    }
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
    final int serverLocalPort = serverSocket.getLocalPort();
    RunProfile profile = environment.getRunProfile();
    final ExecutionResult result = pyState.execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, serverLocalPort));
    return XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PyDebugProcess pyDebugProcess = createDebugProcess(session, serverSocket, result, pyState);
            createConsoleCommunicationAndSetupActions(environment.getProject(), result, pyDebugProcess, session);
            return pyDebugProcess;
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) ServerSocket(java.net.ServerSocket) NotNull(org.jetbrains.annotations.NotNull) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 4 with XDebugProcess

use of com.intellij.xdebugger.XDebugProcess 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 5 with XDebugProcess

use of com.intellij.xdebugger.XDebugProcess in project intellij-plugins by JetBrains.

the class DartRunner method doExecuteDartDebug.

private RunContentDescriptor doExecuteDartDebug(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env, @Nullable final String dasExecutionContextId) throws RuntimeConfigurationError, ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    // already checked
    assert (sdk != null);
    final RunProfile runConfiguration = env.getRunProfile();
    final VirtualFile contextFileOrDir;
    VirtualFile currentWorkingDirectory;
    final ExecutionResult executionResult;
    final String debuggingHost;
    final int observatoryPort;
    if (runConfiguration instanceof DartRunConfigurationBase) {
        contextFileOrDir = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().getDartFileOrDirectory();
        final String cwd = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().computeProcessWorkingDirectory(env.getProject());
        currentWorkingDirectory = LocalFileSystem.getInstance().findFileByPath((cwd));
        executionResult = state.execute(env.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        debuggingHost = null;
        observatoryPort = ((DartCommandLineRunningState) state).getObservatoryPort();
    } else if (runConfiguration instanceof DartRemoteDebugConfiguration) {
        final String path = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getDartProjectPath();
        contextFileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (contextFileOrDir == null) {
            throw new RuntimeConfigurationError("Folder not found: " + FileUtil.toSystemDependentName(path));
        }
        currentWorkingDirectory = contextFileOrDir;
        executionResult = null;
        debuggingHost = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getHost();
        observatoryPort = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getPort();
    } else {
        LOG.error("Unexpected run configuration: " + runConfiguration.getClass().getName());
        return null;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    final XDebuggerManager debuggerManager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession debugSession = debuggerManager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            final DartUrlResolver dartUrlResolver = getDartUrlResolver(env.getProject(), contextFileOrDir);
            return new DartVmServiceDebugProcess(session, StringUtil.notNullize(debuggingHost, "localhost"), observatoryPort, executionResult, dartUrlResolver, dasExecutionContextId, runConfiguration instanceof DartRemoteDebugConfiguration, getTimeout(), currentWorkingDirectory);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) NotNull(org.jetbrains.annotations.NotNull) DartVmServiceDebugProcess(com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartRemoteDebugConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Aggregations

XDebugProcess (com.intellij.xdebugger.XDebugProcess)14 XDebugSession (com.intellij.xdebugger.XDebugSession)13 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)12 NotNull (org.jetbrains.annotations.NotNull)12 ExecutionException (com.intellij.execution.ExecutionException)6 ExecutionResult (com.intellij.execution.ExecutionResult)3 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)3 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)3 ServerSocket (java.net.ServerSocket)3 DebugEnvironment (com.intellij.debugger.DebugEnvironment)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 CloudAttachDialog (com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog)1 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)1 JavaDebugProcess (com.intellij.debugger.engine.JavaDebugProcess)1 RemoteStateState (com.intellij.debugger.engine.RemoteStateState)1 Executor (com.intellij.execution.Executor)1 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1