public void testSerialize() throws Exception { XLineBreakpoint<?> master = createMaster(); XLineBreakpoint<?> slave = createSlave(); myDependentBreakpointManager.setMasterBreakpoint(slave, master, true); Element element = save(); myDependentBreakpointManager.clearMasterBreakpoint(slave); // System.out.println(JDOMUtil.writeElement(element, SystemProperties.getLineSeparator())); load(element); XBreakpoint<?>[] breakpoints = myBreakpointManager.getAllBreakpoints(); assertEquals(2, breakpoints.length); XLineBreakpoint newMaster = (XLineBreakpoint) breakpoints[0]; XLineBreakpoint newSlave = (XLineBreakpoint) breakpoints[1]; assertEquals("file://master", newMaster.getFileUrl()); assertEquals("file://slave", newSlave.getFileUrl()); assertSame(newMaster, myDependentBreakpointManager.getMasterBreakpoint(newSlave)); assertTrue(myDependentBreakpointManager.isLeaveEnabled(newSlave)); }
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); } } }); } }
public void addBreakpoint( @NotNull final String isolateId, @NotNull final XLineBreakpoint<XBreakpointProperties> xBreakpoint, @NotNull final VmServiceConsumers.BreakpointConsumerWrapper consumer) { final XSourcePosition position = xBreakpoint.getSourcePosition(); if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) { consumer.sourcePositionNotApplicable(); return; } addRequest( new Runnable() { @Override public void run() { final String uri = myDebugProcess.getUriForFile(position.getFile()); final int line = position.getLine() + 1; myVmService.addBreakpointWithScriptUri(isolateId, uri, line, consumer); } }); }
public void addBreakpointForIsolates( @NotNull final XLineBreakpoint<XBreakpointProperties> xBreakpoint, @NotNull final Collection<IsolatesInfo.IsolateInfo> isolateInfos) { for (final IsolatesInfo.IsolateInfo isolateInfo : isolateInfos) { addBreakpoint( isolateInfo.getIsolateId(), xBreakpoint.getSourcePosition(), new VmServiceConsumers.BreakpointConsumerWrapper() { @Override void sourcePositionNotApplicable() {} @Override public void received(Breakpoint vmBreakpoint) { myBreakpointHandler.vmBreakpointAdded( xBreakpoint, isolateInfo.getIsolateId(), vmBreakpoint); } @Override public void onError(RPCError error) {} }); } }
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); } } }
/** * Toggle line breakpoint with editor support: - unfolds folded block on the line - if folded, * checks if line breakpoints could be toggled inside folded text */ @NotNull public static Promise toggleLineBreakpoint( @NotNull Project project, @NotNull XSourcePosition position, @Nullable Editor editor, boolean temporary, boolean moveCarret) { int lineStart = position.getLine(); VirtualFile file = position.getFile(); // for folded text check each line and find out type with the biggest priority int linesEnd = lineStart; if (editor != null) { FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart); if (region != null && !region.isExpanded()) { linesEnd = region.getDocument().getLineNumber(region.getEndOffset()); } } final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager(); XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes(); XLineBreakpointType<?> typeWinner = null; int lineWinner = -1; for (int line = lineStart; line <= linesEnd; line++) { int maxPriority = 0; for (XLineBreakpointType<?> type : lineTypes) { maxPriority = Math.max(maxPriority, type.getPriority()); final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line); if (breakpoint != null && temporary && !breakpoint.isTemporary()) { breakpoint.setTemporary(true); } else if (type.canPutAt(file, line, project) || breakpoint != null) { if (typeWinner == null || type.getPriority() > typeWinner.getPriority()) { typeWinner = type; lineWinner = line; } } } // already found max priority type - stop if (typeWinner != null && typeWinner.getPriority() == maxPriority) { break; } } if (typeWinner != null) { XSourcePosition winPosition = (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner); if (winPosition != null) { Promise<XLineBreakpoint> res = XDebuggerUtilImpl.toggleAndReturnLineBreakpoint( project, typeWinner, winPosition, temporary, editor); if (editor != null && lineStart != lineWinner) { int offset = editor.getDocument().getLineStartOffset(lineWinner); ExpandRegionAction.expandRegionAtOffset(project, editor, offset); if (moveCarret) { editor.getCaretModel().moveToOffset(offset); } } return res; } } return PromiseKt.rejectedPromise(); }