Search in sources :

Example 6 with SuspendContextImpl

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

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

the class ThreadDescriptorImpl method setContext.

public void setContext(EvaluationContextImpl context) {
    final ThreadReferenceProxyImpl thread = getThreadReference();
    final SuspendManager suspendManager = context != null ? context.getDebugProcess().getSuspendManager() : null;
    final SuspendContextImpl suspendContext = context != null ? context.getSuspendContext() : null;
    try {
        myIsSuspended = suspendManager != null ? suspendManager.isSuspended(thread) : thread.isSuspended();
    } catch (ObjectCollectedException e) {
        myIsSuspended = false;
    }
    myIsExpandable = calcExpandable(myIsSuspended);
    mySuspendContext = suspendManager != null ? SuspendManagerUtil.findContextByThread(suspendManager, thread) : suspendContext;
    myIsAtBreakpoint = thread.isAtBreakpoint();
    myIsCurrent = suspendContext != null ? suspendContext.getThread() == thread : false;
    myIsFrozen = suspendManager != null ? suspendManager.isFrozen(thread) : myIsSuspended;
}
Also used : ObjectCollectedException(com.sun.jdi.ObjectCollectedException) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl) SuspendManager(com.intellij.debugger.engine.SuspendManager)

Example 8 with SuspendContextImpl

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

the class ReloadClassesWorker method reloadClasses.

public void reloadClasses(final Map<String, HotSwapFile> modifiedClasses) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    if (modifiedClasses == null || modifiedClasses.size() == 0) {
        myProgress.addMessage(myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.hotswap.loaded.classes.up.to.date"));
        return;
    }
    final DebugProcessImpl debugProcess = getDebugProcess();
    final VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();
    final Project project = debugProcess.getProject();
    final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager();
    breakpointManager.disableBreakpoints(debugProcess);
    try {
        RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy);
        int processedEntriesCount = 0;
        for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) {
            // stop if process is finished already
            if (debugProcess.isDetached() || debugProcess.isDetaching()) {
                break;
            }
            if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
                // once at least one class has been actually reloaded, do not interrupt the whole process
                break;
            }
            processedEntriesCount++;
            final String qualifiedName = entry.getKey();
            if (qualifiedName != null) {
                myProgress.setText(qualifiedName);
                myProgress.setFraction(processedEntriesCount / (double) modifiedClasses.size());
            }
            try {
                redefineProcessor.processClass(qualifiedName, entry.getValue().file);
            } catch (IOException e) {
                reportProblem(qualifiedName, e);
            }
        }
        if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
            // once at least one class has been actually reloaded, do not interrupt the whole process
            return;
        }
        redefineProcessor.processPending();
        myProgress.setFraction(1);
        final int partiallyRedefinedClassesCount = redefineProcessor.getPartiallyRedefinedClassesCount();
        if (partiallyRedefinedClassesCount == 0) {
            myProgress.addMessage(myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.classes.reloaded", redefineProcessor.getProcessedClassesCount()));
        } else {
            final String message = DebuggerBundle.message("status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount, redefineProcessor.getProcessedClassesCount());
            myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message);
        }
        LOG.debug("classes reloaded");
    } catch (Throwable e) {
        processException(e);
    }
    debugProcess.onHotSwapFinished();
    DebuggerContextImpl context = myDebuggerSession.getContextManager().getContext();
    SuspendContextImpl suspendContext = context.getSuspendContext();
    if (suspendContext != null) {
        XExecutionStack stack = suspendContext.getActiveExecutionStack();
        if (stack != null) {
            ((JavaExecutionStack) stack).initTopFrame();
        }
    }
    final Semaphore waitSemaphore = new Semaphore();
    waitSemaphore.down();
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(() -> {
        try {
            if (!project.isDisposed()) {
                breakpointManager.reloadBreakpoints();
                debugProcess.getRequestsManager().clearWarnings();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("requests updated");
                    LOG.debug("time stamp set");
                }
                myDebuggerSession.refresh(false);
                XDebugSession session = myDebuggerSession.getXDebugSession();
                if (session != null) {
                    session.rebuildViews();
                }
            }
        } catch (Throwable e) {
            LOG.error(e);
        } finally {
            waitSemaphore.up();
        }
    });
    waitSemaphore.waitFor();
    if (!project.isDisposed()) {
        try {
            breakpointManager.enableBreakpoints(debugProcess);
        } catch (Exception e) {
            processException(e);
        }
    }
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) IOException(java.io.IOException) Semaphore(com.intellij.util.concurrency.Semaphore) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) JavaExecutionStack(com.intellij.debugger.engine.JavaExecutionStack) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with SuspendContextImpl

use of com.intellij.debugger.engine.SuspendContextImpl 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 10 with SuspendContextImpl

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

the class SuspendContextCommandImpl method action.

@Override
public final void action() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("trying " + this);
    }
    final SuspendContextImpl suspendContext = getSuspendContext();
    if (suspendContext == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("skip processing - context is null " + this);
        }
        notifyCancelled();
        return;
    }
    if (suspendContext.myInProgress) {
        suspendContext.postponeCommand(this);
    } else {
        try {
            if (!suspendContext.isResumed()) {
                suspendContext.myInProgress = true;
                contextAction(suspendContext);
            } else {
                notifyCancelled();
            }
        } finally {
            suspendContext.myInProgress = false;
            if (suspendContext.isResumed()) {
                for (SuspendContextCommandImpl postponed = suspendContext.pollPostponedCommand(); postponed != null; postponed = suspendContext.pollPostponedCommand()) {
                    postponed.notifyCancelled();
                }
            } else {
                SuspendContextCommandImpl postponed = suspendContext.pollPostponedCommand();
                if (postponed != null) {
                    final Stack<SuspendContextCommandImpl> stack = new Stack<>();
                    while (postponed != null) {
                        stack.push(postponed);
                        postponed = suspendContext.pollPostponedCommand();
                    }
                    final DebuggerManagerThreadImpl managerThread = suspendContext.getDebugProcess().getManagerThread();
                    while (!stack.isEmpty()) {
                        managerThread.pushBack(stack.pop());
                    }
                }
            }
        }
    }
}
Also used : DebuggerManagerThreadImpl(com.intellij.debugger.engine.DebuggerManagerThreadImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) Stack(com.intellij.util.containers.Stack)

Aggregations

SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)14 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)5 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)4 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)3 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)3 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)3 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)3 List (java.util.List)3 SuspendManager (com.intellij.debugger.engine.SuspendManager)2 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)2 ThreadDescriptorImpl (com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl)2 XDebugSession (com.intellij.xdebugger.XDebugSession)2 XExecutionStack (com.intellij.xdebugger.frame.XExecutionStack)2 ObjectCollectedException (com.sun.jdi.ObjectCollectedException)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 Client (com.android.ddmlib.Client)1 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1