Search in sources :

Example 6 with Breakpoint

use of freemarker.debug.Breakpoint in project liferay-ide by liferay.

the class FMDebugTarget method resume.

@SuppressWarnings("rawtypes")
public void resume() {
    final Job job = new Job("resume") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                // need to check to see if current thread is stepping and then remove the step breakpoint
                Debugger debugger = getDebuggerClient();
                if (debugger != null) {
                    if (fmThread.isStepping()) {
                        Breakpoint stepBp = fmThread.getStepBreakpoint();
                        debugger.removeBreakpoint(stepBp);
                    }
                    for (Iterator i = debugger.getSuspendedEnvironments().iterator(); i.hasNext(); ) {
                        DebuggedEnvironment env = (DebuggedEnvironment) i.next();
                        try {
                            env.resume();
                        } catch (Exception e) {
                            PortalCore.logError("Could not resume suspended environment", e);
                        }
                    }
                    fmStackFrames = EMPTY_STACK_FRAMES;
                    resumed(DebugEvent.CLIENT_REQUEST);
                }
            } catch (RemoteException e) {
                PortalCore.logError("Could not fully resume suspended environments", e);
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : Debugger(freemarker.debug.Debugger) Breakpoint(freemarker.debug.Breakpoint) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DebuggedEnvironment(freemarker.debug.DebuggedEnvironment) Iterator(java.util.Iterator) Job(org.eclipse.core.runtime.jobs.Job) RemoteException(java.rmi.RemoteException) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) RemoteException(java.rmi.RemoteException)

Example 7 with Breakpoint

use of freemarker.debug.Breakpoint 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)

Example 8 with Breakpoint

use of freemarker.debug.Breakpoint in project liferay-ide by liferay.

the class FMDebugTarget method removeRemoteBreakpoints.

private void removeRemoteBreakpoints(final IBreakpoint[] breakpoints) {
    final List<Breakpoint> remoteBreakpoints = new ArrayList<Breakpoint>();
    for (IBreakpoint bp : breakpoints) {
        final String templateName = bp.getMarker().getAttribute(ILRDebugConstants.FM_TEMPLATE_NAME, "");
        final String remoteTemplateName = createRemoteTemplateName(templateName);
        final Breakpoint remoteBp = new Breakpoint(remoteTemplateName, bp.getMarker().getAttribute(IMarker.LINE_NUMBER, -1));
        remoteBreakpoints.add(remoteBp);
    }
    final Job job = new Job("remove remote breakpoints") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus retval = null;
            for (Breakpoint bp : remoteBreakpoints) {
                try {
                    getDebuggerClient().removeBreakpoint(bp);
                } catch (Exception e) {
                    retval = PortalCore.createErrorStatus(NLS.bind("Unable to get debug client to remove 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) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) RemoteException(java.rmi.RemoteException)

Example 9 with Breakpoint

use of freemarker.debug.Breakpoint in project freemarker by apache.

the class RmiDebuggerService method removeBreakpoint.

void removeBreakpoint(Breakpoint breakpoint) {
    String templateName = breakpoint.getTemplateName();
    synchronized (templateDebugInfos) {
        TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
        if (tdi != null) {
            List breakpoints = tdi.breakpoints;
            int pos = Collections.binarySearch(breakpoints, breakpoint);
            if (pos >= 0) {
                breakpoints.remove(pos);
                for (Iterator iter = tdi.templates.iterator(); iter.hasNext(); ) {
                    TemplateReference ref = (TemplateReference) iter.next();
                    Template t = ref.getTemplate();
                    if (t == null) {
                        iter.remove();
                    } else {
                        removeDebugBreak(t, breakpoint);
                    }
                }
            }
            if (tdi.isEmpty()) {
                templateDebugInfos.remove(templateName);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Breakpoint(freemarker.debug.Breakpoint) Template(freemarker.template.Template)

Aggregations

Breakpoint (freemarker.debug.Breakpoint)9 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)6 RemoteException (java.rmi.RemoteException)5 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 ILineBreakpoint (org.eclipse.debug.core.model.ILineBreakpoint)5 List (java.util.List)3 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 DebugException (org.eclipse.debug.core.DebugException)3 Debugger (freemarker.debug.Debugger)2 Template (freemarker.template.Template)2 IStatus (org.eclipse.core.runtime.IStatus)2 FMThread (com.liferay.ide.portal.core.debug.fm.FMThread)1 DebuggedEnvironment (freemarker.debug.DebuggedEnvironment)1 IThread (org.eclipse.debug.core.model.IThread)1