Search in sources :

Example 1 with Breakpoint

use of org.dartlang.vm.service.element.Breakpoint 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 2 with Breakpoint

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

the class CanonicalBreakpoint method addBreakpoint.

public void addBreakpoint(@NotNull final String isolateId, @Nullable final XSourcePosition position, @NotNull final VmServiceConsumers.BreakpointsConsumer consumer) {
    if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) {
        consumer.sourcePositionNotApplicable();
        return;
    }
    addRequest(() -> {
        final int line = position.getLine() + 1;
        final Collection<String> scriptUris = myDebugProcess.getUrisForFile(position.getFile());
        final CanonicalBreakpoint canonicalBreakpoint = new CanonicalBreakpoint(position.getFile().getName(), position.getFile().getCanonicalPath(), line);
        canonicalBreakpoints.add(canonicalBreakpoint);
        final List<Breakpoint> breakpointResponses = new ArrayList<>();
        final List<RPCError> errorResponses = new ArrayList<>();
        for (String uri : scriptUris) {
            myVmService.addBreakpointWithScriptUri(isolateId, uri, line, new AddBreakpointWithScriptUriConsumer() {

                @Override
                public void received(Breakpoint response) {
                    breakpointResponses.add(response);
                    breakpointNumbersToCanonicalMap.put(response.getBreakpointNumber(), canonicalBreakpoint);
                    checkDone();
                }

                @Override
                public void received(Sentinel response) {
                    checkDone();
                }

                @Override
                public void onError(RPCError error) {
                    errorResponses.add(error);
                    checkDone();
                }

                private void checkDone() {
                    if (scriptUris.size() == breakpointResponses.size() + errorResponses.size()) {
                        consumer.received(breakpointResponses, errorResponses);
                    }
                }
            });
        }
    });
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint) AddBreakpointWithScriptUriConsumer(org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer) Sentinel(org.dartlang.vm.service.element.Sentinel) ArrayList(java.util.ArrayList) RPCError(org.dartlang.vm.service.element.RPCError) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint)

Example 3 with Breakpoint

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

the class CanonicalBreakpoint method handleDebuggerConnected.

public void handleDebuggerConnected() {
    streamListen(VmService.DEBUG_STREAM_ID, new VmServiceConsumers.SuccessConsumerWrapper() {

        @Override
        public void received(final Success success) {
            myVmServiceReceiverThreadId = Thread.currentThread().getId();
            streamListen(VmService.ISOLATE_STREAM_ID, new VmServiceConsumers.SuccessConsumerWrapper() {

                @Override
                public void received(final Success success) {
                    getVm(new VmServiceConsumers.VmConsumerWrapper() {

                        @Override
                        public void received(final VM vm) {
                            for (final IsolateRef isolateRef : vm.getIsolates()) {
                                getIsolate(isolateRef.getId(), new VmServiceConsumers.GetIsolateConsumerWrapper() {

                                    @Override
                                    public void received(final Isolate isolate) {
                                        final Event event = isolate.getPauseEvent();
                                        final EventKind eventKind = event.getKind();
                                        // yet, and we'll get lifecycle events for them later.
                                        if (eventKind == EventKind.None) {
                                            return;
                                        }
                                        // This is the entry point for attaching a debugger to a running app.
                                        if (eventKind == EventKind.Resume) {
                                            attachIsolate(isolateRef, isolate);
                                            return;
                                        }
                                        // if event is not PauseStart it means that PauseStart event will follow later and will be handled by listener
                                        handleIsolate(isolateRef, eventKind == EventKind.PauseStart);
                                        // Handle the case of isolates paused when we connect (this can come up in remote debugging).
                                        if (eventKind == EventKind.PauseBreakpoint || eventKind == EventKind.PauseException || eventKind == EventKind.PauseInterrupted) {
                                            myDebugProcess.isolateSuspended(isolateRef);
                                            ApplicationManager.getApplication().executeOnPooledThread(() -> {
                                                final ElementList<Breakpoint> breakpoints = eventKind == EventKind.PauseBreakpoint ? event.getPauseBreakpoints() : null;
                                                final InstanceRef exception = eventKind == EventKind.PauseException ? event.getException() : null;
                                                myVmServiceListener.onIsolatePaused(isolateRef, breakpoints, exception, event.getTopFrame(), event.getAtAsyncSuspension());
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint) InstanceRef(org.dartlang.vm.service.element.InstanceRef) IsolateRef(org.dartlang.vm.service.element.IsolateRef) EventKind(org.dartlang.vm.service.element.EventKind) Success(org.dartlang.vm.service.element.Success) VM(org.dartlang.vm.service.element.VM) Isolate(org.dartlang.vm.service.element.Isolate) Event(org.dartlang.vm.service.element.Event)

Aggregations

XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)3 Breakpoint (org.dartlang.vm.service.element.Breakpoint)3 Isolate (org.dartlang.vm.service.element.Isolate)2 RPCError (org.dartlang.vm.service.element.RPCError)2 Sentinel (org.dartlang.vm.service.element.Sentinel)2 Sets (com.google.common.collect.Sets)1 XBreakpointProperties (com.intellij.xdebugger.breakpoints.XBreakpointProperties)1 Analytics (io.flutter.analytics.Analytics)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AddBreakpointWithScriptUriConsumer (org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer)1 GetIsolateConsumer (org.dartlang.vm.service.consumer.GetIsolateConsumer)1 Event (org.dartlang.vm.service.element.Event)1 EventKind (org.dartlang.vm.service.element.EventKind)1 InstanceRef (org.dartlang.vm.service.element.InstanceRef)1 IsolateRef (org.dartlang.vm.service.element.IsolateRef)1 LibraryRef (org.dartlang.vm.service.element.LibraryRef)1 ScriptRef (org.dartlang.vm.service.element.ScriptRef)1 Success (org.dartlang.vm.service.element.Success)1