Search in sources :

Example 6 with Breakpoint

use of com.intellij.debugger.ui.breakpoints.Breakpoint in project intellij-community by JetBrains.

the class ToggleFieldBreakpointAction method update.

@Override
public void update(AnActionEvent event) {
    SourcePosition place = getPlace(event);
    boolean toEnable = place != null;
    Presentation presentation = event.getPresentation();
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        presentation.setVisible(toEnable);
    } else if (DebuggerAction.isContextView(event)) {
        presentation.setText(DebuggerBundle.message("action.add.field.watchpoint.text"));
        Project project = event.getData(CommonDataKeys.PROJECT);
        if (project != null && place != null) {
            Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile());
            if (document != null) {
                final int offset = place.getOffset();
                final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager();
                final Breakpoint fieldBreakpoint = offset >= 0 ? breakpointManager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null;
                if (fieldBreakpoint != null) {
                    presentation.setEnabled(false);
                    return;
                }
            }
        }
    }
    presentation.setVisible(toEnable);
}
Also used : Project(com.intellij.openapi.project.Project) FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) SourcePosition(com.intellij.debugger.SourcePosition) Document(com.intellij.openapi.editor.Document) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager)

Example 7 with Breakpoint

use of com.intellij.debugger.ui.breakpoints.Breakpoint in project intellij-community by JetBrains.

the class ToggleFieldBreakpointAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    final SourcePosition place = getPlace(e);
    if (place != null) {
        Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile());
        if (document != null) {
            DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
            BreakpointManager manager = debuggerManager.getBreakpointManager();
            final int offset = place.getOffset();
            final Breakpoint breakpoint = offset >= 0 ? manager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null;
            if (breakpoint == null) {
                FieldBreakpoint fieldBreakpoint = manager.addFieldBreakpoint(document, offset);
                if (fieldBreakpoint != null) {
                    if (DebuggerAction.isContextView(e)) {
                        final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(e.getDataContext());
                        if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
                            ObjectReference object = ((FieldDescriptorImpl) selectedNode.getDescriptor()).getObject();
                            if (object != null) {
                                long id = object.uniqueID();
                                InstanceFilter[] instanceFilters = new InstanceFilter[] { InstanceFilter.create(Long.toString(id)) };
                                fieldBreakpoint.setInstanceFilters(instanceFilters);
                                fieldBreakpoint.setInstanceFiltersEnabled(true);
                            }
                        }
                    }
                    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
                    if (editor != null) {
                        manager.editBreakpoint(fieldBreakpoint, editor);
                    }
                }
            } else {
                manager.removeBreakpoint(breakpoint);
            }
        }
    }
}
Also used : FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) InstanceFilter(com.intellij.debugger.InstanceFilter) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Document(com.intellij.openapi.editor.Document) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager) FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) FieldDescriptorImpl(com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl) Project(com.intellij.openapi.project.Project) ObjectReference(com.sun.jdi.ObjectReference) SourcePosition(com.intellij.debugger.SourcePosition) Editor(com.intellij.openapi.editor.Editor)

Example 8 with Breakpoint

use of com.intellij.debugger.ui.breakpoints.Breakpoint in project android by JetBrains.

the class InstantRunManager method refreshDebugger.

private void refreshDebugger(@NotNull String packageName) {
    // First we reapply the breakpoints on the new code, otherwise the breakpoints
    // remain set on the old classes and will never be hit again.
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            DebuggerManagerEx debugger = DebuggerManagerEx.getInstanceEx(myProject);
            if (!debugger.getSessions().isEmpty()) {
                List<Breakpoint> breakpoints = debugger.getBreakpointManager().getBreakpoints();
                for (Breakpoint breakpoint : breakpoints) {
                    if (breakpoint.isEnabled()) {
                        breakpoint.setEnabled(false);
                        breakpoint.setEnabled(true);
                    }
                }
            }
        }
    });
    // Now we refresh the call-stacks and the variable panes.
    DebuggerManagerEx debugger = DebuggerManagerEx.getInstanceEx(myProject);
    for (final DebuggerSession session : debugger.getSessions()) {
        Client client = session.getProcess().getProcessHandler().getUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT);
        if (client != null && client.isValid() && StringUtil.equals(packageName, client.getClientData().getClientDescription())) {
            session.getProcess().getManagerThread().invoke(new DebuggerCommandImpl() {

                @Override
                protected void action() throws Exception {
                    DebuggerContextImpl context = session.getContextManager().getContext();
                    SuspendContextImpl suspendContext = context.getSuspendContext();
                    if (suspendContext != null) {
                        XExecutionStack stack = suspendContext.getActiveExecutionStack();
                        if (stack != null) {
                            ((JavaExecutionStack) stack).initTopFrame();
                        }
                    }
                    ApplicationManager.getApplication().invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            session.refresh(false);
                            XDebugSession xSession = session.getXDebugSession();
                            if (xSession != null) {
                                xSession.resume();
                            }
                        }
                    });
                }
            });
        }
    }
}
Also used : Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) XDebugSession(com.intellij.xdebugger.XDebugSession) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack) InstantRunPushFailedException(com.android.tools.fd.client.InstantRunPushFailedException) IOException(java.io.IOException) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) List(java.util.List) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) InstantRunClient(com.android.tools.fd.client.InstantRunClient) Client(com.android.ddmlib.Client)

Example 9 with Breakpoint

use of com.intellij.debugger.ui.breakpoints.Breakpoint in project intellij-community by JetBrains.

the class ToggleMethodBreakpointAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project);
    if (debugManager == null) {
        return;
    }
    final BreakpointManager manager = debugManager.getBreakpointManager();
    final PlaceInDocument place = getPlace(e);
    if (place != null && DocumentUtil.isValidOffset(place.getOffset(), place.getDocument())) {
        Breakpoint breakpoint = manager.findBreakpoint(place.getDocument(), place.getOffset(), MethodBreakpoint.CATEGORY);
        if (breakpoint == null) {
            manager.addMethodBreakpoint(place.getDocument(), place.getDocument().getLineNumber(place.getOffset()));
        } else {
            manager.removeBreakpoint(breakpoint);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) MethodBreakpoint(com.intellij.debugger.ui.breakpoints.MethodBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager)

Example 10 with Breakpoint

use of com.intellij.debugger.ui.breakpoints.Breakpoint in project intellij-community by JetBrains.

the class DebugProcessEvents method processLocatableEvent.

private void processLocatableEvent(final SuspendContextImpl suspendContext, final LocatableEvent event) {
    ThreadReference thread = event.thread();
    //LOG.assertTrue(thread.isSuspended());
    preprocessEvent(suspendContext, thread);
    //we use schedule to allow processing other events during processing this one
    //this is especially necessary if a method is breakpoint condition
    getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {

        @Override
        public void contextAction() throws Exception {
            final SuspendManager suspendManager = getSuspendManager();
            SuspendContextImpl evaluatingContext = SuspendManagerUtil.getEvaluatingContext(suspendManager, suspendContext.getThread());
            if (evaluatingContext != null && !DebuggerSession.enableBreakpointsDuringEvaluation()) {
                // is inside evaluation, so ignore any breakpoints
                suspendManager.voteResume(suspendContext);
                return;
            }
            final LocatableEventRequestor requestor = (LocatableEventRequestor) getRequestsManager().findRequestor(event.request());
            boolean resumePreferred = requestor != null && DebuggerSettings.SUSPEND_NONE.equals(requestor.getSuspendPolicy());
            boolean requestHit;
            try {
                requestHit = (requestor != null) && requestor.processLocatableEvent(this, event);
            } catch (final LocatableEventRequestor.EventProcessingException ex) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(ex.getMessage());
                }
                final boolean[] considerRequestHit = new boolean[] { true };
                DebuggerInvocationUtil.invokeAndWait(getProject(), () -> {
                    final String displayName = requestor instanceof Breakpoint ? ((Breakpoint) requestor).getDisplayName() : requestor.getClass().getSimpleName();
                    final String message = DebuggerBundle.message("error.evaluating.breakpoint.condition.or.action", displayName, ex.getMessage());
                    considerRequestHit[0] = Messages.showYesNoDialog(getProject(), message, ex.getTitle(), Messages.getQuestionIcon()) == Messages.YES;
                }, ModalityState.NON_MODAL);
                requestHit = considerRequestHit[0];
                resumePreferred = !requestHit;
            }
            if (requestHit && requestor instanceof Breakpoint) {
                // if requestor is a breakpoint and this breakpoint was hit, no matter its suspend policy
                ApplicationManager.getApplication().runReadAction(() -> {
                    XDebugSession session = getSession().getXDebugSession();
                    if (session != null) {
                        XBreakpoint breakpoint = ((Breakpoint) requestor).getXBreakpoint();
                        if (breakpoint != null) {
                            ((XDebugSessionImpl) session).processDependencies(breakpoint);
                        }
                    }
                });
            }
            if (!requestHit || resumePreferred) {
                suspendManager.voteResume(suspendContext);
            } else {
                if (myReturnValueWatcher != null) {
                    myReturnValueWatcher.disable();
                }
                //if (suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL) {
                //  // there could be explicit resume as a result of call to voteSuspend()
                //  // e.g. when breakpoint was considered invalid, in that case the filter will be applied _after_
                //  // resuming and all breakpoints in other threads will be ignored.
                //  // As resume() implicitly cleares the filter, the filter must be always applied _before_ any resume() action happens
                //  myBreakpointManager.applyThreadFilter(DebugProcessEvents.this, event.thread());
                //}
                suspendManager.voteSuspend(suspendContext);
                showStatusText(DebugProcessEvents.this, event);
            }
        }
    });
}
Also used : StackCapturingLineBreakpoint(com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) XDebugSession(com.intellij.xdebugger.XDebugSession) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) ThreadReference(com.sun.jdi.ThreadReference) LocatableEventRequestor(com.intellij.debugger.engine.requests.LocatableEventRequestor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) InternalException(com.sun.jdi.InternalException)

Aggregations

Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)13 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)4 BreakpointManager (com.intellij.debugger.ui.breakpoints.BreakpointManager)4 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)4 StackCapturingLineBreakpoint (com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint)3 Project (com.intellij.openapi.project.Project)3 SourcePosition (com.intellij.debugger.SourcePosition)2 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)2 Requestor (com.intellij.debugger.requests.Requestor)2 FieldBreakpoint (com.intellij.debugger.ui.breakpoints.FieldBreakpoint)2 Document (com.intellij.openapi.editor.Document)2 XDebugSession (com.intellij.xdebugger.XDebugSession)2 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)2 XBreakpointBase (com.intellij.xdebugger.impl.breakpoints.XBreakpointBase)2 InternalException (com.sun.jdi.InternalException)2 Event (com.sun.jdi.event.Event)2 Client (com.android.ddmlib.Client)1 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1 CloudLineBreakpointType (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)1