package com.intellij.debugger.actions;

import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.engine.SuspendContextImpl;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.sun.jdi.request.EventRequest;
import org.jetbrains.annotations.NotNull;

public class PauseActionHandler extends DebuggerActionHandler {
  public void perform(@NotNull final Project project, final AnActionEvent event) {
    (DebuggerManagerEx.getInstanceEx(project)).getContext().getDebuggerSession().pause();
  }

  public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(project).getContext().getDebuggerSession();
    return debuggerSession != null && !debuggerSession.getProcess().isPausePressed() &&
           (debuggerSession.isEvaluating() || 
            debuggerSession.isRunning() || isSingleThreadSuspended(debuggerSession)
           );
  }

  private boolean isSingleThreadSuspended(final DebuggerSession debuggerSession) {
    final SuspendContextImpl suspendContext = debuggerSession.getContextManager().getContext().getSuspendContext();
    return suspendContext != null && suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD;
  }
}

@@ -1137,16 +1137,23 @@
 private 
+static 
 boolean 
@@ -1369,16 +1369,47 @@
  null &&
+ !suspendContext.isResumed() &&
  suspend

fix assertion IDEADEV-25722