Search in sources :

Example 1 with ExecutionResult

use of com.intellij.execution.ExecutionResult 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 2 with ExecutionResult

use of com.intellij.execution.ExecutionResult in project intellij-community by JetBrains.

the class PyBaseDebuggerTask method finishSession.

protected void finishSession() throws InterruptedException {
    disposeDebugProcess();
    if (mySession != null) {
        new WriteAction() {

            protected void run(@NotNull Result result) throws Throwable {
                mySession.stop();
            }
        }.execute();
        //wait for process termination after session.stop() which is async
        waitFor(mySession.getDebugProcess().getProcessHandler());
        XDebuggerTestUtil.disposeDebugSession(mySession);
        mySession = null;
        myDebugProcess = null;
        myPausedSemaphore = null;
    }
    final ExecutionResult result = myExecutionResult;
    if (myExecutionResult != null) {
        UIUtil.invokeLaterIfNeeded(() -> Disposer.dispose(result.getExecutionConsole()));
        myExecutionResult = null;
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ExecutionResult(com.intellij.execution.ExecutionResult) ExecutionResult(com.intellij.execution.ExecutionResult) Result(com.intellij.openapi.application.Result)

Example 3 with ExecutionResult

use of com.intellij.execution.ExecutionResult 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 4 with ExecutionResult

use of com.intellij.execution.ExecutionResult in project intellij-community by JetBrains.

the class DebuggerSession method attach.

@Nullable
private ExecutionResult attach(DebugEnvironment environment) throws ExecutionException {
    RemoteConnection remoteConnection = environment.getRemoteConnection();
    final String addressDisplayName = DebuggerBundle.getAddressDisplayName(remoteConnection);
    final String transportName = DebuggerBundle.getTransportName(remoteConnection);
    final ExecutionResult executionResult = myDebugProcess.attachVirtualMachine(environment, this);
    getContextManager().setState(SESSION_EMPTY_CONTEXT, State.WAITING_ATTACH, Event.START_WAIT_ATTACH, DebuggerBundle.message("status.waiting.attach", addressDisplayName, transportName));
    return executionResult;
}
Also used : ExecutionResult(com.intellij.execution.ExecutionResult) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ExecutionResult

use of com.intellij.execution.ExecutionResult 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

ExecutionResult (com.intellij.execution.ExecutionResult)25 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)9 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)6 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)6 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)6 ProcessHandler (com.intellij.execution.process.ProcessHandler)5 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)5 XDebugSession (com.intellij.xdebugger.XDebugSession)5 ExecutionException (com.intellij.execution.ExecutionException)4 Project (com.intellij.openapi.project.Project)3 XDebugProcess (com.intellij.xdebugger.XDebugProcess)3 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)3 JstdBrowserInfo (com.google.jstestdriver.idea.server.JstdBrowserInfo)2 JstdServerLifeCycleAdapter (com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter)2 DebugEnvironment (com.intellij.debugger.DebugEnvironment)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 RunProfile (com.intellij.execution.configurations.RunProfile)2 NopProcessHandler (com.intellij.execution.process.NopProcessHandler)2 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)2