Search in sources :

Example 6 with DebuggerSession

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

the class JvmSmartStepIntoActionHandler method isEnabled.

public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
    final DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
    DebuggerSession debuggerSession = context.getDebuggerSession();
    final boolean isPaused = debuggerSession != null && debuggerSession.isPaused();
    final SuspendContextImpl suspendContext = context.getSuspendContext();
    final boolean hasCurrentThread = suspendContext != null && suspendContext.getThread() != null;
    return isPaused && hasCurrentThread;
}
Also used : DebuggerSession(com.intellij.debugger.impl.DebuggerSession) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 7 with DebuggerSession

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

the class ThreadDumpAction method update.

public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    Project project = e.getProject();
    if (project == null) {
        presentation.setEnabled(false);
        return;
    }
    DebuggerSession debuggerSession = (DebuggerManagerEx.getInstanceEx(project)).getContext().getDebuggerSession();
    presentation.setEnabled(debuggerSession != null && debuggerSession.isAttached());
}
Also used : Project(com.intellij.openapi.project.Project) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 8 with DebuggerSession

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

the class ToggleFieldBreakpointAction method getPlace.

@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return null;
    }
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
        if (psiElement instanceof PsiField) {
            return SourcePosition.createFromElement(psiElement);
        }
        return null;
    }
    final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
    if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess != null) {
            // if there is an active debug session
            final Ref<SourcePosition> positionRef = new Ref<>(null);
            debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {

                @Override
                public Priority getPriority() {
                    return Priority.HIGH;
                }

                @Override
                public void threadAction() {
                    ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
                }
            });
            final SourcePosition sourcePosition = positionRef.get();
            if (sourcePosition != null) {
                return sourcePosition;
            }
        }
    }
    if (DebuggerAction.isContextView(event)) {
        DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
        if (tree != null && tree.getSelectionPath() != null) {
            DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
            if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
                Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
                DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
                PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
                if (psiClass != null) {
                    psiClass = (PsiClass) psiClass.getNavigationElement();
                    final PsiField psiField = psiClass.findFieldByName(field.name(), true);
                    if (psiField != null) {
                        return SourcePosition.createFromElement(psiField);
                    }
                }
            }
        }
        return null;
    }
    Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    }
    if (editor != null) {
        final Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (file != null) {
            final VirtualFile virtualFile = file.getVirtualFile();
            FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
            if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
                final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
                if (field != null) {
                    return SourcePosition.createFromElement(field);
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) Document(com.intellij.openapi.editor.Document) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) FieldDescriptorImpl(com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl) Project(com.intellij.openapi.project.Project) Field(com.sun.jdi.Field) Ref(com.intellij.openapi.util.Ref) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) FileType(com.intellij.openapi.fileTypes.FileType) SourcePosition(com.intellij.debugger.SourcePosition) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Editor(com.intellij.openapi.editor.Editor) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with DebuggerSession

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

the class EditSourceAction method getSourcePosition.

private static SourcePosition getSourcePosition(DebuggerTreeNodeImpl selectedNode, DebuggerContextImpl debuggerContext) {
    final DebuggerContextImpl context = debuggerContext;
    if (selectedNode == null || context == null) {
        return null;
    }
    final Project project = selectedNode.getProject();
    final DebuggerSession debuggerSession = context.getDebuggerSession();
    if (debuggerSession == null) {
        return null;
    }
    NodeDescriptorImpl nodeDescriptor = selectedNode.getDescriptor();
    if (nodeDescriptor instanceof WatchItemDescriptor) {
        Modifier modifier = ((WatchItemDescriptor) nodeDescriptor).getModifier();
        if (modifier == null) {
            return null;
        }
        nodeDescriptor = (NodeDescriptorImpl) modifier.getInspectItem(project);
    }
    final NodeDescriptorImpl nodeDescriptor1 = nodeDescriptor;
    return ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {

        public SourcePosition compute() {
            return SourcePositionProvider.getSourcePosition(nodeDescriptor1, project, context);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) SourcePosition(com.intellij.debugger.SourcePosition) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) WatchItemDescriptor(com.intellij.debugger.ui.impl.watch.WatchItemDescriptor) Modifier(com.intellij.debugger.engine.evaluation.expression.Modifier) NodeDescriptorImpl(com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)

Example 10 with DebuggerSession

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

the class ExportThreadsAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
    final DebuggerSession session = context.getDebuggerSession();
    if (session != null && session.isAttached()) {
        final DebugProcessImpl process = context.getDebugProcess();
        if (process != null) {
            process.getManagerThread().invoke(new DebuggerCommandImpl() {

                protected void action() throws Exception {
                    final List<ThreadState> threads = ThreadDumpAction.buildThreadStates(process.getVirtualMachineProxy());
                    ApplicationManager.getApplication().invokeLater(() -> ExportToTextFileAction.export(project, ThreadDumpPanel.createToFileExporter(project, threads)), ModalityState.NON_MODAL);
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) List(java.util.List) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Aggregations

DebuggerSession (com.intellij.debugger.impl.DebuggerSession)25 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)11 Project (com.intellij.openapi.project.Project)9 XDebugSession (com.intellij.xdebugger.XDebugSession)6 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)4 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)4 Nullable (org.jetbrains.annotations.Nullable)4 SourcePosition (com.intellij.debugger.SourcePosition)3 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)3 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)3 DebugEnvironment (com.intellij.debugger.DebugEnvironment)2 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)2 DebuggerTree (com.intellij.debugger.ui.impl.watch.DebuggerTree)2 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)2 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)2 WatchItemDescriptor (com.intellij.debugger.ui.impl.watch.WatchItemDescriptor)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Ref (com.intellij.openapi.util.Ref)2 XDebugProcess (com.intellij.xdebugger.XDebugProcess)2 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)2