Search in sources :

Example 6 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.

the class SourceCodeChecker method checkSource.

public static void checkSource(DebuggerContextImpl debuggerContext) {
    if (!Registry.is("debugger.check.source")) {
        return;
    }
    SuspendContextImpl suspendContext = debuggerContext.getSuspendContext();
    if (suspendContext == null) {
        return;
    }
    suspendContext.getDebugProcess().getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {

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

        @Override
        public void contextAction() throws Exception {
            try {
                StackFrameProxyImpl frameProxy = debuggerContext.getFrameProxy();
                if (frameProxy == null) {
                    return;
                }
                Location location = frameProxy.location();
                check(location, debuggerContext.getSourcePosition(), suspendContext.getDebugProcess().getProject());
            //checkAllClasses(debuggerContext);
            } catch (EvaluateException e) {
                LOG.info(e);
            }
        }
    });
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) NoDataException(com.intellij.debugger.NoDataException)

Example 7 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.

the class ExecutionWithDebuggerToolsTestCase method addDefaultBreakpointListener.

protected void addDefaultBreakpointListener() {
    if (myPauseScriptListener == null) {
        final DebugProcessImpl debugProcess = getDebugProcess();
        assertTrue("Debug process was not started", debugProcess != null);
        myPauseScriptListener = new DelayedEventsProcessListener(new DebugProcessAdapterImpl() {

            @Override
            public void paused(SuspendContextImpl suspendContext) {
                try {
                    if (myScriptRunnables.isEmpty()) {
                        print("resuming ", ProcessOutputTypes.SYSTEM);
                        printContext(suspendContext);
                        resume(suspendContext);
                        return;
                    }
                    SuspendContextRunnable suspendContextRunnable = myScriptRunnables.remove(0);
                    suspendContextRunnable.run(suspendContext);
                } catch (Exception e) {
                    addException(e);
                    error(e);
                } catch (AssertionError e) {
                    addException(e);
                    resume(suspendContext);
                }
                if (myScriptRunnables.isEmpty()) {
                    myScriptRunnablesSema.up();
                }
            }

            //executed in manager thread
            @Override
            public void resumed(SuspendContextImpl suspendContext) {
                final SuspendContextImpl pausedContext = debugProcess.getSuspendManager().getPausedContext();
                if (pausedContext != null) {
                    debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(pausedContext) {

                        @Override
                        public void contextAction() throws Exception {
                            paused(pausedContext);
                        }
                    });
                }
            }
        });
        debugProcess.addDebugProcessListener(myPauseScriptListener);
    }
}
Also used : SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) ExecutionException(com.intellij.execution.ExecutionException) CompoundRuntimeException(com.intellij.util.lang.CompoundRuntimeException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 8 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.

the class ExecutionWithDebuggerToolsTestCase method pumpSwingThread.

protected void pumpSwingThread() {
    LOG.assertTrue(SwingUtilities.isEventDispatchThread());
    final InvokeRatherLaterRequest request = myRatherLaterRequests.get(0);
    request.invokesN++;
    if (request.invokesN == RATHER_LATER_INVOKES_N) {
        myRatherLaterRequests.remove(0);
        if (!myRatherLaterRequests.isEmpty())
            pumpSwingThread();
    }
    if (request.myDebuggerCommand instanceof SuspendContextCommandImpl) {
        request.myDebugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(((SuspendContextCommandImpl) request.myDebuggerCommand).getSuspendContext()) {

            @Override
            public void contextAction() throws Exception {
                pumpDebuggerThread(request);
            }

            @Override
            protected void commandCancelled() {
                pumpDebuggerThread(request);
            }
        });
    } else {
        request.myDebugProcess.getManagerThread().schedule(new DebuggerCommandImpl() {

            @Override
            protected void action() throws Exception {
                pumpDebuggerThread(request);
            }

            @Override
            protected void commandCancelled() {
                pumpDebuggerThread(request);
            }
        });
    }
}
Also used : DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) ExecutionException(com.intellij.execution.ExecutionException) CompoundRuntimeException(com.intellij.util.lang.CompoundRuntimeException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 9 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.

the class SuspendContextImpl method resume.

protected void resume() {
    assertNotResumed();
    if (isEvaluating()) {
        LOG.error("Resuming context while evaluating", ThreadDumper.dumpThreadsToString());
    }
    DebuggerManagerThreadImpl.assertIsManagerThread();
    try {
        if (!Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
            myKeptReferences.forEach(DebuggerUtilsEx::enableCollection);
            myKeptReferences.clear();
        }
        for (SuspendContextCommandImpl cmd = pollPostponedCommand(); cmd != null; cmd = pollPostponedCommand()) {
            cmd.notifyCancelled();
        }
        resumeImpl();
    } finally {
        myIsResumed = true;
    }
}
Also used : DebuggerUtilsEx(com.intellij.debugger.impl.DebuggerUtilsEx) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl)

Example 10 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl 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

SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)14 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)9 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)3 NotNull (org.jetbrains.annotations.NotNull)3 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)2 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)2 ExecutionException (com.intellij.execution.ExecutionException)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 CompoundRuntimeException (com.intellij.util.lang.CompoundRuntimeException)2 VMDisconnectedException (com.sun.jdi.VMDisconnectedException)2 EvaluatingComputable (com.intellij.debugger.EvaluatingComputable)1 NoDataException (com.intellij.debugger.NoDataException)1 SourcePosition (com.intellij.debugger.SourcePosition)1 JavaValue (com.intellij.debugger.engine.JavaValue)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 SuspendContextCommand (com.intellij.debugger.engine.managerThread.SuspendContextCommand)1 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)1