Search in sources :

Example 1 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method computeStackFrames.

public void computeStackFrames(@NotNull final String isolateId, final int firstFrameIndex, @NotNull final XExecutionStack.XStackFrameContainer container, @Nullable final InstanceRef exception) {
    addRequest(() -> myVmService.getStack(isolateId, new GetStackConsumer() {

        @Override
        public void received(final Stack vmStack) {
            ApplicationManager.getApplication().executeOnPooledThread(() -> {
                InstanceRef exceptionToAddToFrame = exception;
                // Check for async causal frames; fall back to using regular sync frames.
                ElementList<Frame> elementList = vmStack.getAsyncCausalFrames();
                if (elementList == null) {
                    elementList = vmStack.getFrames();
                }
                final List<Frame> vmFrames = Lists.newArrayList(elementList);
                final List<XStackFrame> xStackFrames = new ArrayList<>(vmFrames.size());
                for (final Frame vmFrame : vmFrames) {
                    if (vmFrame.getKind() == FrameKind.AsyncSuspensionMarker) {
                        // Render an asynchronous gap.
                        final XStackFrame markerFrame = new DartAsyncMarkerFrame();
                        xStackFrames.add(markerFrame);
                    } else {
                        final DartVmServiceStackFrame stackFrame = new DartVmServiceStackFrame(myDebugProcess, isolateId, vmFrame, vmFrames, exceptionToAddToFrame);
                        stackFrame.setIsDroppableFrame(vmFrame.getKind() == FrameKind.Regular);
                        xStackFrames.add(stackFrame);
                        if (!stackFrame.isInDartSdkPatchFile()) {
                            // The exception (if any) is added to the frame where debugger stops and to the upper frames.
                            exceptionToAddToFrame = null;
                        }
                    }
                }
                container.addStackFrames(firstFrameIndex == 0 ? xStackFrames : xStackFrames.subList(firstFrameIndex, xStackFrames.size()), true);
            });
        }

        @Override
        public void onError(final RPCError error) {
            container.errorOccurred(error.getMessage());
        }

        @Override
        public void received(Sentinel response) {
            container.errorOccurred(response.getValueAsString());
        }
    }));
}
Also used : InstanceRef(org.dartlang.vm.service.element.InstanceRef) GetStackConsumer(org.dartlang.vm.service.consumer.GetStackConsumer) Frame(org.dartlang.vm.service.element.Frame) DartVmServiceStackFrame(io.flutter.vmService.frame.DartVmServiceStackFrame) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) DartAsyncMarkerFrame(io.flutter.vmService.frame.DartAsyncMarkerFrame) Sentinel(org.dartlang.vm.service.element.Sentinel) ArrayList(java.util.ArrayList) RPCError(org.dartlang.vm.service.element.RPCError) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack) Stack(org.dartlang.vm.service.element.Stack) DartVmServiceStackFrame(io.flutter.vmService.frame.DartVmServiceStackFrame) DartAsyncMarkerFrame(io.flutter.vmService.frame.DartAsyncMarkerFrame)

Example 2 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method attachIsolate.

public void attachIsolate(@NotNull IsolateRef isolateRef, @NotNull Isolate isolate) {
    final boolean newIsolate = myIsolatesInfo.addIsolate(isolateRef);
    // Just to make sure that the main isolate is not handled twice, both from handleDebuggerConnected() and DartVmServiceListener.received(PauseStart)
    if (newIsolate) {
        final XDebugSessionImpl session = (XDebugSessionImpl) myDebugProcess.getSession();
        ApplicationManager.getApplication().runReadAction(() -> {
            session.reset();
            session.initBreakpoints();
        });
        addRequest(() -> myVmService.setExceptionPauseMode(isolateRef.getId(), myDebugProcess.getBreakOnExceptionMode(), new SetExceptionPauseModeConsumer() {

            @Override
            public void received(Success response) {
                setInitialBreakpointsAndCheckExtensions(isolateRef, isolate);
            }

            @Override
            public void onError(RPCError error) {
            }

            @Override
            public void received(Sentinel response) {
            }
        }));
    }
}
Also used : Sentinel(org.dartlang.vm.service.element.Sentinel) RPCError(org.dartlang.vm.service.element.RPCError) SetExceptionPauseModeConsumer(org.dartlang.vm.service.consumer.SetExceptionPauseModeConsumer) Success(org.dartlang.vm.service.element.Success) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Example 3 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method getCachedIsolate.

public CompletableFuture<Isolate> getCachedIsolate(@NotNull final String isolateId) {
    return myIsolatesInfo.getCachedIsolate(isolateId, () -> {
        final CompletableFuture<Isolate> isolateFuture = new CompletableFuture<>();
        getIsolate(isolateId, new GetIsolateConsumer() {

            @Override
            public void onError(RPCError error) {
                isolateFuture.completeExceptionally(new RuntimeException(error.getMessage()));
            }

            @Override
            public void received(Isolate response) {
                isolateFuture.complete(response);
            }

            @Override
            public void received(Sentinel response) {
                // Unable to get the isolate.
                isolateFuture.complete(null);
            }
        });
        return isolateFuture;
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GetIsolateConsumer(org.dartlang.vm.service.consumer.GetIsolateConsumer) Sentinel(org.dartlang.vm.service.element.Sentinel) Isolate(org.dartlang.vm.service.element.Isolate) RPCError(org.dartlang.vm.service.element.RPCError)

Example 4 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method doSetBreakpointsForIsolate.

private void doSetBreakpointsForIsolate(@NotNull final Set<XLineBreakpoint<XBreakpointProperties>> xBreakpoints, @NotNull final String isolateId, @Nullable final Runnable onFinished) {
    if (xBreakpoints.isEmpty()) {
        if (onFinished != null) {
            onFinished.run();
        }
        return;
    }
    final AtomicInteger counter = new AtomicInteger(xBreakpoints.size());
    for (final XLineBreakpoint<XBreakpointProperties> xBreakpoint : xBreakpoints) {
        addBreakpoint(isolateId, xBreakpoint.getSourcePosition(), new VmServiceConsumers.BreakpointsConsumer() {

            @Override
            void sourcePositionNotApplicable() {
                myBreakpointHandler.breakpointFailed(xBreakpoint);
                checkDone();
            }

            @Override
            void received(List<Breakpoint> breakpointResponses, List<RPCError> errorResponses) {
                if (breakpointResponses.size() > 0) {
                    for (Breakpoint breakpoint : breakpointResponses) {
                        myBreakpointHandler.vmBreakpointAdded(xBreakpoint, isolateId, breakpoint);
                    }
                } else if (errorResponses.size() > 0) {
                    myBreakpointHandler.breakpointFailed(xBreakpoint);
                }
                checkDone();
            }

            private void checkDone() {
                if (counter.decrementAndGet() == 0 && onFinished != null) {
                    onFinished.run();
                    myVmService.getIsolate(isolateId, new GetIsolateConsumer() {

                        @Override
                        public void received(Isolate response) {
                            final Set<String> libraryUris = new HashSet<>();
                            final Set<String> fileNames = new HashSet<>();
                            for (LibraryRef library : response.getLibraries()) {
                                final String uri = library.getUri();
                                libraryUris.add(uri);
                                final String[] split = uri.split("/");
                                fileNames.add(split[split.length - 1]);
                            }
                            final ElementList<Breakpoint> breakpoints = response.getBreakpoints();
                            if (breakpoints.isEmpty()) {
                                return;
                            }
                            final Set<CanonicalBreakpoint> mappedCanonicalBreakpoints = new HashSet<>();
                            for (Breakpoint breakpoint : breakpoints) {
                                Object location = breakpoint.getLocation();
                                // In JIT mode, locations will be unresolved at this time since files aren't compiled until they are used.
                                if (location instanceof UnresolvedSourceLocation) {
                                    final ScriptRef script = ((UnresolvedSourceLocation) location).getScript();
                                    if (script != null && libraryUris.contains(script.getUri())) {
                                        mappedCanonicalBreakpoints.add(breakpointNumbersToCanonicalMap.get(breakpoint.getBreakpointNumber()));
                                    }
                                }
                            }
                            final Analytics analytics = FlutterInitializer.getAnalytics();
                            final String category = "breakpoint";
                            final Sets.SetView<CanonicalBreakpoint> initialDifference = Sets.difference(canonicalBreakpoints, mappedCanonicalBreakpoints);
                            final Set<CanonicalBreakpoint> finalDifference = new HashSet<>();
                            for (CanonicalBreakpoint missingBreakpoint : initialDifference) {
                                // built. So it's okay to ignore these breakpoints in our count.
                                if (fileNames.contains(missingBreakpoint.fileName)) {
                                    finalDifference.add(missingBreakpoint);
                                }
                            }
                            analytics.sendEventMetric(category, "unmapped-count", finalDifference.size());
                            // For internal bazel projects, report files where mapping failed.
                            if (WorkspaceCache.getInstance(myDebugProcess.getSession().getProject()).isBazel()) {
                                for (CanonicalBreakpoint canonicalBreakpoint : finalDifference) {
                                    if (canonicalBreakpoint.path.contains("google3")) {
                                        analytics.sendEvent(category, String.format("unmapped-file|%s|%s", response.getRootLib().getUri(), canonicalBreakpoint.path));
                                    }
                                }
                            }
                        }

                        @Override
                        public void received(Sentinel response) {
                        }

                        @Override
                        public void onError(RPCError error) {
                        }
                    });
                }
            }
        });
    }
}
Also used : GetIsolateConsumer(org.dartlang.vm.service.consumer.GetIsolateConsumer) Sets(com.google.common.collect.Sets) HashSet(java.util.HashSet) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint) Sentinel(org.dartlang.vm.service.element.Sentinel) LibraryRef(org.dartlang.vm.service.element.LibraryRef) RPCError(org.dartlang.vm.service.element.RPCError) Analytics(io.flutter.analytics.Analytics) XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Isolate(org.dartlang.vm.service.element.Isolate) UnresolvedSourceLocation(org.dartlang.vm.service.element.UnresolvedSourceLocation) ScriptRef(org.dartlang.vm.service.element.ScriptRef)

Example 5 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method getScriptSync.

@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();
}
Also used : Script(org.dartlang.vm.service.element.Script) Sentinel(org.dartlang.vm.service.element.Sentinel) Obj(org.dartlang.vm.service.element.Obj) GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) RPCError(org.dartlang.vm.service.element.RPCError) Semaphore(com.intellij.util.concurrency.Semaphore) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RPCError (org.dartlang.vm.service.element.RPCError)7 Sentinel (org.dartlang.vm.service.element.Sentinel)7 ArrayList (java.util.ArrayList)3 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)2 GetIsolateConsumer (org.dartlang.vm.service.consumer.GetIsolateConsumer)2 Breakpoint (org.dartlang.vm.service.element.Breakpoint)2 Isolate (org.dartlang.vm.service.element.Isolate)2 Sets (com.google.common.collect.Sets)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 XBreakpointProperties (com.intellij.xdebugger.breakpoints.XBreakpointProperties)1 XExecutionStack (com.intellij.xdebugger.frame.XExecutionStack)1 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)1 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)1 Analytics (io.flutter.analytics.Analytics)1 DartAsyncMarkerFrame (io.flutter.vmService.frame.DartAsyncMarkerFrame)1 DartVmServiceStackFrame (io.flutter.vmService.frame.DartVmServiceStackFrame)1 HashSet (java.util.HashSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AddBreakpointWithScriptUriConsumer (org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer)1