public void handleIsolate(
      @NotNull final IsolateRef isolateRef, final boolean isolatePausedStart) {
    // We should auto-resume on a StartPaused event, if we're not remote debugging, and after
    // breakpoints have been set.

    final boolean newIsolate = myIsolatesInfo.addIsolate(isolateRef);

    if (isolatePausedStart) {
      myIsolatesInfo.setShouldInitialResume(isolateRef);
    }

    // Just to make sure that the main isolate is not handled twice, both from
    // handleDebuggerConnected() and DartVmServiceListener.received(PauseStart)
    if (newIsolate) {
      addRequest(
          () ->
              myVmService.setExceptionPauseMode(
                  isolateRef.getId(),
                  ExceptionPauseMode.Unhandled,
                  new VmServiceConsumers.SuccessConsumerWrapper() {
                    @Override
                    public void received(Success response) {
                      setInitialBreakpointsAndResume(isolateRef);
                    }
                  }));
    } else {
      checkInitialResume(isolateRef);
    }
  }
  private void doSetInitialBreakpointsAndResume(@NotNull final IsolateRef isolateRef) {
    final Set<XLineBreakpoint<XBreakpointProperties>> xBreakpoints =
        myBreakpointHandler.getXBreakpoints();

    if (xBreakpoints.isEmpty()) {
      myIsolatesInfo.setBreakpointsSet(isolateRef);
      checkInitialResume(isolateRef);
      return;
    }

    final AtomicInteger counter = new AtomicInteger(xBreakpoints.size());

    for (final XLineBreakpoint<XBreakpointProperties> xBreakpoint : xBreakpoints) {
      addBreakpoint(
          isolateRef.getId(),
          xBreakpoint.getSourcePosition(),
          new VmServiceConsumers.BreakpointConsumerWrapper() {
            @Override
            void sourcePositionNotApplicable() {
              checkDone();
            }

            @Override
            public void received(Breakpoint vmBreakpoint) {
              myBreakpointHandler.vmBreakpointAdded(xBreakpoint, isolateRef.getId(), vmBreakpoint);
              checkDone();
            }

            @Override
            public void onError(RPCError error) {
              myBreakpointHandler.breakpointFailed(xBreakpoint);
              checkDone();
            }

            private void checkDone() {
              if (counter.decrementAndGet() == 0) {
                myIsolatesInfo.setBreakpointsSet(isolateRef);
                checkInitialResume(isolateRef);
              }
            }
          });
    }
  }
 private void setInitialBreakpointsAndResume(@NotNull final IsolateRef isolateRef) {
   if (myDebugProcess.isRemoteDebug()) {
     if (myDebugProcess.myRemoteProjectRootUri == null) {
       // need to detect remote project root path before setting breakpoints
       getIsolate(
           isolateRef.getId(),
           new VmServiceConsumers.GetIsolateConsumerWrapper() {
             @Override
             public void received(final Isolate isolate) {
               myDebugProcess.guessRemoteProjectRoot(isolate.getLibraries());
               doSetInitialBreakpointsAndResume(isolateRef);
             }
           });
     } else {
       doSetInitialBreakpointsAndResume(isolateRef);
     }
   } else {
     doSetInitialBreakpointsAndResume(isolateRef);
   }
 }
  void onIsolatePaused(
      @NotNull final IsolateRef isolateRef,
      @Nullable final ElementList<Breakpoint> vmBreakpoints,
      @Nullable final InstanceRef exception,
      @Nullable final Frame vmTopFrame,
      boolean atAsyncSuspension) {
    if (vmTopFrame == null) {
      myDebugProcess.getSession().positionReached(new XSuspendContext() {});
      return;
    }

    final DartVmServiceSuspendContext suspendContext =
        new DartVmServiceSuspendContext(
            myDebugProcess, isolateRef, vmTopFrame, exception, atAsyncSuspension);
    final XStackFrame xTopFrame = suspendContext.getActiveExecutionStack().getTopFrame();
    final XSourcePosition sourcePosition = xTopFrame == null ? null : xTopFrame.getSourcePosition();

    if (vmBreakpoints == null || vmBreakpoints.isEmpty()) {
      final StepOption latestStep = myDebugProcess.getVmServiceWrapper().getLatestStep();

      if (latestStep == StepOption.Over
          && equalSourcePositions(myLatestSourcePosition, sourcePosition)) {
        // continue stepping to change current line
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), latestStep);
      } else {
        myLatestSourcePosition = sourcePosition;
        myDebugProcess.getSession().positionReached(suspendContext);
      }
    } else {
      if (vmBreakpoints.size() > 1) {
        // Shouldn't happen. IDE doesn't allow to set 2 breakpoints on one line.
        LOG.error(vmBreakpoints.size() + " breakpoints hit in one shot.");
      }

      // Remove any temporary (run to cursor) breakpoints.
      myBreakpointHandler.removeTemporaryBreakpoints(isolateRef.getId());

      final XLineBreakpoint<XBreakpointProperties> xBreakpoint =
          myBreakpointHandler.getXBreakpoint(vmBreakpoints.get(0));

      if (xBreakpoint == null) {
        // breakpoint could be set in the Observatory
        myLatestSourcePosition = sourcePosition;
        myDebugProcess.getSession().positionReached(suspendContext);
        return;
      }

      if ("false"
          .equals(
              evaluateExpression(
                  isolateRef.getId(), vmTopFrame, xBreakpoint.getConditionExpression()))) {
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
        return;
      }

      myLatestSourcePosition = sourcePosition;

      final String logExpression =
          evaluateExpression(isolateRef.getId(), vmTopFrame, xBreakpoint.getLogExpressionObject());
      final boolean suspend =
          myDebugProcess.getSession().breakpointReached(xBreakpoint, logExpression, suspendContext);
      if (!suspend) {
        myDebugProcess.getVmServiceWrapper().resumeIsolate(isolateRef.getId(), null);
      }
    }
  }
 private void checkInitialResume(IsolateRef isolateRef) {
   if (myIsolatesInfo.getShouldInitialResume(isolateRef)) {
     resumeIsolate(isolateRef.getId(), null);
   }
 }