Search in sources :

Example 26 with IBreakpoint

use of org.eclipse.debug.core.model.IBreakpoint in project webtools.sourceediting by eclipse.

the class BreakpointRulerAction method getBreakpoints.

protected IBreakpoint[] getBreakpoints(IMarker[] markers) {
    IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
    List breakpoints = new ArrayList(markers.length);
    for (int i = 0; i < markers.length; i++) {
        IBreakpoint breakpoint = manager.getBreakpoint(markers[i]);
        if (breakpoint != null) {
            breakpoints.add(breakpoint);
        }
    }
    return (IBreakpoint[]) breakpoints.toArray(new IBreakpoint[0]);
}
Also used : ArrayList(java.util.ArrayList) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) ArrayList(java.util.ArrayList) List(java.util.List) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 27 with IBreakpoint

use of org.eclipse.debug.core.model.IBreakpoint in project webtools.sourceediting by eclipse.

the class ToggleBreakpointAction method removeBreakpoints.

protected void removeBreakpoints(int lineNumber) {
    IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
    IBreakpoint[] breakpoints = getBreakpoints(getMarkers());
    for (int i = 0; i < breakpoints.length; i++) {
        try {
            breakpointManager.removeBreakpoint(breakpoints[i], true);
        } catch (CoreException e) {
            Logger.logException(e);
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 28 with IBreakpoint

use of org.eclipse.debug.core.model.IBreakpoint in project webtools.sourceediting by eclipse.

the class JavaStratumBreakpointProvider method addBreakpoint.

public IStatus addBreakpoint(IDocument document, IEditorInput input, int editorLineNumber, int offset) throws CoreException {
    // check if there is a valid position to set breakpoint
    int pos = getValidPosition(document, editorLineNumber);
    IStatus status = null;
    if (pos >= 0) {
        IResource res = getResourceFromInput(input);
        if (res != null) {
            String path = null;
            // $NON-NLS-1$
            IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", res.getName(), path, getClassPattern(res), editorLineNumber, pos, pos, 0, true, null);
            if (point == null) {
                // $NON-NLS-1$
                status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null);
            }
        } else if (input instanceof IStorageEditorInput) {
            // For non-resources, use the workspace root and a coordinated
            // attribute that is used to
            // prevent unwanted (breakpoint) markers from being loaded
            // into the editors.
            res = ResourcesPlugin.getWorkspace().getRoot();
            String id = input.getName();
            if (input instanceof IStorageEditorInput && ((IStorageEditorInput) input).getStorage() != null && ((IStorageEditorInput) input).getStorage().getFullPath() != null) {
                id = ((IStorageEditorInput) input).getStorage().getFullPath().toString();
            }
            Map attributes = new HashMap();
            attributes.put(StructuredResourceMarkerAnnotationModel.SECONDARY_ID_KEY, id);
            String path = null;
            // $NON-NLS-1$
            IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", input.getName(), path, getClassPattern(res), editorLineNumber, pos, pos, 0, true, attributes);
            if (point == null) {
                // $NON-NLS-1$
                status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null);
            }
        }
    } else {
        status = new Status(IStatus.INFO, JSPUIPlugin.ID, IStatus.INFO, JSPUIMessages.BreakpointNotAllowed, null);
    }
    if (status == null) {
        status = new Status(IStatus.OK, JSPUIPlugin.ID, IStatus.OK, JSPUIMessages.OK, null);
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) HashMap(java.util.HashMap) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) HashMap(java.util.HashMap) Map(java.util.Map) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IResource(org.eclipse.core.resources.IResource)

Example 29 with IBreakpoint

use of org.eclipse.debug.core.model.IBreakpoint in project liferay-ide by liferay.

the class FMDebugTarget method addRemoteBreakpoints.

public void addRemoteBreakpoints(final Debugger debugger, final IBreakpoint[] bps) throws RemoteException {
    final List<Breakpoint> remoteBps = new ArrayList<Breakpoint>();
    for (IBreakpoint bp : bps) {
        final int line = bp.getMarker().getAttribute(IMarker.LINE_NUMBER, -1);
        final String templateName = bp.getMarker().getAttribute(ILRDebugConstants.FM_TEMPLATE_NAME, null);
        final String remoteTemplateName = createRemoteTemplateName(templateName);
        if (!CoreUtil.isNullOrEmpty(remoteTemplateName) && line > -1) {
            remoteBps.add(new Breakpoint(remoteTemplateName, line));
        }
    }
    final Job job = new Job("add remote breakpoints") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus retval = null;
            for (Breakpoint bp : remoteBps) {
                try {
                    debugger.addBreakpoint(bp);
                } catch (RemoteException e) {
                    retval = PortalCore.createErrorStatus(NLS.bind("Could not add remote breakpoint: {0}:{1}", new Object[] { bp.getTemplateName(), bp.getLine() }), e);
                    if (retval != Status.OK_STATUS) {
                        PortalCore.logError(retval.getMessage());
                    }
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : Breakpoint(freemarker.debug.Breakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) Job(org.eclipse.core.runtime.jobs.Job) RemoteException(java.rmi.RemoteException) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) Breakpoint(freemarker.debug.Breakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 30 with IBreakpoint

use of org.eclipse.debug.core.model.IBreakpoint in project liferay-ide by liferay.

the class FMDebugTarget method step.

/*
     * Since current fm debugger doens't have native stepping we must emulate stepping with following steps.
     *
     * 1. Starting at the current stopped line, continue going down the template file to find a
     *    suitable line to stop, ie, a addBreakpoint() that doesn't throw an exception.
     * 2. For the next line if there is already a breakpoint, simply call resume(),
     * 3. If there is no breakpoint already installed, add another one to the next line if that line has a valid
     *    breakpoint location, then resume().
     * 4. Once the next breakpoint is hit, we need to remove the previously added step breakpoint
     */
@SuppressWarnings({ "rawtypes" })
void step(FMThread thread) throws DebugException {
    int currentLineNumber = -1;
    String templateName = null;
    Breakpoint existingStepBp = null;
    final IBreakpoint[] breakpoints = thread.getBreakpoints();
    if (breakpoints.length > 0) {
        try {
            ILineBreakpoint bp = (ILineBreakpoint) breakpoints[0];
            currentLineNumber = bp.getLineNumber();
            templateName = bp.getMarker().getAttribute(ILRDebugConstants.FM_TEMPLATE_NAME, "");
        } catch (CoreException e) {
            PortalCore.logError("Could not get breakpoint information.", e);
        }
    } else {
        existingStepBp = thread.getStepBreakpoint();
        currentLineNumber = existingStepBp.getLine();
        templateName = existingStepBp.getTemplateName();
    }
    if (currentLineNumber > -1 && templateName != null) {
        final String remoteTemplateName = createRemoteTemplateName(templateName);
        int stepLine = currentLineNumber + 1;
        Breakpoint existingBp = null;
        Debugger debugCli = getDebuggerClient();
        try {
            List remoteBps = debugCli.getBreakpoints(remoteTemplateName);
            for (Iterator i = remoteBps.iterator(); i.hasNext(); ) {
                Breakpoint remoteBp = (Breakpoint) i.next();
                if (remoteBp.getLine() == stepLine) {
                    existingBp = remoteBp;
                    break;
                }
            }
            if (existingBp == null) {
                boolean addedRemote = false;
                while (!addedRemote) {
                    Breakpoint newBp = new Breakpoint(remoteTemplateName, stepLine++);
                    try {
                        debugCli.addBreakpoint(newBp);
                    } catch (RemoteException e) {
                    // we except to get some remote exceptions if the next line is invalid breakpoint location
                    }
                    List updatedRemoteBps = debugCli.getBreakpoints(remoteTemplateName);
                    if (// our new remote bp was sucessfully added
                    updatedRemoteBps.size() == remoteBps.size() + 1) {
                        addedRemote = true;
                        thread.setStepBreakpoint(newBp);
                        thread.setStepping(true);
                        fireResumeEvent(DebugEvent.RESUME);
                        if (existingStepBp != null) {
                            debugCli.removeBreakpoint(existingStepBp);
                        }
                        thread.getEnvironment().resume();
                    }
                }
            } else {
                // the next line already has a remote breakpoint installed so lets clear our "step" breakpoint
                thread.setStepBreakpoint(null);
                thread.setStepping(false);
                fireResumeEvent(DebugEvent.RESUME);
                if (existingStepBp != null) {
                    debugCli.removeBreakpoint(existingStepBp);
                }
                thread.getEnvironment().resume();
            }
        } catch (RemoteException e) {
            PortalCore.logError("Unable to check remote breakpoints", e);
        }
    } else {
        PortalCore.logError("Unable to step because of missing lineNumber or templateName information.");
    }
}
Also used : Debugger(freemarker.debug.Debugger) Breakpoint(freemarker.debug.Breakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) ArrayList(java.util.ArrayList) List(java.util.List) RemoteException(java.rmi.RemoteException) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) Breakpoint(freemarker.debug.Breakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Aggregations

IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)36 CoreException (org.eclipse.core.runtime.CoreException)12 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)12 Breakpoint (nl.tudelft.watchdog.core.logic.breakpoint.Breakpoint)9 IResource (org.eclipse.core.resources.IResource)9 ILineBreakpoint (org.eclipse.debug.core.model.ILineBreakpoint)9 ArrayList (java.util.ArrayList)6 IJavaBreakpoint (org.eclipse.jdt.debug.core.IJavaBreakpoint)6 IJavaLineBreakpoint (org.eclipse.jdt.debug.core.IJavaLineBreakpoint)6 IStatus (org.eclipse.core.runtime.IStatus)5 ITextSelection (org.eclipse.jface.text.ITextSelection)5 Test (org.junit.Test)5 Breakpoint (freemarker.debug.Breakpoint)4 IMarker (org.eclipse.core.resources.IMarker)4 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)4 ErlangLineBreakpoint (org.erlide.backend.debug.ErlangLineBreakpoint)4 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3