Search in sources :

Example 41 with XDebugSession

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

the class DebuggerContextUtil method findNearest.

public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) {
    if (psi instanceof PsiCompiledElement) {
        // it makes no sense to compute text range of compiled element
        return null;
    }
    final DebuggerSession session = context.getDebuggerSession();
    if (session != null) {
        try {
            final XDebugSession debugSession = session.getXDebugSession();
            if (debugSession != null) {
                final XSourcePosition position = debugSession.getCurrentPosition();
                Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);
                //final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null;
                if (editor != null && position != null && position.getFile().equals(file.getOriginalFile().getVirtualFile())) {
                    PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
                    final Collection<TextRange> ranges = IdentifierHighlighterPass.getUsages(psi, method != null ? method : file, false);
                    final int breakPointLine = position.getLine();
                    int bestLine = -1;
                    int bestOffset = -1;
                    for (TextRange range : ranges) {
                        final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
                        if (line > bestLine && line < breakPointLine) {
                            bestLine = line;
                            bestOffset = range.getStartOffset();
                        } else if (line == breakPointLine) {
                            bestOffset = range.getStartOffset();
                            break;
                        }
                    }
                    if (bestOffset > -1) {
                        return SourcePosition.createFromOffset(file, bestOffset);
                    }
                }
            }
        } catch (Exception ignore) {
        }
    }
    return null;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) PsiMethod(com.intellij.psi.PsiMethod) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) TextRange(com.intellij.openapi.util.TextRange) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Editor(com.intellij.openapi.editor.Editor)

Example 42 with XDebugSession

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

the class CodeFragmentFactoryContextWrapper method wrapContext.

private PsiElement wrapContext(Project project, final PsiElement originalContext) {
    if (project.isDefault())
        return originalContext;
    //TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
    if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
        return originalContext;
    }
    PsiElement context = originalContext;
    XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
    if (session != null) {
        XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
        Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
        //final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
        if (!ContainerUtil.isEmpty(markupMap)) {
            final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
            int offset = markupVariables.getFirst().length() - 1;
            final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
            final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
            codeFragment.accept(new JavaRecursiveElementVisitor() {

                public void visitLocalVariable(PsiLocalVariable variable) {
                    final String name = variable.getName();
                    variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
                }
            });
            final PsiElement newContext = codeFragment.findElementAt(offset);
            if (newContext != null) {
                context = newContext;
            }
        }
    }
    return context;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup) HashMap(java.util.HashMap) Map(java.util.Map) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) JavaRecursiveElementVisitor(com.intellij.psi.JavaRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Example 43 with XDebugSession

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

the class ShowTypesAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project != null) {
        XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
        if (session != null && session.getDebugProcess() instanceof JavaDebugProcess) {
            e.getPresentation().setEnabledAndVisible(true);
            super.update(e);
            return;
        }
    }
    e.getPresentation().setEnabledAndVisible(false);
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) JavaDebugProcess(com.intellij.debugger.engine.JavaDebugProcess)

Example 44 with XDebugSession

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

the class ThreadDumpAction 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();
        process.getManagerThread().invoke(new DebuggerCommandImpl() {

            protected void action() throws Exception {
                final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy();
                vm.suspend();
                try {
                    final List<ThreadState> threads = buildThreadStates(vm);
                    ApplicationManager.getApplication().invokeLater(() -> {
                        XDebugSession xSession = session.getXDebugSession();
                        if (xSession != null) {
                            DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session);
                        }
                    }, ModalityState.NON_MODAL);
                } finally {
                    vm.resume();
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ArrayList(java.util.ArrayList) List(java.util.List) SmartList(com.intellij.util.SmartList) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 45 with XDebugSession

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

the class XsltBreakpointHandler method registerBreakpoint.

@Override
public void registerBreakpoint(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint) {
    final XSourcePosition sourcePosition = breakpoint.getSourcePosition();
    if (sourcePosition == null || !sourcePosition.getFile().exists() || !sourcePosition.getFile().isValid()) {
        // ???
        return;
    }
    final VirtualFile file = sourcePosition.getFile();
    final Project project = myXsltDebugProcess.getSession().getProject();
    final String fileURL = getFileURL(file);
    final int lineNumber = getActualLineNumber(breakpoint, project);
    if (lineNumber == -1) {
        final XDebugSession session = myXsltDebugProcess.getSession();
        session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, "Unsupported breakpoint position");
        return;
    }
    try {
        final BreakpointManager manager = myXsltDebugProcess.getBreakpointManager();
        Breakpoint bp;
        if ((bp = manager.getBreakpoint(fileURL, lineNumber)) != null) {
            bp.setEnabled(true);
        } else {
            manager.setBreakpoint(fileURL, lineNumber);
        }
    } catch (DebuggerStoppedException ignore) {
    } catch (VMPausedException e) {
        final XDebugSession session = myXsltDebugProcess.getSession();
        session.reportMessage("Target VM is not responding. Breakpoint can not be set", MessageType.ERROR);
        session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, "Target VM is not responding. Breakpoint can not be set");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) Breakpoint(org.intellij.plugins.xsltDebugger.rt.engine.Breakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XSourcePosition(com.intellij.xdebugger.XSourcePosition) VMPausedException(org.intellij.plugins.xsltDebugger.VMPausedException) BreakpointManager(org.intellij.plugins.xsltDebugger.rt.engine.BreakpointManager) Breakpoint(org.intellij.plugins.xsltDebugger.rt.engine.Breakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) DebuggerStoppedException(org.intellij.plugins.xsltDebugger.rt.engine.DebuggerStoppedException)

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