Search in sources :

Example 1 with XDebugSession

use of com.intellij.xdebugger.XDebugSession 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 XDebugSession

use of com.intellij.xdebugger.XDebugSession 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 XDebugSession

use of com.intellij.xdebugger.XDebugSession 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 XDebugSession

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

the class PyDebugRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    XDebugSession session = createSession(state, environment);
    initSession(session, state, environment.getExecutor());
    return session.getRunContentDescriptor();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession)

Example 5 with XDebugSession

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

the class AlternativeSourceNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (!DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE) {
        return null;
    }
    XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
    if (session == null) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    XSourcePosition position = session.getCurrentPosition();
    if (position == null || !file.equals(position.getFile())) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (psiFile == null)
        return null;
    if (!(psiFile instanceof PsiJavaFile))
        return null;
    PsiClass[] classes = ((PsiJavaFile) psiFile).getClasses();
    if (classes.length == 0)
        return null;
    PsiClass baseClass = classes[0];
    String name = baseClass.getQualifiedName();
    if (name == null)
        return null;
    if (DumbService.getInstance(myProject).isDumb())
        return null;
    ArrayList<PsiClass> alts = ContainerUtil.newArrayList(JavaPsiFacade.getInstance(myProject).findClasses(name, GlobalSearchScope.allScope(myProject)));
    ContainerUtil.removeDuplicates(alts);
    FILE_PROCESSED_KEY.set(file, true);
    if (alts.size() > 1) {
        for (PsiClass cls : alts) {
            if (cls.equals(baseClass) || cls.getNavigationElement().equals(baseClass)) {
                alts.remove(cls);
                break;
            }
        }
        alts.add(0, baseClass);
        ComboBoxClassElement[] elems = ContainerUtil.map2Array(alts, ComboBoxClassElement.class, psiClass -> new ComboBoxClassElement((PsiClass) psiClass.getNavigationElement()));
        String locationDeclName = null;
        XStackFrame frame = session.getCurrentStackFrame();
        if (frame instanceof JavaStackFrame) {
            Location location = ((JavaStackFrame) frame).getDescriptor().getLocation();
            if (location != null) {
                locationDeclName = location.declaringType().name();
            }
        }
        return new AlternativeSourceNotificationPanel(elems, baseClass, myProject, file, locationDeclName);
    }
    return null;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XDebugSession (com.intellij.xdebugger.XDebugSession)50 Project (com.intellij.openapi.project.Project)15 NotNull (org.jetbrains.annotations.NotNull)13 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)9 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)9 XDebugProcess (com.intellij.xdebugger.XDebugProcess)8 Nullable (org.jetbrains.annotations.Nullable)7 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)6 IOException (java.io.IOException)5 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)4 ExecutionException (com.intellij.execution.ExecutionException)4 XValueNodeImpl (com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl)4 DebugEnvironment (com.intellij.debugger.DebugEnvironment)3 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)3 ExecutionResult (com.intellij.execution.ExecutionResult)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 XSourcePosition (com.intellij.xdebugger.XSourcePosition)3 ServerSocket (java.net.ServerSocket)3 List (java.util.List)3 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)2