diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/BreakpointsMediator.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/BreakpointsMediator.java new file mode 100644 index 00000000000..2adec9cf43a --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/BreakpointsMediator.java @@ -0,0 +1,838 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River - Initial API and implementation + * Ericsson - Low-level breakpoints integration + *******************************************************************************/ + +package org.eclipse.dd.dsf.debug.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.RejectedExecutionException; + +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.dd.dsf.concurrent.CountingRequestMonitor; +import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.DsfRunnable; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.concurrent.ThreadSafe; +import org.eclipse.dd.dsf.datamodel.DMContexts; +import org.eclipse.dd.dsf.debug.DsfDebugPlugin; +import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointDMContext; +import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; +import org.eclipse.dd.dsf.service.AbstractDsfService; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IBreakpointListener; +import org.eclipse.debug.core.IBreakpointManager; +import org.eclipse.debug.core.IBreakpointManagerListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.osgi.framework.BundleContext; + +/** + * + */ +public class BreakpointsMediator extends AbstractDsfService implements IBreakpointManagerListener, IBreakpointListener +{ + + /** + * The attribute translator that this service will use to map the platform + * breakpiont attributes to the corresponding target attributes, and vice + * versa. + */ + private IBreakpointAttributeTranslator fAttributeTranslator; + + /** + * DSF Debug service for creating breakpoints. + */ + IBreakpoints fBreakpoints; + + /** + * Platform breakpoint manager + */ + IBreakpointManager fBreakpointManager; + + + /////////////////////////////////////////////////////////////////////////// + // Breakpoints tracking + /////////////////////////////////////////////////////////////////////////// + + /** + * Holds the set of platform breakpoints with their corresponding back-end + * breakpoint attributes, per context (i.e. each platform breakpoint is + * replicated for each execution context). + * - Context entry added/removed on start/stopTrackingBreakpoints() + * - Augmented on breakpointAdded() + * - Modified on breakpointChanged() + * - Diminished on breakpointRemoved() + */ + private Map>>> fPlatformBPs = + new HashMap>>>(); + + /** + * Holds the mapping from platform breakpoint to the corresponding target + * breakpoint(s), per context. There can be multiple back-end BPs for a + * single platform BP in the case of [1] multiple target contexts, and/or + * [2] thread filtering. + * Updated when: + * - We start/stop tracking an execution context + * - A platform breakpoint is added/removed + * - A thread filter is applied/removed + */ + private Map>> fBreakpointDMContexts = + new HashMap>>(); + + /** + * Due to the very asynchronous nature of DSF, a new breakpoint request can + * pop up at any time before an ongoing one is completed. The following set + * is used to store requests until the ongoing operation completes. + */ + private Set fPendingRequests = new HashSet(); + + /** + * @see fPendingRequests + */ + private Set fPendingBreakpoints = new HashSet(); + + /////////////////////////////////////////////////////////////////////////// + // AbstractDsfService + /////////////////////////////////////////////////////////////////////////// + + /** + * The service constructor + * + * @param session + * @param debugModelId + */ + public BreakpointsMediator(DsfSession session, IBreakpointAttributeTranslator attributeTranslator) { + super(session); + fAttributeTranslator = attributeTranslator; + } + + @Override + public void initialize(final RequestMonitor rm) { + // - Collect references for the services we interact with + // - Register to interesting events + // - Obtain the list of platform breakpoints + // - Register the service for interested parties + super.initialize( + new RequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + doInitialize(rm); + }}); + } + + /** + * Asynchronous service initialization + * + * @param requestMonitor + */ + private void doInitialize(RequestMonitor rm) { + + // Get the services references + fBreakpoints = getServicesTracker().getService(IBreakpoints.class); + fBreakpointManager = DebugPlugin.getDefault().getBreakpointManager(); + fAttributeTranslator.initialize(this); + + // Register to the useful events + fBreakpointManager.addBreakpointListener(this); + fBreakpointManager.addBreakpointManagerListener( this ); + + // Register this service + register(new String[] { BreakpointsMediator.class.getName() }, + new Hashtable()); + + rm.done(); + } + + @Override + public void shutdown(final RequestMonitor rm) { + // - Un-register the service + // - Stop listening to events + // - Remove the breakpoints installed by this service + // + // Since we are shutting down, there is no overwhelming need + // to keep the maps coherent... + + // Stop accepting requests and events + unregister(); + fBreakpointManager.removeBreakpointListener(this); + fBreakpointManager.removeBreakpointManagerListener( this ); + fAttributeTranslator.dispose(); + + // Cleanup the breakpoints that are still installed by the service. + // Use a counting monitor which will call mom to complete the shutdown + // after the breakpoints are un-installed (successfully or not). + CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm) { + @Override + protected void handleCompleted() { + BreakpointsMediator.super.shutdown(rm); + } + }; + + // We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints() + // modifies the map as it walks through it. + List platformBPKeysCopy = new ArrayList(fPlatformBPs.size()); + platformBPKeysCopy.addAll(0, fPlatformBPs.keySet()); + for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) { + stopTrackingBreakpoints(dmc, countingRm); + } + countingRm.setDoneCount(platformBPKeysCopy.size()); + } + + @Override + protected BundleContext getBundleContext() { + return DsfDebugPlugin.getBundleContext(); + } + + /////////////////////////////////////////////////////////////////////////// + // IBreakpointsManager + /////////////////////////////////////////////////////////////////////////// + + + /** + * Install and begin tracking breakpoints for given context. The service + * will keep installing new breakpoints that appear in the IDE for this + * context until {@link #uninstallBreakpoints(IDMContext)} is called for that + * context. + * @param dmc Context to start tracking breakpoints for. + * @param rm Completion callback. + */ + public void startTrackingBreakpoints(IBreakpointsTargetDMContext dmc, final RequestMonitor rm) { + // - Augment the maps with the new execution context + // - Install the platform breakpoints on the selected target + + // Validate the context + final IBreakpointsTargetDMContext breakpointsDmc = DMContexts.getAncestorOfType(dmc, IBreakpointsTargetDMContext.class); + if (breakpointsDmc == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid context type", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Make sure a mapping for this execution context does not already exist + Map>> platformBPs = fPlatformBPs.get(dmc); + if (platformBPs != null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INTERNAL_ERROR, "Context already initialized", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Create entries in the breakpoint tables for the new context. These entries should only + // be removed when this service stops tracking breakpoints for the given context. + fPlatformBPs.put(breakpointsDmc, new HashMap>>()); + fBreakpointDMContexts.put(breakpointsDmc, new HashMap>()); + + // Install the platform breakpoints (stored in fPlatformBPs) on the target. + // We need to use a background thread for this operation because we are + // accessing the resources system to retrieve the breakpoint attributes. + // Accessing the resources system potentially requires using global locks. + // Also we will be calling IBreakpointAttributeTranslator which is prohibited + // from being called on the session executor thread. + new Job("MI Debugger: Install initial breakpoint list.") { //$NON-NLS-1$ + { setSystem(true); } + + // Get the stored breakpoints from the platform BreakpointManager + // and install them on the target + @Override + protected IStatus run(IProgressMonitor monitor) { + // Read initial breakpoints from platform. Copy the breakpoint attributes into a local map. + // Note that we cannot write data into fPlatformBPs table here directly because we are not + // executing on the dispatch thread. + final Map>> initialPlatformBPs = + new HashMap>>(); + try { + // Get the stored breakpoint list from the platform BreakpointManager + IBreakpoint[] bps = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); + // Single out the installable breakpoints... + for (IBreakpoint bp : bps) { + if (fAttributeTranslator.supportsBreakpoint(bp)) { + // Retrieve the breakpoint attributes + List> attrsArray = + fAttributeTranslator.getBreakpointAttributes(bp, fBreakpointManager.isEnabled()); + // Store it for now (will be installed on the dispatcher thread) + initialPlatformBPs.put(bp, attrsArray); + } + } + } catch (CoreException e) { + IStatus status = new Status( + IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, REQUEST_FAILED, "Unable to read initial breakpoint attributes", e); //$NON-NLS-1$ + rm.setStatus(status); + rm.done(); + return status; + } + + // Submit the runnable to plant the breakpoints on dispatch thread. + getExecutor().submit(new Runnable() { + public void run() { + installInitialBreakpoints(breakpointsDmc, initialPlatformBPs, rm); + } + }); + + return Status.OK_STATUS; + } + }.schedule(); + } + + /** + * Installs the breakpoints that existed prior to the activation of this + * breakpoints context. + */ + private void installInitialBreakpoints(final IBreakpointsTargetDMContext dmc, + Map>> initialPlatformBPs, + RequestMonitor rm) + { + // Retrieve the set of platform breakpoints for this context + Map>> platformBPs = fPlatformBPs.get(dmc); + if (platformBPs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Install the individual breakpoints on the executor thread + // Requires a counting monitor to know when we're done + final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm); + countingRm.setDoneCount(platformBPs.size()); + + for (final IBreakpoint bp : initialPlatformBPs.keySet()) { + final List> attrs = initialPlatformBPs.get(bp); + // Upon determining the debuggerPath, the breakpoint is installed + installBreakpoint(dmc, bp, attrs, new RequestMonitor(getExecutor(), countingRm)); + } + } + + + public void stopTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) { + // - Remove the target breakpoints for the given execution context + // - Update the maps + + // Remove the breakpoints for given DMC from the internal maps. + Map>> platformBPs = fPlatformBPs.get(dmc); + if (platformBPs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INTERNAL_ERROR, "Breakpoints not installed for given context", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Uninstall the individual breakpoints on the executor thread + // Requires a counting monitor to know when we're done + final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm); + countingRm.setDoneCount(platformBPs.size()); + + for (final IBreakpoint bp : platformBPs.keySet()) { + uninstallBreakpoint(dmc, bp, + new RequestMonitor(getExecutor(), countingRm) { + @Override + protected void handleCompleted() { + // After the breakpoint is removed from target. Call the attribute + // translator to refresh breakpoint status based on the new target + // breakpoint status. + new Job("Breakpoint status update") { //$NON-NLS-1$ + { setSystem(true); } + @Override + protected IStatus run(IProgressMonitor monitor) { + fAttributeTranslator.updateBreakpointStatus(bp); + return Status.OK_STATUS; + }; + }.schedule(); + + countingRm.done(); + } + }); + } + } + + /////////////////////////////////////////////////////////////////////////// + // Back-end interface functions + /////////////////////////////////////////////////////////////////////////// + + /** + * Install a new platform breakpoint on the back-end. A platform breakpoint + * can resolve into multiple back-end breakpoints when threads are taken + * into account. + * + * @param dmc + * @param breakpoint + * @param attrsList + * @param rm + */ + private void installBreakpoint(IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint, + final List> attrsList, final RequestMonitor rm) + { + // Retrieve the set of breakpoints for this context + final Map>> platformBPs = fPlatformBPs.get(dmc); + assert platformBPs != null; + + final Map> breakpointIDs = fBreakpointDMContexts.get(dmc); + assert breakpointIDs != null; // fBreakpointIds should be updated in parallel with fPlatformBPs + + // Ensure the breakpoint is not already installed + if (platformBPs.containsKey(breakpoint)) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_STATE, "Breakpoint already installed", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Update the breakpoint status when all back-end breakpoints have been installed + final CountingRequestMonitor installRM = new CountingRequestMonitor(getExecutor(), rm) { + @Override + protected void handleCompleted() { + // Store the platform breakpoint + platformBPs.put(breakpoint, attrsList); + new Job("Breakpoint status update") { //$NON-NLS-1$ + { setSystem(true); } + @Override + protected IStatus run(IProgressMonitor monitor) { + fAttributeTranslator.updateBreakpointStatus(breakpoint); + return Status.OK_STATUS; + }; + }.schedule(); + rm.done(); + } + }; + + // A back-end breakpoint needs to be installed for each specified attributes map. + installRM.setDoneCount(attrsList.size()); + + // Install the back-end breakpoint(s) + for (Map attrs : attrsList) { + fBreakpoints.insertBreakpoint( + dmc, attrs, + new DataRequestMonitor(getExecutor(), installRM) { + @Override + protected void handleCompleted() { + if (getStatus().isOK()) { + // Add the breakpoint back-end mapping + List list = breakpointIDs.get(breakpoint); + if (list == null) + list = new LinkedList(); + list.add(getData()); + breakpointIDs.put(breakpoint, list); + } + installRM.done(); + } + }); + } + } + + /** + * Un-install an individual breakpoint on the back-end. For one platform + * breakpoint, there could be multiple corresponding back-end breakpoints. + * + * @param dmc + * @param breakpoint + * @param rm + */ + private void uninstallBreakpoint(final IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint, + final RequestMonitor rm) + { + // Remove completion monitor + CountingRequestMonitor removeRM = new CountingRequestMonitor(getExecutor(), rm) { + @Override + protected void handleCompleted() { + // Remove the attributes mapping + Map>> platformBPs = fPlatformBPs.get(dmc); + if (platformBPs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$ + rm.done(); + return; + } + platformBPs.remove(breakpoint); + + // Remove the back-end mapping + Map> breakpointIDs = fBreakpointDMContexts.get(dmc); + if (breakpointIDs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$ + rm.done(); + return; + } + breakpointIDs.get(breakpoint).clear(); + breakpointIDs.remove(breakpoint); + + // Update breakpoint status + new Job("Breakpoint status update") { //$NON-NLS-1$ + { setSystem(true); } + @Override + protected IStatus run(IProgressMonitor monitor) { + fAttributeTranslator.updateBreakpointStatus(breakpoint); + return Status.OK_STATUS; + }; + }.schedule(); + + rm.done(); + } + }; + + // Remove the back-end breakpoints + Map> breakpointIDs = fBreakpointDMContexts.get(dmc); + if (breakpointIDs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + List list = breakpointIDs.get(breakpoint); + int count = 0; + if (list != null) { + for (IBreakpointDMContext bp : list) { + fBreakpoints.removeBreakpoint(bp, removeRM); + } + count = list.size(); + } + removeRM.setDoneCount(count); + } + + /** + * Modify an individual breakpoint + * + * @param context + * @param breakpoint + * @param attributes + * @param rm + * @throws CoreException + */ + private void modifyBreakpoint(final IBreakpointsTargetDMContext context, final IBreakpoint breakpoint, + final List> newAttrsList0, final IMarkerDelta oldValues, final RequestMonitor rm) + { + // Get the maps + final Map>> platformBPs = fPlatformBPs.get(context); + final Map> breakpointIDs = fBreakpointDMContexts.get(context); + if (platformBPs == null || breakpointIDs == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Get the original breakpoint attributes + final List> oldAttrsList0 = platformBPs.get(breakpoint); + if (oldAttrsList0 == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Get the list of corresponding back-end breakpoints + final List oldBpContexts = new ArrayList(breakpointIDs.get(breakpoint)); + if (oldBpContexts == null) { + rm.setStatus(new Status(IStatus.ERROR, DsfDebugPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$ + rm.done(); + return; + } + + List> commonAttrsList = getCommonAttributeMaps(newAttrsList0, oldAttrsList0); + final List newBpContexts = new ArrayList(commonAttrsList.size()); + + List> newAttrsList = new ArrayList>(newAttrsList0); + newAttrsList.removeAll(commonAttrsList); + + List> oldAttrsList = new ArrayList>(oldAttrsList0); + for (int i = 0; i < oldAttrsList.size(); i++) { + if (commonAttrsList.contains(oldAttrsList.get(i))) { + newBpContexts.add(oldBpContexts.remove(i)); + } + } + + final List> attrDeltasArray = getAttributesDeltas(oldAttrsList, newAttrsList); + + final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm) { + @Override + protected void handleCompleted() { + breakpointIDs.put(breakpoint, newBpContexts); + // Update breakpoint status + new Job("Breakpoint status update") { //$NON-NLS-1$ + { setSystem(true); } + @Override + protected IStatus run(IProgressMonitor monitor) { + fAttributeTranslator.updateBreakpointStatus(breakpoint); + return Status.OK_STATUS; + }; + }.schedule(); + + super.handleCompleted(); + } + }; + + countingRM.setDoneCount(attrDeltasArray.size()); + + for (int i = 0; i < attrDeltasArray.size(); i++) { + if (attrDeltasArray.get(i) == null) { + fBreakpoints.removeBreakpoint(oldBpContexts.get(i), countingRM); + } else if ( i >= oldBpContexts.size()) { + final Map attrs = newAttrsList.get(i); + fBreakpoints.insertBreakpoint( + context, attrs, + new DataRequestMonitor(getExecutor(), countingRM) { + @Override + protected void handleOK() { + newBpContexts.add(getData()); + countingRM.done(); + } + }); + } else if ( !fAttributeTranslator.canUpdateAttributes(oldBpContexts.get(i), attrDeltasArray.get(i)) ) { + final Map attrs = newAttrsList.get(i); + fBreakpoints.removeBreakpoint( + oldBpContexts.get(i), + new RequestMonitor(getExecutor(), countingRM) { + @Override + protected void handleOK() { + fBreakpoints.insertBreakpoint( + context, attrs, + new DataRequestMonitor(getExecutor(), countingRM) { + @Override + protected void handleOK() { + newBpContexts.add(getData()); + countingRM.done(); + } + }); + } + }); + } else { + final IBreakpointDMContext bpCtx = oldBpContexts.get(i); + fBreakpoints.updateBreakpoint( + oldBpContexts.get(i), attrDeltasArray.get(i), + new RequestMonitor(getExecutor(), countingRM) { + @Override + protected void handleOK() { + newBpContexts.add(bpCtx); + countingRM.done(); + } + }); + } + } + } + + private List> getCommonAttributeMaps(List> array1, List> array2) + { + List> intersection = new LinkedList>(); + List> list2 = new ArrayList>(array1); + for (Map array1Map : array1) { + if (list2.remove(array1Map)) { + intersection.add(array1Map); + } + } + return intersection; + } + + /** + * Determine the set of modified attributes + * + * @param oldAttributes + * @param newAttributes + * @return + */ + private List> getAttributesDeltas(List> oldAttributesList, List> newAttributesList) { + List> deltas = new ArrayList>(oldAttributesList.size()); + + // Go through the bp attributes common to the old and the new lists and calculate + // their deltas. + for (int i = 0; i < oldAttributesList.size() && i < newAttributesList.size(); i++) { + Map oldAttributes = oldAttributesList.get(i); + Map newAttributes = newAttributesList.get(i); + + Map delta = new HashMap(); + + Set oldKeySet = oldAttributes.keySet(); + Set newKeySet = newAttributes.keySet(); + + Set commonKeys = new HashSet(newKeySet); commonKeys.retainAll(oldKeySet); + Set addedKeys = new HashSet(newKeySet); addedKeys.removeAll(oldKeySet); + Set removedKeys = new HashSet(oldKeySet); removedKeys.removeAll(newKeySet); + + // Add the modified attributes + for (String key : commonKeys) { + if (!(oldAttributes.get(key).equals(newAttributes.get(key)))) + delta.put(key, newAttributes.get(key)); + } + + // Add the new attributes + for (String key : addedKeys) { + delta.put(key, newAttributes.get(key)); + } + + // Remove the deleted attributes + for (String key : removedKeys) { + delta.put(key, null); + } + deltas.add(delta); + } + + // Add all the new attributes as deltas + for (int i = deltas.size(); i < newAttributesList.size(); i++) { + deltas.add(newAttributesList.get(i)); + } + + // For any old attribute Maps that were removed, insert a null value in the deltas list. + for (int i = deltas.size(); i < oldAttributesList.size(); i++) { + deltas.add(null); + } + + return deltas; + } + + /////////////////////////////////////////////////////////////////////////// + // IBreakpointManagerListener implementation + /////////////////////////////////////////////////////////////////////////// + + public void breakpointManagerEnablementChanged(boolean enabled) { + for (IBreakpoint breakpoint : fBreakpointManager.getBreakpoints()) { + breakpointChanged(breakpoint, null); + } + } + + @ThreadSafe + public void breakpointAdded(final IBreakpoint breakpoint) { + if (fAttributeTranslator.supportsBreakpoint(breakpoint)) { + try { + // Retrieve the breakpoint attributes + final List> attrsArray = + fAttributeTranslator.getBreakpointAttributes(breakpoint, fBreakpointManager.isEnabled()); + + getExecutor().execute(new DsfRunnable() { + public void run() { + //TODO pp: need to track pending requests + + final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) { + @Override + protected void handleError() { + if (getStatus().getSeverity() == IStatus.ERROR) { + DsfDebugPlugin.getDefault().getLog().log(getStatus()); + } + } + }; + countingRm.setDoneCount(fPlatformBPs.size()); + + // Install the breakpoint in all the execution contexts + for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) { + installBreakpoint(dmc, breakpoint, attrsArray, new RequestMonitor(getExecutor(), countingRm)); + } + } + }); + } catch (CoreException e) { + DsfDebugPlugin.getDefault().getLog().log(e.getStatus()); + } catch (RejectedExecutionException e) { + } + } + + } + + /////////////////////////////////////////////////////////////////////////// + // IBreakpointListener implementation + /////////////////////////////////////////////////////////////////////////// + + public void breakpointChanged(final IBreakpoint breakpoint, final IMarkerDelta delta) { + if (fAttributeTranslator.supportsBreakpoint(breakpoint)) { + try { + // Retrieve the breakpoint attributes + final List> attrsArray = + fAttributeTranslator.getBreakpointAttributes(breakpoint, fBreakpointManager.isEnabled()); + + // Modify the breakpoint in all the target contexts + getExecutor().execute( new DsfRunnable() { + public void run() { + + // If the breakpoint is currently being updated, queue the request and exit + if (fPendingRequests.contains(breakpoint)) { + fPendingBreakpoints.add(breakpoint); + return; + } + + // Keep track of the updates + final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) { + @Override + protected void handleCompleted() { + + if (!getStatus().isOK()) { + if (getStatus().getSeverity() == IStatus.ERROR) { + DsfDebugPlugin.getDefault().getLog().log(getStatus()); + } + } + + // Indicate that the pending request has completed + fPendingRequests.remove(breakpoint); + + // Process the next pending update for this breakpoint + if (fPendingBreakpoints.contains(breakpoint)) { + fPendingBreakpoints.remove(breakpoint); + new Job("Deferred breakpoint changed job") { //$NON-NLS-1$ + { setSystem(true); } + @Override + protected IStatus run(IProgressMonitor monitor) { + breakpointChanged(breakpoint, delta); + return Status.OK_STATUS; + }; + }.schedule(); + } + } + }; + countingRm.setDoneCount(fPlatformBPs.size()); + + // Mark the breakpoint as being updated and go + fPendingRequests.add(breakpoint); + + // Modify the breakpoint in all the execution contexts + for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) { + modifyBreakpoint(dmc, breakpoint, attrsArray, delta, new RequestMonitor(getExecutor(), countingRm)); + } + } + }); + } catch (CoreException e) { + DsfDebugPlugin.getDefault().getLog().log(e.getStatus()); + } catch (RejectedExecutionException e) { + } + } + + } + + public void breakpointRemoved(final IBreakpoint breakpoint, IMarkerDelta delta) { + + if (fAttributeTranslator.supportsBreakpoint(breakpoint)) { + try { + getExecutor().execute(new DsfRunnable() { + public void run() { + //TODO pp: need to track pending requests + + CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) { + @Override + protected void handleError() { + if (getStatus().getSeverity() == IStatus.ERROR) { + DsfDebugPlugin.getDefault().getLog().log(getStatus()); + } + } + }; + countingRm.setDoneCount(fPlatformBPs.size()); + + // Remove the breakpoint in all the execution contexts + for (IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) { + if (fPlatformBPs.get(dmc).remove(breakpoint) != null) { + uninstallBreakpoint(dmc, breakpoint, countingRm); + } else { + // Breakpoint not installed for given context, do nothing. + } + } + } + }); + } catch (RejectedExecutionException e) { + } + } + + } +} diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointAttributeTranslator.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointAttributeTranslator.java new file mode 100644 index 00000000000..067809fb82a --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointAttributeTranslator.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.dsf.debug.service; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor; +import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointDMContext; +import org.eclipse.debug.core.model.IBreakpoint; + + +@ThreadSafeAndProhibitedFromDsfExecutor("") +public interface IBreakpointAttributeTranslator { + + public void initialize(BreakpointsMediator mediator); + + public void dispose(); + + public List> getBreakpointAttributes(IBreakpoint breakpoint, boolean bpManagerEnabled) throws CoreException; + + public boolean canUpdateAttributes(IBreakpointDMContext bp, Map delta); + + public boolean supportsBreakpoint(IBreakpoint bp); + + public void updateBreakpointStatus(IBreakpoint bp); +} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointsManager.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointsManager.java deleted file mode 100644 index 79063e39a6c..00000000000 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/IBreakpointsManager.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.dsf.debug.service; - -import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; -import org.eclipse.dd.dsf.service.IDsfService; - -/** - * Breakpoint service interface. The breakpoint service tracks platform breakpoint - * objects, and based on those, it manages breakpoints in the debugger back end. - * The purpose of the service model interface is to allow UI clients to display - * breakpoint status in more detail and more dynamically than it it possible with - * just the marker-based breakpoint object. - */ -public interface IBreakpointsManager extends IDsfService { - - /** - * Install and begin tracking breakpoints for given context. The service - * will keep installing new breakpoints that appear in the IDE for this - * context until {@link #uninstallBreakpoints(IDMContext)} is called for that - * context. - * @param dmc Context to start tracking breakpoints for. - * @param rm Completion callback. - */ - public void startTrackingBreakpoints(IBreakpointsTargetDMContext dmc, RequestMonitor rm); - - /** - * Uninstall and stop tracking breakpoints for the given context. - * @param dmc Context to start tracking breakpoints for. - * @param rm Completion callback. - */ - public void stopTrackingBreakpoints(IBreakpointsTargetDMContext dmc, RequestMonitor rm); -}