public void evaluateInTargetContext(
     @NotNull final String isolateId,
     @NotNull final String targetId,
     @NotNull final String expression,
     @NotNull final EvaluateConsumer consumer) {
   addRequest(() -> myVmService.evaluate(isolateId, targetId, expression, consumer));
 }
  @Nullable
  public Script getScriptSync(@NotNull final String isolateId, @NotNull final String scriptId) {
    assertSyncRequestAllowed();

    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    final Ref<Script> resultRef = Ref.create();

    addRequest(
        () ->
            myVmService.getObject(
                isolateId,
                scriptId,
                new GetObjectConsumer() {
                  @Override
                  public void received(Obj script) {
                    resultRef.set((Script) script);
                    semaphore.up();
                  }

                  @Override
                  public void received(Sentinel response) {
                    semaphore.up();
                  }

                  @Override
                  public void onError(RPCError error) {
                    semaphore.up();
                  }
                }));

    semaphore.waitFor(RESPONSE_WAIT_TIMEOUT);
    return resultRef.get();
  }
 public void removeBreakpoint(
     @NotNull final String isolateId, @NotNull final String vmBreakpointId) {
   addRequest(
       () ->
           myVmService.removeBreakpoint(
               isolateId, vmBreakpointId, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER));
 }
  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);
    }
  }
 public void getCollectionObject(
     @NotNull final String isolateId,
     @NotNull final String objectId,
     final int offset,
     final int count,
     @NotNull final GetObjectConsumer consumer) {
   addRequest(() -> myVmService.getObject(isolateId, objectId, offset, count, consumer));
 }
 public void resumeIsolate(
     @NotNull final String isolateId, @Nullable final StepOption stepOption) {
   addRequest(
       () -> {
         myLatestStep = stepOption;
         myVmService.resume(isolateId, stepOption, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
       });
 }
  public void addBreakpoint(
      @NotNull final String isolateId,
      @Nullable final XSourcePosition position,
      @NotNull final VmServiceConsumers.BreakpointConsumerWrapper consumer) {
    if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) {
      consumer.sourcePositionNotApplicable();
      return;
    }

    addRequest(
        () -> {
          final int line = position.getLine() + 1;
          for (String uri : myDebugProcess.getUrisForFile(position.getFile())) {
            myVmService.addBreakpointWithScriptUri(isolateId, uri, line, consumer);
          }
        });
  }
  public void computeStackFrames(
      @NotNull final String isolateId,
      final int firstFrameIndex,
      @NotNull final XExecutionStack.XStackFrameContainer container,
      @Nullable final InstanceRef exception) {
    addRequest(
        () ->
            myVmService.getStack(
                isolateId,
                new StackConsumer() {
                  @Override
                  public void received(final Stack vmStack) {
                    ApplicationManager.getApplication()
                        .executeOnPooledThread(
                            () -> {
                              InstanceRef exceptionToAddToFrame = exception;
                              final List<XStackFrame> result =
                                  new ArrayList<>(vmStack.getFrames().size());
                              for (Frame vmFrame : vmStack.getFrames()) {
                                final DartVmServiceStackFrame stackFrame =
                                    new DartVmServiceStackFrame(
                                        myDebugProcess, isolateId, vmFrame, exceptionToAddToFrame);
                                result.add(stackFrame);

                                if (!stackFrame.isInDartSdkPatchFile()) {
                                  // exception (if any) is added to the frame where debugger stops
                                  // and to the upper frames
                                  exceptionToAddToFrame = null;
                                }
                              }
                              container.addStackFrames(
                                  firstFrameIndex == 0
                                      ? result
                                      : result.subList(firstFrameIndex, result.size()),
                                  true);
                            });
                  }

                  @Override
                  public void onError(final RPCError error) {
                    container.errorOccurred(error.getMessage());
                  }
                }));
  }
  public void evaluateInFrame(
      @NotNull final String isolateId,
      @NotNull final Frame vmFrame,
      @NotNull final String expression,
      @NotNull final XDebuggerEvaluator.XEvaluationCallback callback,
      final boolean reportIfError) {
    addRequest(
        () ->
            myVmService.evaluateInFrame(
                isolateId,
                vmFrame.getIndex(),
                expression,
                new EvaluateInFrameConsumer() {
                  @Override
                  public void received(InstanceRef instanceRef) {
                    callback.evaluated(
                        new DartVmServiceValue(
                            myDebugProcess, isolateId, "result", instanceRef, null, null, false));
                  }

                  @Override
                  public void received(ErrorRef errorRef) {
                    if (reportIfError) {
                      callback.errorOccurred(
                          DartVmServiceEvaluator.getPresentableError(errorRef.getMessage()));
                    }
                  }

                  @Override
                  public void onError(RPCError error) {
                    if (reportIfError) {
                      callback.errorOccurred(error.getMessage());
                    }
                  }
                }));
  }
 public void getObject(
     @NotNull final String isolateId,
     @NotNull final String objectId,
     @NotNull final GetObjectConsumer consumer) {
   addRequest(() -> myVmService.getObject(isolateId, objectId, consumer));
 }
 public void pauseIsolate(@NotNull final String isolateId) {
   addRequest(() -> myVmService.pause(isolateId, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER));
 }
 private void getIsolate(
     @NotNull final String isolateId, @NotNull final GetIsolateConsumer consumer) {
   addRequest(() -> myVmService.getIsolate(isolateId, consumer));
 }
 private void getVm(@NotNull final VMConsumer consumer) {
   addRequest(() -> myVmService.getVM(consumer));
 }
 private void streamListen(
     @NotNull final String streamId, @NotNull final SuccessConsumer consumer) {
   addRequest(() -> myVmService.streamListen(streamId, consumer));
 }