/** * Notifies this listener that the given breakpoint has been added to the breakpoint manager. * * @param breakpoint the added breakpoint * @since 2.0 */ public void breakpointAdded(IBreakpoint breakpoint) { if (!isAvailable()) { return; } if (supportsBreakpoint(breakpoint)) { try { if (breakpoint.isEnabled()) { // only add the breakpoint to the debugger when the // breakpoint is enabled int linenumber = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1); // TODO: get marker language type or get language from the // resource IResource r = breakpoint.getMarker().getResource(); String pRel = r.getProjectRelativePath().toOSString(); String filename = pRel; if (linenumber > 0) { // only linenumbers greater than 0 are valid as // linenumber is 1-based // convert the Eclipse breakpoint to an internal // representation of breakpoints AbstractBreakPoint bp = createBreakpoint(filename, linenumber); if (bp != null) { this.getVMContainer().addBreakpoint(bp); } } } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
@Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { AbstractTextEditor editor = getEditor(part); if (editor != null) { IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine() + 1; IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_ID); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber) { breakpoint.delete(); return; } } } DartBreakpoint breakpoint = new DartBreakpoint(resource, lineNumber); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); } }
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { if (part instanceof IEditorPart) { IEditorPart editor = (IEditorPart) part; IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (breakpoint.getMarker().getType().equals(IDroolsDebugConstants.DROOLS_MARKER_TYPE)) { if (((DroolsLineBreakpoint) breakpoint).getDRLLineNumber() == (lineNumber + 1)) { breakpoint.delete(); return; } } } } // TODO: drools breakpoints can only be created in functions and consequences DroolsLineBreakpoint lineBreakpoint = new DroolsLineBreakpoint(resource, lineNumber + 1); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); } }
public IBreakpoint findIBreakpoint(String filename, int lineNumber) { IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(this.debugServiceFactory.getLIConstants().getDebugModel()); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (supportsBreakpoint(breakpoint)) { try { if (breakpoint.isEnabled()) { // only add the breakpoint to the debugger when the // breakpoint is enabled int l = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1); // TODO: get marker language type or get language from // the resource IResource r = breakpoint.getMarker().getResource(); String location = r.getProjectRelativePath().toOSString(); if (l > 0) { // only linenumbers greater than 0 are valid as // linenumber is 1-based if (location.equals(filename) && lineNumber == l) { return breakpoint; } } } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; }
protected void toggleWatchpoint( IResource resource, int lineNumber, String fcn, String var, boolean access, boolean modification) throws CoreException { // look for existing watchpoint to delete IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (breakpoint instanceof PDAWatchpoint && resource.equals(breakpoint.getMarker().getResource())) { PDAWatchpoint watchpoint = (PDAWatchpoint) breakpoint; String otherVar = watchpoint.getVariableName(); String otherFcn = watchpoint.getFunctionName(); if (otherVar.equals(var) && otherFcn.equals(fcn)) { breakpoint.delete(); return; } } } // create watchpoint PDAWatchpoint watchpoint = new PDAWatchpoint(resource, lineNumber + 1, fcn, var, access, modification); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(watchpoint); }
/* (non-Javadoc) * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { IEditorPart editorPart = (IEditorPart) part; IEditorInput editorInput = editorPart.getEditorInput(); IResource resource = null; if (editorInput instanceof IFileEditorInput) { resource = ((IFileEditorInput) editorInput).getFile(); } if (resource == null) { Display.getCurrent().beep(); return; } ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) { DebugUITools.deleteBreakpoints( new IBreakpoint[] {breakpoint}, part.getSite().getShell(), null); return; } } } // create line breakpoint (doc line numbers start at 0) new AntLineBreakpoint(resource, lineNumber + 1); }
/* (non-Javadoc) * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ @Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { ITextEditor textEditor = getEditor(part); if (textEditor != null) { IResource resource = textEditor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) { // remove breakpoint.delete(); return; } } } // create line breakpoint (doc line numbers start at 0) PDALineBreakpoint lineBreakpoint = new PDALineBreakpoint(resource, lineNumber + 1); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); } }
public void enableLineBreakpoint(IFile file, int lineNumber) throws CoreException { try { IBreakpoint lineBkpt = findStratumBreakpoint(file, lineNumber); if (lineBkpt != null) { lineBkpt.setEnabled(true); } } catch (CoreException e) { e.printStackTrace(); } }
public void clearLineBreakpoint(IFile file, int lineNumber) throws CoreException { try { IBreakpoint lineBkpt = findStratumBreakpoint(file, lineNumber); if (lineBkpt != null) { lineBkpt.delete(); } } catch (CoreException e) { e.printStackTrace(); } }
protected void collectBrakePoint(IResource resource) throws CoreException { fBreakpoints = new BucketMap<IResource, IBreakpoint>(6); fBreakpointAttributes = new HashMap<IBreakpoint, Map<String, Object>>(6); final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); IMarker[] markers = resource.findMarkers(IBreakpoint.LINE_BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); for (IMarker marker : markers) { IResource markerResource = marker.getResource(); IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker); if (breakpoint != null) { fBreakpoints.add(markerResource, breakpoint); fBreakpointAttributes.put(breakpoint, breakpoint.getMarker().getAttributes()); } } }
/* * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) */ @Override public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { Annotation a = findAnnotation(breakpoint.getMarker()); if (a != null) { removeAnnotation(a, true); } }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.IAction#run() */ public void run() { try { /* * Test if there are any markers at the current position. * if there are any, remove breakpointmarker, otherwise create a * new one. */ List list = getMarkers(); if (list.isEmpty()) { // create new markers IDocument document = getDocument(); int lineNumber = getVerticalRulerInfo().getLineOfLastMouseButtonActivity(); if (lineNumber >= document.getNumberOfLines()) { return; } try { IRegion line = document.getLineInformation(lineNumber); ITextSelection selection = new TextSelection(document, line.getOffset(), line.getLength()); // fBreakpointAdapter.toggleLineBreakpoints(fTextEditor, selection); fBreakpointAdapter.toggleBreakpoints(fTextEditor, selection); } catch (BadLocationException e) { // likely document is folded so you cannot get the line information of the folded line } } else { // remove existing breakpoints of any type IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); Iterator iterator = list.iterator(); while (iterator.hasNext()) { IMarker marker = (IMarker) iterator.next(); IBreakpoint breakpoint = manager.getBreakpoint(marker); if (breakpoint != null) { breakpoint.delete(); } } } } catch (CoreException e) { // JDIDebugUIPlugin.errorDialog(ActionMessages.getString("ManageBreakpointRulerAction.error.adding.message1"), e); //$NON-NLS-1$ // JDIDebugUIPlugin.errorDialog(ActionMessages.ManageBreakpointRulerAction_error_adding_message1, e); // This message may not make sense FIXME JDIDebugUIPlugin.errorDialog( ActionMessages.ManageMethodBreakpointActionDelegate_methodNonAvailable, e); } }
@Override public void run() { if (breakpoint != null) { try { breakpoint.delete(); } catch (CoreException e) { SDBGDebugUIPlugin.logError(e); } } }
/** * Compares two breakpoints. * * @param b1 * @param b2 * @return */ private int doCompare(IBreakpoint b1, IBreakpoint b2) { String text1 = IInternalDebugCoreConstants.EMPTY_STRING; String text2 = IInternalDebugCoreConstants.EMPTY_STRING; text1 += b1.getModelIdentifier(); text2 += b2.getModelIdentifier(); IMarker marker1 = b1.getMarker(); IMarker marker2 = b2.getMarker(); try { if (marker1.exists() && marker2.exists()) { text1 += SPACE + marker1.getType(); text2 += SPACE + marker2.getType(); } } catch (CoreException e) { DebugUIPlugin.log(e); } int result = text1.compareTo(text2); if (result != 0) { return result; } // model and type are the same if (fContext != null) { String name1 = fContext.getModelPresentation().getText(b1); String name2 = fContext.getModelPresentation().getText(b2); boolean lineBreakpoint = false; try { lineBreakpoint = marker1.isSubtypeOf(IBreakpoint.LINE_BREAKPOINT_MARKER); } catch (CoreException ce) { } if (lineBreakpoint) { return compareLineBreakpoints(b1, b2, name1, name2); } return name1.compareTo(name2); } return result; }
/** * Notifies this listener that the given breakpoint has been removed from the breakpoint manager. * If the given breakpoint has been removed because it has been deleted, the associated marker * delta is also provided. * * @param breakpoint the removed breakpoint * @param delta the associated marker delta, or <code>null</code> when the breakpoint is removed * from the breakpoint manager without being deleted * @see org.eclipse.core.resources.IMarkerDelta * @since 2.0 */ public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { if (!isAvailable()) { return; } if (supportsBreakpoint(breakpoint)) { // convert IBreakpoint to AbstractBreakPoint Breakpoint int linenumber = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1); IResource r = breakpoint.getMarker().getResource(); String pRel = r.getProjectRelativePath().toOSString(); String filename = pRel; if (linenumber > 0) { // only linenumbers greater than 0 are valid as linenumber is // 1-based AbstractBreakPoint bp = createBreakpoint(filename, linenumber); if (bp != null) { this.getVMContainer().removeBreakpoint(bp); } } } }
public static List<String> addBreakpointProjectsAndModules( final Collection<IProject> projects, final Collection<String> interpretedModules2) { final IBreakpointManager bpm = DebugPlugin.getDefault().getBreakpointManager(); final List<String> result = Lists.newArrayList(interpretedModules2); for (final IBreakpoint bp : bpm.getBreakpoints(ErlDebugConstants.ID_ERLANG_DEBUG_MODEL)) { final IMarker m = bp.getMarker(); final IResource r = m.getResource(); final String name = r.getName(); if (ModuleKind.hasErlExtension(name)) { final IProject p = r.getProject(); if (projects.contains(p)) { final String s = p.getName() + ":" + name; if (!result.contains(s)) { result.add(s); } } } } return result; }
/** * Returns true whether this target can install the given breakpoint. We have to make sure the * language ids match */ public boolean supportsBreakpoint(IBreakpoint breakpoint) { if (breakpoint .getModelIdentifier() .equals(this.debugServiceFactory.getLIConstants().getDebugModel())) { // TODO: JDIDebugTarget implements this as <code>return breakpoint // instanceof IJavaBreakpoint;</code> return true; } else { return false; } }
/** * Notifies this listener that an attribute of the given breakpoint has changed, as described by * the delta. * * @param breakpoint the changed breakpoint * @param delta the marker delta that describes the changes with the marker associated with the * given breakpoint, or <code>null</code> when the breakpoint change does not generate a * marker delta * @see org.eclipse.core.resources.IMarkerDelta */ public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { if (supportsBreakpoint(breakpoint)) { try { if (breakpoint.isEnabled()) { breakpointAdded(breakpoint); } else { breakpointRemoved(breakpoint, null); } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/* * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) */ @Override public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { Annotation a = findAnnotation(breakpoint.getMarker()); if (a != null) { if (a instanceof SimpleMarkerAnnotation) { ((SimpleMarkerAnnotation) a).update(); } synchronized (getLockObject()) { getAnnotationModelEvent().annotationChanged(a); } fireModelChanged(); } else { addBreakpointAnnotation(breakpoint, true); } }
private boolean hidePlantingAnnotation(IAnnotationModel model, IBreakpoint bp, Position p) { // Check if a breakpoint annotation does not need to be shown // since it has same position as the breakpoint marker. @SuppressWarnings("rawtypes") Iterator i = model.getAnnotationIterator(); while (i.hasNext()) { Annotation a = (Annotation) i.next(); if (a instanceof MarkerAnnotation) { Position q = model.getPosition(a); if (q != null && p.getOffset() == q.getOffset()) { if (bp.getMarker().equals(((MarkerAnnotation) a).getMarker())) return true; } } } return false; }
private void addBreakpointAnnotation(IBreakpoint breakpoint, boolean fireEvent) { if (fDocument == null) { return; } final IMarker marker = breakpoint.getMarker(); if (marker == null) { return; } try { Position position = createPositionFromBreakpoint(breakpoint); if (position != null) { addAnnotation(new MarkerAnnotation(marker), position, fireEvent); } } catch (CoreException exc) { // ignore problems accessing attributes } catch (BadLocationException exc) { // ignore wrong positions } }
private Position createPositionFromBreakpoint(IBreakpoint breakpoint) throws CoreException { IBreakpointLocationProvider locationProvider = breakpoint.getAdapter(IBreakpointLocationProvider.class); /* if there is a location provider, than use the provider to retrieve the location */ if (locationProvider != null) { /* if there is source info, than create a source line position */ String sourceFile = locationProvider.getSourceFile(breakpoint, fDebugContext); if (sourceFile != null) { int lineNumber = locationProvider.getLineNumber(breakpoint, fDebugContext) - 1; return createPositionFromSourceLine(sourceFile, lineNumber); } else { /* if there is label info, than create a label position */ IAddress labelAddress = locationProvider.getLabelAddress(breakpoint, fDebugContext); if (labelAddress != null) { return createPositionFromLabel(labelAddress.getValue()); /* Otherwise, create an address position */ } else { // See bug 300053 comment 5: // Since there can only be one annotation per marker and in order to support multiple // annotations per breakpoint, we need a specialized annotation type. // // So for now, we only create an annotation for the first valid address. We can add // support for multiple annotations per breakpoint when it's needed. IAddress[] addresses = locationProvider.getAddresses(breakpoint, fDebugContext); for (int i = 0; addresses != null && i < addresses.length; ++i) { BigInteger address = addresses[i].getValue(); Position position = createPositionFromAddress(address); if (position != null) return position; } } } /* otherwise, use legacy ICBreakpoint location info */ } else { if (breakpoint instanceof ICAddressBreakpoint) { ICAddressBreakpoint addressBreakpoint = (ICAddressBreakpoint) breakpoint; return createPositionFromAddress(decodeAddress(addressBreakpoint.getAddress())); } else if (breakpoint instanceof ILineBreakpoint) { ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; Position position = null; final int lineNumber = lineBreakpoint.getLineNumber() - 1; final IMarker marker = breakpoint.getMarker(); if (marker.getResource().getType() == IResource.FILE) { position = createPositionFromSourceLine((IFile) marker.getResource(), lineNumber); if (position != null) { return position; } } String fileName = marker.getAttribute(ICLineBreakpoint.SOURCE_HANDLE, null); position = createPositionFromSourceLine(fileName, lineNumber); if (position == null && breakpoint instanceof ICLineBreakpoint) { ICLineBreakpoint cBreakpoint = (ICLineBreakpoint) breakpoint; if (breakpoint instanceof ICFunctionBreakpoint) { position = createPositionFromLabel(cBreakpoint.getFunction()); } else { position = createPositionFromAddress(decodeAddress(cBreakpoint.getAddress())); } } return position; } } return null; }
@Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { TextSelection textSelection = (TextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); if (part instanceof IEditorPart) { IEditorPart editor = (IEditorPart) part; IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); if (resource != null) { for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) { breakpoint.delete(); return; } } } String path = ClojureCore.getAsRootClasspathRelativePath((IFile) resource).substring(1); JDIDebugModel.createStratumBreakpoint( resource, "Clojure", resource.getName(), path, null, lineNumber + 1, -1, -1, 0, true, null); } else { // Do it "the hard way" by using the WorkspaceRoot as the host for our breakpoint // ... quick analysis seems to indicate it's done this way by the JDT "itself" ! IStorageEditorInput input = (IStorageEditorInput) editor.getEditorInput(); IStorage storage = input.getStorage(); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (breakpoint instanceof IJavaStratumLineBreakpoint) { IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) breakpoint; if (storage .getFullPath() .toPortableString() .equals(stratumBreakpoint.getSourcePath())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) { breakpoint.delete(); return; } } } } Map attributes = new HashMap(); StorageMarkerAnnotationModel.addAttribute(attributes, storage); System.out.println("not editor part resource"); JDIDebugModel.createStratumBreakpoint( ResourcesPlugin.getWorkspace().getRoot(), "Clojure", storage.getName(), storage.getFullPath().toPortableString(), null, lineNumber + 1, -1, -1, 0, true, attributes); } } }