37
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2007, 2008 Wind River and others.
|
|
3 |
* All rights reserved. This program and the accompanying materials
|
|
4 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
5 |
* which accompanies this distribution, and is available at
|
|
6 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
7 |
*
|
|
8 |
* Contributors:
|
|
9 |
* Wind River - Initial API and implementation
|
|
10 |
* Ericsson - Low-level breakpoints integration
|
|
11 |
*******************************************************************************/
|
|
12 |
|
|
13 |
package org.eclipse.cdt.dsf.debug.service;
|
|
14 |
|
|
15 |
import java.util.ArrayList;
|
|
16 |
import java.util.HashMap;
|
|
17 |
import java.util.HashSet;
|
|
18 |
import java.util.Hashtable;
|
|
19 |
import java.util.LinkedList;
|
|
20 |
import java.util.List;
|
|
21 |
import java.util.Map;
|
|
22 |
import java.util.Set;
|
|
23 |
import java.util.concurrent.RejectedExecutionException;
|
|
24 |
|
|
25 |
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
|
|
26 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
|
27 |
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
|
28 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
|
29 |
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
|
|
30 |
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
|
31 |
import org.eclipse.cdt.dsf.datamodel.IDMContext;
|
|
32 |
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext;
|
|
33 |
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
|
|
34 |
import org.eclipse.cdt.dsf.internal.DsfPlugin;
|
|
35 |
import org.eclipse.cdt.dsf.service.AbstractDsfService;
|
|
36 |
import org.eclipse.cdt.dsf.service.DsfSession;
|
|
37 |
import org.eclipse.core.resources.IMarkerDelta;
|
|
38 |
import org.eclipse.core.runtime.CoreException;
|
|
39 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
40 |
import org.eclipse.core.runtime.IStatus;
|
|
41 |
import org.eclipse.core.runtime.Status;
|
|
42 |
import org.eclipse.core.runtime.jobs.Job;
|
|
43 |
import org.eclipse.debug.core.DebugPlugin;
|
|
44 |
import org.eclipse.debug.core.IBreakpointListener;
|
|
45 |
import org.eclipse.debug.core.IBreakpointManager;
|
|
46 |
import org.eclipse.debug.core.IBreakpointManagerListener;
|
|
47 |
import org.eclipse.debug.core.model.IBreakpoint;
|
|
48 |
import org.osgi.framework.BundleContext;
|
|
49 |
|
|
50 |
/**
|
|
51 |
*
|
|
52 |
*/
|
|
53 |
public class BreakpointsMediator extends AbstractDsfService implements IBreakpointManagerListener, IBreakpointListener
|
|
54 |
{
|
|
55 |
|
|
56 |
/**
|
|
57 |
* The attribute translator that this service will use to map the platform
|
|
58 |
* breakpiont attributes to the corresponding target attributes, and vice
|
|
59 |
* versa.
|
|
60 |
*/
|
|
61 |
private IBreakpointAttributeTranslator fAttributeTranslator;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* DSF Debug service for creating breakpoints.
|
|
65 |
*/
|
|
66 |
IBreakpoints fBreakpoints;
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Platform breakpoint manager
|
|
70 |
*/
|
|
71 |
IBreakpointManager fBreakpointManager;
|
|
72 |
|
|
73 |
|
|
74 |
///////////////////////////////////////////////////////////////////////////
|
|
75 |
// Breakpoints tracking
|
|
76 |
///////////////////////////////////////////////////////////////////////////
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Holds the set of platform breakpoints with their corresponding back-end
|
|
80 |
* breakpoint attributes, per context (i.e. each platform breakpoint is
|
|
81 |
* replicated for each execution context).
|
|
82 |
* - Context entry added/removed on start/stopTrackingBreakpoints()
|
|
83 |
* - Augmented on breakpointAdded()
|
|
84 |
* - Modified on breakpointChanged()
|
|
85 |
* - Diminished on breakpointRemoved()
|
|
86 |
*/
|
|
87 |
private Map<IBreakpointsTargetDMContext, Map<IBreakpoint, List<Map<String, Object>>>> fPlatformBPs =
|
|
88 |
new HashMap<IBreakpointsTargetDMContext, Map<IBreakpoint, List<Map<String, Object>>>>();
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Holds the mapping from platform breakpoint to the corresponding target
|
|
92 |
* breakpoint(s), per context. There can be multiple back-end BPs for a
|
|
93 |
* single platform BP in the case of [1] multiple target contexts, and/or
|
|
94 |
* [2] thread filtering.
|
|
95 |
* Updated when:
|
|
96 |
* - We start/stop tracking an execution context
|
|
97 |
* - A platform breakpoint is added/removed
|
|
98 |
* - A thread filter is applied/removed
|
|
99 |
*/
|
|
100 |
private Map<IBreakpointsTargetDMContext, Map<IBreakpoint, List<IBreakpointDMContext>>> fBreakpointDMContexts =
|
|
101 |
new HashMap<IBreakpointsTargetDMContext, Map<IBreakpoint, List<IBreakpointDMContext>>>();
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Due to the very asynchronous nature of DSF, a new breakpoint request can
|
|
105 |
* pop up at any time before an ongoing one is completed. The following set
|
|
106 |
* is used to store requests until the ongoing operation completes.
|
|
107 |
*/
|
|
108 |
private Set<IBreakpoint> fPendingRequests = new HashSet<IBreakpoint>();
|
|
109 |
|
|
110 |
/**
|
|
111 |
* @see fPendingRequests
|
|
112 |
*/
|
|
113 |
private Set<IBreakpoint> fPendingBreakpoints = new HashSet<IBreakpoint>();
|
|
114 |
|
|
115 |
///////////////////////////////////////////////////////////////////////////
|
|
116 |
// AbstractDsfService
|
|
117 |
///////////////////////////////////////////////////////////////////////////
|
|
118 |
|
|
119 |
/**
|
|
120 |
* The service constructor
|
|
121 |
*
|
|
122 |
* @param session
|
|
123 |
* @param debugModelId
|
|
124 |
*/
|
|
125 |
public BreakpointsMediator(DsfSession session, IBreakpointAttributeTranslator attributeTranslator) {
|
|
126 |
super(session);
|
|
127 |
fAttributeTranslator = attributeTranslator;
|
|
128 |
}
|
|
129 |
|
|
130 |
@Override
|
|
131 |
public void initialize(final RequestMonitor rm) {
|
|
132 |
// - Collect references for the services we interact with
|
|
133 |
// - Register to interesting events
|
|
134 |
// - Obtain the list of platform breakpoints
|
|
135 |
// - Register the service for interested parties
|
|
136 |
super.initialize(
|
|
137 |
new RequestMonitor(getExecutor(), rm) {
|
|
138 |
@Override
|
|
139 |
protected void handleSuccess() {
|
|
140 |
doInitialize(rm);
|
|
141 |
}});
|
|
142 |
}
|
|
143 |
|
|
144 |
/**
|
|
145 |
* Asynchronous service initialization
|
|
146 |
*
|
|
147 |
* @param requestMonitor
|
|
148 |
*/
|
|
149 |
private void doInitialize(RequestMonitor rm) {
|
|
150 |
|
|
151 |
// Get the services references
|
|
152 |
fBreakpoints = getServicesTracker().getService(IBreakpoints.class);
|
|
153 |
fBreakpointManager = DebugPlugin.getDefault().getBreakpointManager();
|
|
154 |
fAttributeTranslator.initialize(this);
|
|
155 |
|
|
156 |
// Register to the useful events
|
|
157 |
fBreakpointManager.addBreakpointListener(this);
|
|
158 |
fBreakpointManager.addBreakpointManagerListener( this );
|
|
159 |
|
|
160 |
// Register this service
|
|
161 |
register(new String[] { BreakpointsMediator.class.getName() },
|
|
162 |
new Hashtable<String, String>());
|
|
163 |
|
|
164 |
rm.done();
|
|
165 |
}
|
|
166 |
|
|
167 |
@Override
|
|
168 |
public void shutdown(final RequestMonitor rm) {
|
|
169 |
// - Un-register the service
|
|
170 |
// - Stop listening to events
|
|
171 |
// - Remove the breakpoints installed by this service
|
|
172 |
//
|
|
173 |
// Since we are shutting down, there is no overwhelming need
|
|
174 |
// to keep the maps coherent...
|
|
175 |
|
|
176 |
// Stop accepting requests and events
|
|
177 |
unregister();
|
|
178 |
fBreakpointManager.removeBreakpointListener(this);
|
|
179 |
fBreakpointManager.removeBreakpointManagerListener( this );
|
|
180 |
fAttributeTranslator.dispose();
|
|
181 |
|
|
182 |
// Cleanup the breakpoints that are still installed by the service.
|
|
183 |
// Use a counting monitor which will call mom to complete the shutdown
|
|
184 |
// after the breakpoints are un-installed (successfully or not).
|
|
185 |
CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm) {
|
|
186 |
@Override
|
|
187 |
protected void handleCompleted() {
|
|
188 |
BreakpointsMediator.super.shutdown(rm);
|
|
189 |
}
|
|
190 |
};
|
|
191 |
|
|
192 |
// We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints()
|
|
193 |
// modifies the map as it walks through it.
|
|
194 |
List<IBreakpointsTargetDMContext> platformBPKeysCopy = new ArrayList<IBreakpointsTargetDMContext>(fPlatformBPs.size());
|
|
195 |
platformBPKeysCopy.addAll(0, fPlatformBPs.keySet());
|
|
196 |
for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) {
|
|
197 |
stopTrackingBreakpoints(dmc, countingRm);
|
|
198 |
}
|
|
199 |
countingRm.setDoneCount(platformBPKeysCopy.size());
|
|
200 |
}
|
|
201 |
|
|
202 |
@Override
|
|
203 |
protected BundleContext getBundleContext() {
|
|
204 |
return DsfPlugin.getBundleContext();
|
|
205 |
}
|
|
206 |
|
|
207 |
///////////////////////////////////////////////////////////////////////////
|
|
208 |
// IBreakpointsManager
|
|
209 |
///////////////////////////////////////////////////////////////////////////
|
|
210 |
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Install and begin tracking breakpoints for given context. The service
|
|
214 |
* will keep installing new breakpoints that appear in the IDE for this
|
|
215 |
* context until {@link #uninstallBreakpoints(IDMContext)} is called for that
|
|
216 |
* context.
|
|
217 |
* @param dmc Context to start tracking breakpoints for.
|
|
218 |
* @param rm Completion callback.
|
|
219 |
*/
|
|
220 |
public void startTrackingBreakpoints(IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
|
|
221 |
// - Augment the maps with the new execution context
|
|
222 |
// - Install the platform breakpoints on the selected target
|
|
223 |
|
|
224 |
// Validate the context
|
|
225 |
final IBreakpointsTargetDMContext breakpointsDmc = DMContexts.getAncestorOfType(dmc, IBreakpointsTargetDMContext.class);
|
|
226 |
if (breakpointsDmc == null) {
|
|
227 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INTERNAL_ERROR, "Invalid context type", null)); //$NON-NLS-1$
|
|
228 |
rm.done();
|
|
229 |
return;
|
|
230 |
}
|
|
231 |
|
|
232 |
// Make sure a mapping for this execution context does not already exist
|
|
233 |
Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(dmc);
|
|
234 |
if (platformBPs != null) {
|
|
235 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INTERNAL_ERROR, "Context already initialized", null)); //$NON-NLS-1$
|
|
236 |
rm.done();
|
|
237 |
return;
|
|
238 |
}
|
|
239 |
|
|
240 |
// Create entries in the breakpoint tables for the new context. These entries should only
|
|
241 |
// be removed when this service stops tracking breakpoints for the given context.
|
|
242 |
fPlatformBPs.put(breakpointsDmc, new HashMap<IBreakpoint, List<Map<String, Object>>>());
|
|
243 |
fBreakpointDMContexts.put(breakpointsDmc, new HashMap<IBreakpoint, List<IBreakpointDMContext>>());
|
|
244 |
|
|
245 |
// Install the platform breakpoints (stored in fPlatformBPs) on the target.
|
|
246 |
// We need to use a background thread for this operation because we are
|
|
247 |
// accessing the resources system to retrieve the breakpoint attributes.
|
|
248 |
// Accessing the resources system potentially requires using global locks.
|
|
249 |
// Also we will be calling IBreakpointAttributeTranslator which is prohibited
|
|
250 |
// from being called on the session executor thread.
|
|
251 |
new Job("MI Debugger: Install initial breakpoint list.") { //$NON-NLS-1$
|
|
252 |
{ setSystem(true); }
|
|
253 |
|
|
254 |
// Get the stored breakpoints from the platform BreakpointManager
|
|
255 |
// and install them on the target
|
|
256 |
@Override
|
|
257 |
protected IStatus run(IProgressMonitor monitor) {
|
|
258 |
// Read initial breakpoints from platform. Copy the breakpoint attributes into a local map.
|
|
259 |
// Note that we cannot write data into fPlatformBPs table here directly because we are not
|
|
260 |
// executing on the dispatch thread.
|
|
261 |
final Map<IBreakpoint, List<Map<String, Object>>> initialPlatformBPs =
|
|
262 |
new HashMap<IBreakpoint, List<Map<String, Object>>>();
|
|
263 |
try {
|
|
264 |
// Get the stored breakpoint list from the platform BreakpointManager
|
|
265 |
IBreakpoint[] bps = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
|
|
266 |
// Single out the installable breakpoints...
|
|
267 |
for (IBreakpoint bp : bps) {
|
|
268 |
if (fAttributeTranslator.supportsBreakpoint(bp)) {
|
|
269 |
// Retrieve the breakpoint attributes
|
|
270 |
List<Map<String, Object>> attrsArray =
|
|
271 |
fAttributeTranslator.getBreakpointAttributes(bp, fBreakpointManager.isEnabled());
|
|
272 |
// Store it for now (will be installed on the dispatcher thread)
|
|
273 |
initialPlatformBPs.put(bp, attrsArray);
|
|
274 |
}
|
|
275 |
}
|
|
276 |
} catch (CoreException e) {
|
|
277 |
IStatus status = new Status(
|
|
278 |
IStatus.ERROR, DsfPlugin.PLUGIN_ID, REQUEST_FAILED, "Unable to read initial breakpoint attributes", e); //$NON-NLS-1$
|
|
279 |
rm.setStatus(status);
|
|
280 |
rm.done();
|
|
281 |
return status;
|
|
282 |
}
|
|
283 |
|
|
284 |
// Submit the runnable to plant the breakpoints on dispatch thread.
|
|
285 |
getExecutor().submit(new Runnable() {
|
|
286 |
public void run() {
|
|
287 |
installInitialBreakpoints(breakpointsDmc, initialPlatformBPs, rm);
|
|
288 |
}
|
|
289 |
});
|
|
290 |
|
|
291 |
return Status.OK_STATUS;
|
|
292 |
}
|
|
293 |
}.schedule();
|
|
294 |
}
|
|
295 |
|
|
296 |
/**
|
|
297 |
* Installs the breakpoints that existed prior to the activation of this
|
|
298 |
* breakpoints context.
|
|
299 |
*/
|
|
300 |
private void installInitialBreakpoints(final IBreakpointsTargetDMContext dmc,
|
|
301 |
Map<IBreakpoint, List<Map<String, Object>>> initialPlatformBPs,
|
|
302 |
RequestMonitor rm)
|
|
303 |
{
|
|
304 |
// Retrieve the set of platform breakpoints for this context
|
|
305 |
Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(dmc);
|
|
306 |
if (platformBPs == null) {
|
|
307 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$
|
|
308 |
rm.done();
|
|
309 |
return;
|
|
310 |
}
|
|
311 |
|
|
312 |
// Install the individual breakpoints on the executor thread
|
|
313 |
// Requires a counting monitor to know when we're done
|
|
314 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm);
|
|
315 |
countingRm.setDoneCount(initialPlatformBPs.size());
|
|
316 |
|
|
317 |
for (final IBreakpoint bp : initialPlatformBPs.keySet()) {
|
|
318 |
final List<Map<String, Object>> attrs = initialPlatformBPs.get(bp);
|
|
319 |
// Upon determining the debuggerPath, the breakpoint is installed
|
|
320 |
installBreakpoint(dmc, bp, attrs, new RequestMonitor(getExecutor(), countingRm));
|
|
321 |
}
|
|
322 |
}
|
|
323 |
|
|
324 |
|
|
325 |
public void stopTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
|
|
326 |
// - Remove the target breakpoints for the given execution context
|
|
327 |
// - Update the maps
|
|
328 |
|
|
329 |
// Remove the breakpoints for given DMC from the internal maps.
|
|
330 |
Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(dmc);
|
|
331 |
if (platformBPs == null) {
|
|
332 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INTERNAL_ERROR, "Breakpoints not installed for given context", null)); //$NON-NLS-1$
|
|
333 |
rm.done();
|
|
334 |
return;
|
|
335 |
}
|
|
336 |
|
|
337 |
// Uninstall the individual breakpoints on the executor thread
|
|
338 |
// Requires a counting monitor to know when we're done
|
|
339 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm);
|
|
340 |
countingRm.setDoneCount(platformBPs.size());
|
|
341 |
|
|
342 |
for (final IBreakpoint bp : platformBPs.keySet()) {
|
|
343 |
uninstallBreakpoint(dmc, bp,
|
|
344 |
new RequestMonitor(getExecutor(), countingRm) {
|
|
345 |
@Override
|
|
346 |
protected void handleCompleted() {
|
|
347 |
// After the breakpoint is removed from target. Call the attribute
|
|
348 |
// translator to refresh breakpoint status based on the new target
|
|
349 |
// breakpoint status.
|
|
350 |
new Job("Breakpoint status update") { //$NON-NLS-1$
|
|
351 |
{ setSystem(true); }
|
|
352 |
@Override
|
|
353 |
protected IStatus run(IProgressMonitor monitor) {
|
|
354 |
fAttributeTranslator.updateBreakpointStatus(bp);
|
|
355 |
return Status.OK_STATUS;
|
|
356 |
};
|
|
357 |
}.schedule();
|
|
358 |
|
|
359 |
countingRm.done();
|
|
360 |
}
|
|
361 |
});
|
|
362 |
}
|
|
363 |
}
|
|
364 |
|
|
365 |
///////////////////////////////////////////////////////////////////////////
|
|
366 |
// Back-end interface functions
|
|
367 |
///////////////////////////////////////////////////////////////////////////
|
|
368 |
|
|
369 |
/**
|
|
370 |
* Install a new platform breakpoint on the back-end. A platform breakpoint
|
|
371 |
* can resolve into multiple back-end breakpoints when threads are taken
|
|
372 |
* into account.
|
|
373 |
*
|
|
374 |
* @param dmc
|
|
375 |
* @param breakpoint
|
|
376 |
* @param attrsList
|
|
377 |
* @param rm
|
|
378 |
*/
|
|
379 |
private void installBreakpoint(IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint,
|
|
380 |
final List<Map<String, Object>> attrsList, final RequestMonitor rm)
|
|
381 |
{
|
|
382 |
// Retrieve the set of breakpoints for this context
|
|
383 |
final Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(dmc);
|
|
384 |
assert platformBPs != null;
|
|
385 |
|
|
386 |
final Map<IBreakpoint, List<IBreakpointDMContext>> breakpointIDs = fBreakpointDMContexts.get(dmc);
|
|
387 |
assert breakpointIDs != null; // fBreakpointIds should be updated in parallel with fPlatformBPs
|
|
388 |
|
|
389 |
// Ensure the breakpoint is not already installed
|
|
390 |
if (platformBPs.containsKey(breakpoint)) {
|
|
391 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_STATE, "Breakpoint already installed", null)); //$NON-NLS-1$
|
|
392 |
rm.done();
|
|
393 |
return;
|
|
394 |
}
|
|
395 |
|
|
396 |
// Update the breakpoint status when all back-end breakpoints have been installed
|
|
397 |
final CountingRequestMonitor installRM = new CountingRequestMonitor(getExecutor(), rm) {
|
|
398 |
@Override
|
|
399 |
protected void handleCompleted() {
|
|
400 |
// Store the platform breakpoint
|
|
401 |
platformBPs.put(breakpoint, attrsList);
|
|
402 |
new Job("Breakpoint status update") { //$NON-NLS-1$
|
|
403 |
{ setSystem(true); }
|
|
404 |
@Override
|
|
405 |
protected IStatus run(IProgressMonitor monitor) {
|
|
406 |
fAttributeTranslator.updateBreakpointStatus(breakpoint);
|
|
407 |
return Status.OK_STATUS;
|
|
408 |
};
|
|
409 |
}.schedule();
|
|
410 |
rm.done();
|
|
411 |
}
|
|
412 |
};
|
|
413 |
|
|
414 |
// A back-end breakpoint needs to be installed for each specified attributes map.
|
|
415 |
installRM.setDoneCount(attrsList.size());
|
|
416 |
|
|
417 |
// Install the back-end breakpoint(s)
|
|
418 |
for (Map<String, Object> attrs : attrsList) {
|
|
419 |
fBreakpoints.insertBreakpoint(
|
|
420 |
dmc, attrs,
|
|
421 |
new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), installRM) {
|
|
422 |
@Override
|
|
423 |
protected void handleCompleted() {
|
|
424 |
List<IBreakpointDMContext> list = breakpointIDs.get(breakpoint);
|
|
425 |
if (list == null) {
|
|
426 |
list = new LinkedList<IBreakpointDMContext>();
|
|
427 |
breakpointIDs.put(breakpoint, list);
|
|
428 |
}
|
|
429 |
|
|
430 |
if (isSuccess()) {
|
|
431 |
// Add the breakpoint back-end mapping
|
|
432 |
list.add(getData());
|
|
433 |
} else {
|
|
434 |
// TODO (bug 219841): need to add breakpoint error status tracking
|
|
435 |
// in addition to fBreakpointDMContexts.
|
|
436 |
}
|
|
437 |
installRM.done();
|
|
438 |
}
|
|
439 |
});
|
|
440 |
}
|
|
441 |
}
|
|
442 |
|
|
443 |
/**
|
|
444 |
* Un-install an individual breakpoint on the back-end. For one platform
|
|
445 |
* breakpoint, there could be multiple corresponding back-end breakpoints.
|
|
446 |
*
|
|
447 |
* @param dmc
|
|
448 |
* @param breakpoint
|
|
449 |
* @param rm
|
|
450 |
*/
|
|
451 |
private void uninstallBreakpoint(final IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint,
|
|
452 |
final RequestMonitor rm)
|
|
453 |
{
|
|
454 |
// Remove completion monitor
|
|
455 |
CountingRequestMonitor removeRM = new CountingRequestMonitor(getExecutor(), rm) {
|
|
456 |
@Override
|
|
457 |
protected void handleCompleted() {
|
|
458 |
// Remove the attributes mapping
|
|
459 |
Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(dmc);
|
|
460 |
if (platformBPs == null) {
|
|
461 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$
|
|
462 |
rm.done();
|
|
463 |
return;
|
|
464 |
}
|
|
465 |
platformBPs.remove(breakpoint);
|
|
466 |
|
|
467 |
// Remove the back-end mapping
|
|
468 |
Map<IBreakpoint, List<IBreakpointDMContext>> breakpointIDs = fBreakpointDMContexts.get(dmc);
|
|
469 |
if (breakpointIDs == null) {
|
|
470 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
|
|
471 |
rm.done();
|
|
472 |
return;
|
|
473 |
}
|
|
474 |
breakpointIDs.get(breakpoint).clear();
|
|
475 |
breakpointIDs.remove(breakpoint);
|
|
476 |
|
|
477 |
// Update breakpoint status
|
|
478 |
new Job("Breakpoint status update") { //$NON-NLS-1$
|
|
479 |
{ setSystem(true); }
|
|
480 |
@Override
|
|
481 |
protected IStatus run(IProgressMonitor monitor) {
|
|
482 |
fAttributeTranslator.updateBreakpointStatus(breakpoint);
|
|
483 |
return Status.OK_STATUS;
|
|
484 |
};
|
|
485 |
}.schedule();
|
|
486 |
|
|
487 |
rm.done();
|
|
488 |
}
|
|
489 |
};
|
|
490 |
|
|
491 |
// Remove the back-end breakpoints
|
|
492 |
Map<IBreakpoint, List<IBreakpointDMContext>> breakpointIDs = fBreakpointDMContexts.get(dmc);
|
|
493 |
if (breakpointIDs == null) {
|
|
494 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
|
|
495 |
rm.done();
|
|
496 |
return;
|
|
497 |
}
|
|
498 |
|
|
499 |
List<IBreakpointDMContext> list = breakpointIDs.get(breakpoint);
|
|
500 |
int count = 0;
|
|
501 |
if (list != null) {
|
|
502 |
for (IBreakpointDMContext bp : list) {
|
|
503 |
fBreakpoints.removeBreakpoint(bp, removeRM);
|
|
504 |
}
|
|
505 |
count = list.size();
|
|
506 |
}
|
|
507 |
removeRM.setDoneCount(count);
|
|
508 |
}
|
|
509 |
|
|
510 |
/**
|
|
511 |
* Modify an individual breakpoint
|
|
512 |
*
|
|
513 |
* @param context
|
|
514 |
* @param breakpoint
|
|
515 |
* @param attributes
|
|
516 |
* @param rm
|
|
517 |
* @throws CoreException
|
|
518 |
*/
|
|
519 |
private void modifyBreakpoint(final IBreakpointsTargetDMContext context, final IBreakpoint breakpoint,
|
|
520 |
final List<Map<String, Object>> newAttrsList0, final IMarkerDelta oldValues, final RequestMonitor rm)
|
|
521 |
{
|
|
522 |
// This method uses several lists to track the changed breakpoints:
|
|
523 |
// commonAttrsList - attributes which have not changed
|
|
524 |
// oldAttrsList - attributes for the breakpoint before the change
|
|
525 |
// newAttrsList - attributes for the breakpoint after the change
|
|
526 |
// oldBpContexts - target-side breakpoints from before the change
|
|
527 |
// newBpContexts - target-side breakpoints after the change
|
|
528 |
// attrDeltasList - changes in the attributes for each attribute map in
|
|
529 |
// oldAttrsList and newAttrsList
|
|
530 |
|
|
531 |
// Get the maps
|
|
532 |
final Map<IBreakpoint, List<Map<String, Object>>> platformBPs = fPlatformBPs.get(context);
|
|
533 |
final Map<IBreakpoint, List<IBreakpointDMContext>> breakpointIDs = fBreakpointDMContexts.get(context);
|
|
534 |
if (platformBPs == null || breakpointIDs == null) {
|
|
535 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$
|
|
536 |
rm.done();
|
|
537 |
return;
|
|
538 |
}
|
|
539 |
|
|
540 |
// Get the original breakpoint attributes
|
|
541 |
final List<Map<String, Object>> oldAttrsList0 = platformBPs.get(breakpoint);
|
|
542 |
if (oldAttrsList0 == null) {
|
|
543 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
|
|
544 |
rm.done();
|
|
545 |
return;
|
|
546 |
}
|
|
547 |
|
|
548 |
// Get the list of corresponding back-end breakpoints
|
|
549 |
final List<IBreakpointDMContext> oldBpContexts = new ArrayList<IBreakpointDMContext>(breakpointIDs.get(breakpoint));
|
|
550 |
if (oldBpContexts == null) {
|
|
551 |
rm.setStatus(new Status(IStatus.ERROR, DsfPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
|
|
552 |
rm.done();
|
|
553 |
return;
|
|
554 |
}
|
|
555 |
|
|
556 |
// Calculate the list of attributes maps that have not changed.
|
|
557 |
// Immediately add these to the list of new breakpoint contexts,
|
|
558 |
// and remove them from further breakpoint attribute comparisons.
|
|
559 |
final List<Map<String, Object>> commonAttrsList = getCommonAttributeMaps(newAttrsList0, oldAttrsList0);
|
|
560 |
final List<IBreakpointDMContext> newBpContexts = new ArrayList<IBreakpointDMContext>(commonAttrsList.size());
|
|
561 |
|
|
562 |
final List<Map<String, Object>> newAttrsList = new ArrayList<Map<String, Object>>(newAttrsList0);
|
|
563 |
newAttrsList.removeAll(commonAttrsList);
|
|
564 |
|
|
565 |
List<Map<String, Object>> oldAttrsList = new ArrayList<Map<String, Object>>(oldAttrsList0);
|
|
566 |
for (int i = 0; i < oldAttrsList.size(); i++) {
|
|
567 |
if (commonAttrsList.contains(oldAttrsList.get(i))) {
|
|
568 |
if (oldBpContexts.size() > i) {
|
|
569 |
newBpContexts.add(oldBpContexts.remove(i));
|
|
570 |
}
|
|
571 |
}
|
|
572 |
}
|
|
573 |
oldAttrsList.removeAll(commonAttrsList);
|
|
574 |
|
|
575 |
// Create a list of attribute changes. The lenghth of this list will
|
|
576 |
// always be max(oldAttrList.size(), newAttrsList.size()), padded with
|
|
577 |
// null's if oldAttrsList was longer.
|
|
578 |
final List<Map<String, Object>> attrDeltasList = getAttributesDeltas(oldAttrsList, newAttrsList);
|
|
579 |
|
|
580 |
// Create the request monitor that will be called when all
|
|
581 |
// modifying/inserting/removing is complete.
|
|
582 |
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm) {
|
|
583 |
@Override
|
|
584 |
protected void handleCompleted() {
|
|
585 |
// Save the new list of breakpoint contexts and attributes
|
|
586 |
breakpointIDs.put(breakpoint, newBpContexts);
|
|
587 |
newAttrsList.addAll(commonAttrsList);
|
|
588 |
platformBPs.put(breakpoint, newAttrsList);
|
|
589 |
|
|
590 |
// Update breakpoint status. updateBreakpointStatus() cannot
|
|
591 |
// be called on the executor thread, so we need to
|
|
592 |
// use a Job.
|
|
593 |
new Job("Breakpoint status update") { //$NON-NLS-1$
|
|
594 |
{ setSystem(true); }
|
|
595 |
@Override
|
|
596 |
protected IStatus run(IProgressMonitor monitor) {
|
|
597 |
fAttributeTranslator.updateBreakpointStatus(breakpoint);
|
|
598 |
return Status.OK_STATUS;
|
|
599 |
};
|
|
600 |
}.schedule();
|
|
601 |
|
|
602 |
super.handleCompleted();
|
|
603 |
}
|
|
604 |
};
|
|
605 |
|
|
606 |
// Set the count, if could be zero if no breakpoints have actually changed.
|
|
607 |
countingRM.setDoneCount(attrDeltasList.size());
|
|
608 |
|
|
609 |
// Process the changed breakpoints.
|
|
610 |
for (int i = 0; i < attrDeltasList.size(); i++) {
|
|
611 |
if (attrDeltasList.get(i) == null) {
|
|
612 |
// The list of new attribute maps was shorter than the old.
|
|
613 |
// Remove the corresponding target-side bp.
|
|
614 |
fBreakpoints.removeBreakpoint(oldBpContexts.get(i), countingRM);
|
|
615 |
} else if ( i >= oldBpContexts.size()) {
|
|
616 |
// The list of new attribute maps was longer, just insert
|
|
617 |
// the new breakpoint
|
|
618 |
final Map<String, Object> attrs = newAttrsList.get(i);
|
|
619 |
fBreakpoints.insertBreakpoint(
|
|
620 |
context, attrs,
|
|
621 |
new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), countingRM) {
|
|
622 |
@Override
|
|
623 |
protected void handleSuccess() {
|
|
624 |
newBpContexts.add(getData());
|
|
625 |
countingRM.done();
|
|
626 |
}
|
|
627 |
});
|
|
628 |
} else if ( !fAttributeTranslator.canUpdateAttributes(oldBpContexts.get(i), attrDeltasList.get(i)) ) {
|
|
629 |
// The attribute translator tells us that the debugger cannot modify the
|
|
630 |
// breakpoint to change the given attributes. Remove the breakpoint
|
|
631 |
// and insert a new one.
|
|
632 |
final Map<String, Object> attrs = newAttrsList.get(i);
|
|
633 |
fBreakpoints.removeBreakpoint(
|
|
634 |
oldBpContexts.get(i),
|
|
635 |
new RequestMonitor(getExecutor(), countingRM) {
|
|
636 |
@Override
|
|
637 |
protected void handleCompleted() {
|
|
638 |
fBreakpoints.insertBreakpoint(
|
|
639 |
context, attrs,
|
|
640 |
new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), countingRM) {
|
|
641 |
@Override
|
|
642 |
protected void handleCompleted() {
|
|
643 |
if (isSuccess()) {
|
|
644 |
newBpContexts.add(getData());
|
|
645 |
} else {
|
|
646 |
// TODO (bug 219841): need to add breakpoint error status tracking
|
|
647 |
// in addition to fBreakpointDMContexts.
|
|
648 |
}
|
|
649 |
countingRM.done();
|
|
650 |
}
|
|
651 |
});
|
|
652 |
}
|
|
653 |
});
|
|
654 |
} else {
|
|
655 |
// The back end can modify the breakpoint. Update the breakpoint with the
|
|
656 |
// new attributes.
|
|
657 |
final IBreakpointDMContext bpCtx = oldBpContexts.get(i);
|
|
658 |
fBreakpoints.updateBreakpoint(
|
|
659 |
oldBpContexts.get(i), newAttrsList.get(i),
|
|
660 |
new RequestMonitor(getExecutor(), countingRM) {
|
|
661 |
@Override
|
|
662 |
protected void handleSuccess() {
|
|
663 |
newBpContexts.add(bpCtx);
|
|
664 |
countingRM.done();
|
|
665 |
}
|
|
666 |
});
|
|
667 |
}
|
|
668 |
}
|
|
669 |
}
|
|
670 |
|
|
671 |
private List<Map<String, Object>> getCommonAttributeMaps(List<Map<String, Object>> array1, List<Map<String, Object>> array2)
|
|
672 |
{
|
|
673 |
List<Map<String, Object>> intersection = new LinkedList<Map<String, Object>>();
|
|
674 |
List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>(array2);
|
|
675 |
for (Map<String, Object> array1Map : array1) {
|
|
676 |
if (list2.remove(array1Map)) {
|
|
677 |
intersection.add(array1Map);
|
|
678 |
}
|
|
679 |
}
|
|
680 |
return intersection;
|
|
681 |
}
|
|
682 |
|
|
683 |
/**
|
|
684 |
* Determine the set of modified attributes
|
|
685 |
*
|
|
686 |
* @param oldAttributes
|
|
687 |
* @param newAttributes
|
|
688 |
* @return
|
|
689 |
*/
|
|
690 |
private List<Map<String, Object>> getAttributesDeltas(List<Map<String, Object>> oldAttributesList, List<Map<String, Object>> newAttributesList) {
|
|
691 |
List<Map<String, Object>> deltas = new ArrayList<Map<String, Object>>(oldAttributesList.size());
|
|
692 |
|
|
693 |
// Go through the bp attributes common to the old and the new lists and calculate
|
|
694 |
// their deltas.
|
|
695 |
for (int i = 0; i < oldAttributesList.size() && i < newAttributesList.size(); i++) {
|
|
696 |
Map<String, Object> oldAttributes = oldAttributesList.get(i);
|
|
697 |
Map<String, Object> newAttributes = newAttributesList.get(i);
|
|
698 |
|
|
699 |
Map<String, Object> delta = new HashMap<String, Object>();
|
|
700 |
|
|
701 |
Set<String> oldKeySet = oldAttributes.keySet();
|
|
702 |
Set<String> newKeySet = newAttributes.keySet();
|
|
703 |
|
|
704 |
Set<String> commonKeys = new HashSet<String>(newKeySet); commonKeys.retainAll(oldKeySet);
|
|
705 |
Set<String> addedKeys = new HashSet<String>(newKeySet); addedKeys.removeAll(oldKeySet);
|
|
706 |
Set<String> removedKeys = new HashSet<String>(oldKeySet); removedKeys.removeAll(newKeySet);
|
|
707 |
|
|
708 |
// Add the modified attributes
|
|
709 |
for (String key : commonKeys) {
|
|
710 |
if (!(oldAttributes.get(key).equals(newAttributes.get(key))))
|
|
711 |
delta.put(key, newAttributes.get(key));
|
|
712 |
}
|
|
713 |
|
|
714 |
// Add the new attributes
|
|
715 |
for (String key : addedKeys) {
|
|
716 |
delta.put(key, newAttributes.get(key));
|
|
717 |
}
|
|
718 |
|
|
719 |
// Remove the deleted attributes
|
|
720 |
for (String key : removedKeys) {
|
|
721 |
delta.put(key, null);
|
|
722 |
}
|
|
723 |
deltas.add(delta);
|
|
724 |
}
|
|
725 |
|
|
726 |
// Add all the new attributes as deltas
|
|
727 |
for (int i = deltas.size(); i < newAttributesList.size(); i++) {
|
|
728 |
deltas.add(newAttributesList.get(i));
|
|
729 |
}
|
|
730 |
|
|
731 |
// For any old attribute Maps that were removed, insert a null value in the deltas list.
|
|
732 |
for (int i = deltas.size(); i < oldAttributesList.size(); i++) {
|
|
733 |
deltas.add(null);
|
|
734 |
}
|
|
735 |
|
|
736 |
return deltas;
|
|
737 |
}
|
|
738 |
|
|
739 |
///////////////////////////////////////////////////////////////////////////
|
|
740 |
// IBreakpointManagerListener implementation
|
|
741 |
///////////////////////////////////////////////////////////////////////////
|
|
742 |
|
|
743 |
public void breakpointManagerEnablementChanged(boolean enabled) {
|
|
744 |
for (IBreakpoint breakpoint : fBreakpointManager.getBreakpoints()) {
|
|
745 |
breakpointChanged(breakpoint, null);
|
|
746 |
}
|
|
747 |
}
|
|
748 |
|
|
749 |
@ThreadSafe
|
|
750 |
public void breakpointAdded(final IBreakpoint breakpoint) {
|
|
751 |
if (fAttributeTranslator.supportsBreakpoint(breakpoint)) {
|
|
752 |
try {
|
|
753 |
// Retrieve the breakpoint attributes
|
|
754 |
final List<Map<String, Object>> attrsArray =
|
|
755 |
fAttributeTranslator.getBreakpointAttributes(breakpoint, fBreakpointManager.isEnabled());
|
|
756 |
|
|
757 |
getExecutor().execute(new DsfRunnable() {
|
|
758 |
public void run() {
|
|
759 |
//TODO pp: need to track pending requests
|
|
760 |
|
|
761 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) {
|
|
762 |
@Override
|
|
763 |
protected void handleError() {
|
|
764 |
if (getStatus().getSeverity() == IStatus.ERROR) {
|
|
765 |
DsfPlugin.getDefault().getLog().log(getStatus());
|
|
766 |
}
|
|
767 |
}
|
|
768 |
};
|
|
769 |
countingRm.setDoneCount(fPlatformBPs.size());
|
|
770 |
|
|
771 |
// Install the breakpoint in all the execution contexts
|
|
772 |
for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
|
|
773 |
installBreakpoint(dmc, breakpoint, attrsArray, new RequestMonitor(getExecutor(), countingRm));
|
|
774 |
}
|
|
775 |
}
|
|
776 |
});
|
|
777 |
} catch (CoreException e) {
|
|
778 |
DsfPlugin.getDefault().getLog().log(e.getStatus());
|
|
779 |
} catch (RejectedExecutionException e) {
|
|
780 |
}
|
|
781 |
}
|
|
782 |
|
|
783 |
}
|
|
784 |
|
|
785 |
///////////////////////////////////////////////////////////////////////////
|
|
786 |
// IBreakpointListener implementation
|
|
787 |
///////////////////////////////////////////////////////////////////////////
|
|
788 |
|
|
789 |
public void breakpointChanged(final IBreakpoint breakpoint, final IMarkerDelta delta) {
|
|
790 |
if (fAttributeTranslator.supportsBreakpoint(breakpoint)) {
|
|
791 |
try {
|
|
792 |
// Retrieve the breakpoint attributes
|
|
793 |
final List<Map<String, Object>> attrsArray =
|
|
794 |
fAttributeTranslator.getBreakpointAttributes(breakpoint, fBreakpointManager.isEnabled());
|
|
795 |
|
|
796 |
// Modify the breakpoint in all the target contexts
|
|
797 |
getExecutor().execute( new DsfRunnable() {
|
|
798 |
public void run() {
|
|
799 |
|
|
800 |
// If the breakpoint is currently being updated, queue the request and exit
|
|
801 |
if (fPendingRequests.contains(breakpoint)) {
|
|
802 |
fPendingBreakpoints.add(breakpoint);
|
|
803 |
return;
|
|
804 |
}
|
|
805 |
|
|
806 |
// Keep track of the updates
|
|
807 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) {
|
|
808 |
@Override
|
|
809 |
protected void handleCompleted() {
|
|
810 |
|
|
811 |
if (!isSuccess()) {
|
|
812 |
if (getStatus().getSeverity() == IStatus.ERROR) {
|
|
813 |
DsfPlugin.getDefault().getLog().log(getStatus());
|
|
814 |
}
|
|
815 |
}
|
|
816 |
|
|
817 |
// Indicate that the pending request has completed
|
|
818 |
fPendingRequests.remove(breakpoint);
|
|
819 |
|
|
820 |
// Process the next pending update for this breakpoint
|
|
821 |
if (fPendingBreakpoints.contains(breakpoint)) {
|
|
822 |
fPendingBreakpoints.remove(breakpoint);
|
|
823 |
new Job("Deferred breakpoint changed job") { //$NON-NLS-1$
|
|
824 |
{ setSystem(true); }
|
|
825 |
@Override
|
|
826 |
protected IStatus run(IProgressMonitor monitor) {
|
|
827 |
breakpointChanged(breakpoint, delta);
|
|
828 |
return Status.OK_STATUS;
|
|
829 |
};
|
|
830 |
}.schedule();
|
|
831 |
}
|
|
832 |
}
|
|
833 |
};
|
|
834 |
countingRm.setDoneCount(fPlatformBPs.size());
|
|
835 |
|
|
836 |
// Mark the breakpoint as being updated and go
|
|
837 |
fPendingRequests.add(breakpoint);
|
|
838 |
|
|
839 |
// Modify the breakpoint in all the execution contexts
|
|
840 |
for (final IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
|
|
841 |
modifyBreakpoint(dmc, breakpoint, attrsArray, delta, new RequestMonitor(getExecutor(), countingRm));
|
|
842 |
}
|
|
843 |
}
|
|
844 |
});
|
|
845 |
} catch (CoreException e) {
|
|
846 |
DsfPlugin.getDefault().getLog().log(e.getStatus());
|
|
847 |
} catch (RejectedExecutionException e) {
|
|
848 |
}
|
|
849 |
}
|
|
850 |
|
|
851 |
}
|
|
852 |
|
|
853 |
public void breakpointRemoved(final IBreakpoint breakpoint, IMarkerDelta delta) {
|
|
854 |
|
|
855 |
if (fAttributeTranslator.supportsBreakpoint(breakpoint)) {
|
|
856 |
try {
|
|
857 |
getExecutor().execute(new DsfRunnable() {
|
|
858 |
public void run() {
|
|
859 |
//TODO pp: need to track pending requests
|
|
860 |
|
|
861 |
CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), null) {
|
|
862 |
@Override
|
|
863 |
protected void handleError() {
|
|
864 |
if (getStatus().getSeverity() == IStatus.ERROR) {
|
|
865 |
DsfPlugin.getDefault().getLog().log(getStatus());
|
|
866 |
}
|
|
867 |
}
|
|
868 |
};
|
|
869 |
countingRm.setDoneCount(fPlatformBPs.size());
|
|
870 |
|
|
871 |
// Remove the breakpoint in all the execution contexts
|
|
872 |
for (IBreakpointsTargetDMContext dmc : fPlatformBPs.keySet()) {
|
|
873 |
if (fPlatformBPs.get(dmc).remove(breakpoint) != null) {
|
|
874 |
uninstallBreakpoint(dmc, breakpoint, countingRm);
|
|
875 |
} else {
|
|
876 |
// Breakpoint not installed for given context, do nothing.
|
|
877 |
}
|
|
878 |
}
|
|
879 |
}
|
|
880 |
});
|
|
881 |
} catch (RejectedExecutionException e) {
|
|
882 |
}
|
|
883 |
}
|
|
884 |
|
|
885 |
}
|
|
886 |
}
|