Search in sources :

Example 11 with ThreadReference

use of com.sun.jdi.ThreadReference 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)

Example 12 with ThreadReference

use of com.sun.jdi.ThreadReference in project intellij-community by JetBrains.

the class DebugProcessEvents method processStepEvent.

private void processStepEvent(SuspendContextImpl suspendContext, StepEvent event) {
    final ThreadReference thread = event.thread();
    //LOG.assertTrue(thread.isSuspended());
    preprocessEvent(suspendContext, thread);
    //noinspection HardCodedStringLiteral
    RequestHint hint = (RequestHint) event.request().getProperty("hint");
    deleteStepRequests(event.thread());
    boolean shouldResume = false;
    final Project project = getProject();
    if (hint != null) {
        final int nextStepDepth = hint.getNextStepDepth(suspendContext);
        if (nextStepDepth == RequestHint.RESUME) {
            getSession().clearSteppingThrough();
            shouldResume = true;
        } else if (nextStepDepth != RequestHint.STOP) {
            final ThreadReferenceProxyImpl threadProxy = suspendContext.getThread();
            doStep(suspendContext, threadProxy, hint.getSize(), nextStepDepth, hint);
            shouldResume = true;
        }
        if (!shouldResume && hint.isRestoreBreakpoints()) {
            DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().enableBreakpoints(this);
        }
    }
    if (shouldResume) {
        getSuspendManager().voteResume(suspendContext);
    } else {
        showStatusText("");
        if (myReturnValueWatcher != null) {
            myReturnValueWatcher.disable();
        }
        getSuspendManager().voteSuspend(suspendContext);
        if (hint != null) {
            final MethodFilter methodFilter = hint.getMethodFilter();
            if (methodFilter instanceof NamedMethodFilter && !hint.wasStepTargetMethodMatched()) {
                final String message = "Method <b>" + ((NamedMethodFilter) methodFilter).getMethodName() + "()</b> has not been called";
                XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(message, MessageType.INFO).notify(project);
            }
            if (hint.wasStepTargetMethodMatched() && hint.isResetIgnoreFilters()) {
                checkPositionNotFiltered(suspendContext.getThread(), filters -> mySession.resetIgnoreStepFiltersFlag());
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ThreadReference(com.sun.jdi.ThreadReference) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl) StackCapturingLineBreakpoint(com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint)

Example 13 with ThreadReference

use of com.sun.jdi.ThreadReference in project kotlin by JetBrains.

the class DebuggerSteppingHelper method createStepRequest.

// copied from DebugProcessImpl.doStep
private static void createStepRequest(@NotNull SuspendContextImpl suspendContext, @Nullable ThreadReferenceProxyImpl stepThread, @NotNull EventRequestManager requestManager, int size, int depth) {
    if (stepThread == null) {
        return;
    }
    try {
        ThreadReference stepThreadReference = stepThread.getThreadReference();
        requestManager.deleteEventRequests(requestManager.stepRequests());
        StepRequest stepRequest = requestManager.createStepRequest(stepThreadReference, size, depth);
        List<ClassFilter> activeFilters = getActiveFilters();
        if (!activeFilters.isEmpty()) {
            String currentClassName = getCurrentClassName(stepThread);
            if (currentClassName == null || !DebuggerUtilsEx.isFiltered(currentClassName, activeFilters)) {
                // add class filters
                for (ClassFilter filter : activeFilters) {
                    stepRequest.addClassExclusionFilter(filter.getPattern());
                }
            }
        }
        // suspend policy to match the suspend policy of the context:
        // if all threads were suspended, then during stepping all the threads must be suspended
        // if only event thread were suspended, then only this particular thread must be suspended during stepping
        stepRequest.setSuspendPolicy(suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD ? EventRequest.SUSPEND_EVENT_THREAD : EventRequest.SUSPEND_ALL);
        stepRequest.enable();
    } catch (ObjectCollectedException ignored) {
    }
}
Also used : ObjectCollectedException(com.sun.jdi.ObjectCollectedException) ClassFilter(com.intellij.ui.classFilter.ClassFilter) StepRequest(com.sun.jdi.request.StepRequest) ThreadReference(com.sun.jdi.ThreadReference)

Aggregations

ThreadReference (com.sun.jdi.ThreadReference)13 ObjectReference (com.sun.jdi.ObjectReference)3 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)2 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)2 StackCapturingLineBreakpoint (com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint)2 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 BooleanValue (com.sun.jdi.BooleanValue)2 StringReference (com.sun.jdi.StringReference)2 Value (com.sun.jdi.Value)2 VirtualMachine (com.sun.jdi.VirtualMachine)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 JobScheduler (com.intellij.concurrency.JobScheduler)1 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 ThreadReferenceProxy (com.intellij.debugger.engine.jdi.ThreadReferenceProxy)1 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)1 RequestManagerImpl (com.intellij.debugger.engine.requests.RequestManagerImpl)1 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)1 NotificationType (com.intellij.notification.NotificationType)1