Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7d2e4ed750c912072b1a419351299717f7a2eae8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
/*******************************************************************************
 * Copyright (c) 2007, 2010 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
 *     Nokia - refactored to work for both GDB and EDC.  Nov. 2009.
 *******************************************************************************/

package org.eclipse.cdt.dsf.debug.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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.cdt.dsf.concurrent.CountingRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
import org.eclipse.cdt.dsf.internal.DsfPlugin;
import org.eclipse.cdt.dsf.service.AbstractDsfService;
import org.eclipse.cdt.dsf.service.DsfSession;
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.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.IBreakpointsListener;
import org.eclipse.debug.core.model.IBreakpoint;
import org.osgi.framework.BundleContext;

/**
/**
 * Breakpoints mediator is a DSF service which synchronizes breakpoints in the 
 * IDE and breakpoints in the debugger.  The IDE breakpoints are managed by the 
 * {@link IBreakpointManager} while the debugger breakpoints are accessed 
 * through the {@link IBreakpoints} service.
 * <p>
 * This class is not intended to be extended by clients.  Instead clients should
 * implement the {@link IBreakpointAttributeTranslator2} interface which is used
 * to translate breakpoint attributes between the IDE and debugger breakpoints.
 * <p>
 * Note: This breakpoint mediator is a second generation implementation that 
 * succeeds {@link BreakpointsMediator}.  This new implementation includes 
 * the following additional features:
 * <ul>
 *   <li> support for multiple target breakpoints for each IDE breakpoint, </li>
 *   <li> support for retrieving the mapping between IDE breakpoints and 
 *        debugger breakpoints,</li>
 *   <li> support for updating IDE breakpoint status based on full target
 *        breakpoint data. </li>
 * </ul>
 * 
 * @see IBreakpointAttributeTranslator2
 * @see BreakpointsMediator
 * 
 * @since 2.1
 */
public class BreakpointsMediator2 extends AbstractDsfService implements IBreakpointsListener
{
	public enum BreakpointEventType {ADDED, REMOVED, MODIFIED}; 	
	
    /**
     * The attribute translator that this service will use to map the platform
     * breakpoint attributes to the corresponding target attributes, and vice
     * versa.
     */
    private IBreakpointAttributeTranslator2 fAttributeTranslator2;

    /**
     * DSF Debug service for creating breakpoints.
     */
    IBreakpoints fBreakpointsService;
    
    /**
     * Platform breakpoint manager
     */
    IBreakpointManager fBreakpointManager;

    /**
     * Object describing the information about a single target breakpoint  
     * corresponding to specific platform breakpoint and breakpoint target 
     * context.
     */
    public interface ITargetBreakpointInfo {

    	/**
    	 * Returns the breakpoint attributes as returned by the attribute translator.
    	 */
    	public Map<String, Object> getAttributes();

    	/**
    	 * Returns the target breakpoint context.  Returns <code>null</code> if the 
    	 * breakpoint failed to install on target. 
    	 */
    	public IBreakpointDMContext getTargetBreakpoint();

    	/**
    	 * Returns the status result of the last breakpoint operation (install/remove). 
    	 */
    	public IStatus getStatus();
    }
    
    private static class TargetBP implements ITargetBreakpointInfo {
    	
    	private Map<String, Object> fAttributes;
    	private IBreakpointDMContext fTargetBPContext;
    	private IStatus fStatus;
    	
    	public TargetBP(Map<String, Object> attrs) {
    		fAttributes = attrs;
    	}
    	
        @Override
    	public Map<String, Object> getAttributes() {
			return fAttributes;
		}
    	
        @Override
    	public IBreakpointDMContext getTargetBreakpoint() {
			return fTargetBPContext;
		}
    	
        @Override
    	public IStatus getStatus() {
			return fStatus;
		}

		public void setTargetBreakpoint(IBreakpointDMContext fTargetBPContext) {
			this.fTargetBPContext = fTargetBPContext;
		}

		public void setStatus(IStatus status) {
			this.fStatus = status;
		}
    }
    
	private class PlatformBreakpointInfo {
		IBreakpoint 		breakpoint;
		boolean 			enabled;
		// All attributes available from UI, including standard and extended ones.
		Map<String, Object>	attributes;
		
		public PlatformBreakpointInfo(IBreakpoint bp, boolean enabled, Map<String, Object> attributes) {
			super();
			breakpoint = bp;
			this.enabled = enabled;
			this.attributes = attributes;
		}
	}

	///////////////////////////////////////////////////////////////////////////
    // Breakpoints tracking
    ///////////////////////////////////////////////////////////////////////////

    /**
     * Holds the set of platform breakpoints with their breakpoint information 
     * structures, 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<IBreakpointsTargetDMContext, Map<IBreakpoint, List<ITargetBreakpointInfo>>> fPlatformBPs = 
		new HashMap<IBreakpointsTargetDMContext, Map<IBreakpoint, List<ITargetBreakpointInfo>>>();

	/**
	 * BreakpointsTargetDMContext's that are being removed from {@link #fPlatformBPs}.
	 * See where this is used for more.
	 */
	private List<IBreakpointsTargetDMContext>	fBPTargetDMCsBeingRemoved = new ArrayList<IBreakpoints.IBreakpointsTargetDMContext>();
	
	/**
	 * Mapping of platform breakpoints to all their attributes (standard ones and
	 * extended ones) from UI. This will be used to check what attributes have
	 * changed for a breakpoint when the breakpoint is changed. The map is <br>
	 * 1. augmented in breakpointsAdded(); <br>
	 * 2. updated in breakpointsChanged(); <br>
	 * 3. diminished in breakpointsRemoved();
	 */
	private Map<IBreakpoint, Map<String, Object>> fBreakpointAttributes = 
		new HashMap<IBreakpoint, Map<String, Object>>();
	
	/**
	 * Hold info about a breakpoint events (added, removed, changed) for later
	 * handling.
	 */
	private static class PendingEventInfo {
		PendingEventInfo(BreakpointEventType eventType, PlatformBreakpointInfo bpInfo,
				Collection<IBreakpointsTargetDMContext> bpsTargetDmc, RequestMonitor rm) {
			fEventType = eventType;
			fBPInfo = bpInfo;
			fBPTargetContexts = bpsTargetDmc;
			fRequestMonitor = rm;
			fAttributeDelta = null;
		}
		
		PendingEventInfo(BreakpointEventType eventType, Collection<IBreakpointsTargetDMContext> updateContexts,
				Map<String, Object> attrDelta) {
			fEventType = eventType;
			fBPTargetContexts = updateContexts;
			fAttributeDelta = attrDelta;
			fRequestMonitor = null;
			fBPInfo = null;
		}

		PlatformBreakpointInfo fBPInfo;
		RequestMonitor fRequestMonitor;
		BreakpointEventType fEventType;
		Collection<IBreakpointsTargetDMContext> fBPTargetContexts;
		Map<String, Object>	fAttributeDelta;	// for change event only
	}
	
    /**
     * 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<IBreakpoint> fRunningEvents    = new HashSet<IBreakpoint>();

	private Map<IBreakpoint, LinkedList<PendingEventInfo>> fPendingEvents = 
			new HashMap<IBreakpoint, LinkedList<PendingEventInfo>>();
	
    ///////////////////////////////////////////////////////////////////////////
    // AbstractDsfService    
    ///////////////////////////////////////////////////////////////////////////

	/**
	 * The service constructor
	 * 
	 * @param session
	 * @param debugModelId
	 */
	public BreakpointsMediator2(DsfSession session, IBreakpointAttributeTranslator2 attributeTranslator) {
        super(session);
        fAttributeTranslator2 = 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 handleSuccess() {
                    doInitialize(rm);
                }});
    }

    /**
     * Asynchronous service initialization 
     * 
     * @param requestMonitor
     */
    private void doInitialize(RequestMonitor rm) {
    	
    	// Get the services references
        fBreakpointsService  = getServicesTracker().getService(IBreakpoints.class);
        fBreakpointManager = DebugPlugin.getDefault().getBreakpointManager();
        fAttributeTranslator2.initialize(this);

        // Register to the useful events
        fBreakpointManager.addBreakpointListener(this);

        // Register this service
        register(new String[] { BreakpointsMediator2.class.getName() },
				 new Hashtable<String, String>());

        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);
        fAttributeTranslator2.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() {
                BreakpointsMediator2.super.shutdown(rm);
            }
        };

        // We have to make a copy of the fPlatformBPs keys because uninstallBreakpoints()
        // modifies the map as it walks through it.
        List<IBreakpointsTargetDMContext> platformBPKeysCopy = new ArrayList<IBreakpointsTargetDMContext>(fPlatformBPs.size());
        platformBPKeysCopy.addAll(0, fPlatformBPs.keySet());
        for (IBreakpointsTargetDMContext dmc : platformBPKeysCopy) {
            stopTrackingBreakpoints(dmc, countingRm);
        }
        countingRm.setDoneCount(platformBPKeysCopy.size());
    }
    
	@Override
    protected BundleContext getBundleContext() {
        return DsfPlugin.getBundleContext();
    }

    protected String getPluginID() {
        return DsfPlugin.PLUGIN_ID;
    }

    protected Plugin getPlugin() {
        return DsfPlugin.getDefault();
    }

	/**
     * 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 #stopTrackingBreakpoints} is called for that
     * context.
     * @param dmc Context to start tracking breakpoints for.
     * @param rm Completion callback.
     */
    public void startTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
        // - Augment the maps with the new execution context
        // - Install the platform breakpoints on the selected target
            
        // Make sure a mapping for this execution context does not already exist
		Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(dmc);
		if (platformBPs != null) {
            rm.setStatus(new Status(IStatus.ERROR, getPluginID(), 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(dmc, new HashMap<IBreakpoint, List<ITargetBreakpointInfo>>());

        // 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 some IBreakpointAttributeTranslator2 methods 
        // that are prohibited from being called on the session executor thread.
		new Job("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) {
        		doBreakpointsAdded(DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(), dmc, rm);
                return Status.OK_STATUS;
            }
        }.schedule();    
    }

    /**
     * Remove and stop installing breakpoints for the given breakpoints target context.
     * @param dmc Context to stop tracking breakpoints for.
     * @param rm Completion callback.
     */
    public void stopTrackingBreakpoints(final IBreakpointsTargetDMContext dmc, final RequestMonitor rm) {
        // - Remove the target breakpoints for the given DMC
    	// - Remove the given DMC from the internal maps.
        //
        Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(dmc);
        if (platformBPs == null) {
            rm.setStatus(new Status(IStatus.INFO /* NOT error */, getPluginID(), INTERNAL_ERROR, "Breakpoints not installed for given context", null)); //$NON-NLS-1$
            rm.done();
            return;
        }
        
        if (platformBPs.size() == 0) {
            fPlatformBPs.remove(dmc);	// dmc tracked but no bps installed for it.
            rm.done();
            return;
        }

        // The stopTrackingBreakpoints() may be called twice for the same DMC 
        // on debugger termination (one on process death and one on debugger shutdown).
        // This is to prevent double killing.
        if (fBPTargetDMCsBeingRemoved.contains(dmc)) { // "stop" is already underway
        	rm.done();
        	return;
        }
        
        fBPTargetDMCsBeingRemoved.add(dmc);
        
        // Just remove the IBreakpoints installed for the "dmc".
        final IBreakpoint[] bps = platformBPs.keySet().toArray(new IBreakpoint[platformBPs.size()]);
        
		new Job("Uninstall target breakpoints list.") { //$NON-NLS-1$
            { setSystem(true); }

        	@Override
            protected IStatus run(IProgressMonitor monitor) {
        		doBreakpointsRemoved(bps, dmc, new RequestMonitor(getExecutor(), rm){
					@Override
					protected void handleCompleted() {
						// Regardless of success or failure in removing the breakpoints,
						// we should stop tracking breakpoints for the "dmc" by removing it
						// from the map.
						fPlatformBPs.remove(dmc);
						fBPTargetDMCsBeingRemoved.remove(dmc);
						
						super.handleCompleted();
					}});
                return Status.OK_STATUS;
            }
        }.schedule();    
    }
    
    /**
     * Find target breakpoints installed in the given context that are resolved 
     * from the given platform breakpoint.
     *  
     * @param dmc - context
     * @param platformBp - platform breakpoint
     * @return array of target breakpoints. 
     */
    public ITargetBreakpointInfo[] getTargetBreakpoints(IBreakpointsTargetDMContext dmc, IBreakpoint platformBp) {
    	assert getExecutor().isInExecutorThread();
    	
        Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(dmc);

        if (platformBPs != null)
        {
        	List<ITargetBreakpointInfo> bpInfo = platformBPs.get(platformBp);
            if (bpInfo != null) {
            	return bpInfo.toArray(new ITargetBreakpointInfo[bpInfo.size()]);
            }
        }
        return null;
    }
    
    /**
     * Find the platform breakpoint that's mapped to the given target breakpoint.
     * 
     * @param dmc - context of the target breakpoint, can be null.
     * @param bp - target breakpoint
     * @return platform breakpoint. null if not found. 
     */
    public IBreakpoint getPlatformBreakpoint(IBreakpointsTargetDMContext dmc, IBreakpointDMContext bp) {
    	assert getExecutor().isInExecutorThread();

    	for (IBreakpointsTargetDMContext bpContext : fPlatformBPs.keySet()) {
    		if (dmc != null && !dmc.equals(bpContext))
    			continue;
    		
	        Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(bpContext);
	
	        if (platformBPs != null && platformBPs.size() > 0)
	        {
	            for(Map.Entry<IBreakpoint, List<ITargetBreakpointInfo>> e: platformBPs.entrySet())
	            {
	                // Stop at the first occurrence
	            	for (ITargetBreakpointInfo tbp : e.getValue()) {
                        IBreakpointDMContext targetBreakpoint = tbp.getTargetBreakpoint();
                        if(targetBreakpoint != null && targetBreakpoint.equals(bp))
	            			return e.getKey();
                    }
	            }    
	        }
    	}

    	return null;
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Back-end interface functions
    ///////////////////////////////////////////////////////////////////////////

	/**
	 * Install a new platform breakpoint on the back-end. A platform breakpoint
	 * can resolve into multiple back-end breakpoints, e.g. when threads are taken
	 * into account.
	 *  
	 * @param dmc
	 * @param breakpoint
	 * @param attrsList - list of attribute map, each mapping to a potential target BP.
	 * @param rm
	 */
	private void installBreakpoint(IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint,
			final List<Map<String, Object>> attrsList, final DataRequestMonitor<List<TargetBP>> rm)
	{
    	// Retrieve the set of breakpoints for this context
        final Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(dmc);
        assert platformBPs != null;

        // Ensure the breakpoint is not already installed
        assert !platformBPs.containsKey(breakpoint);

        final ArrayList<TargetBP> targetBPsAttempted = new ArrayList<TargetBP>(attrsList.size());
        for (int i = 0; i < attrsList.size(); i++) {
        	targetBPsAttempted.add(new TargetBP(attrsList.get(i)));
        }
        
        final ArrayList<ITargetBreakpointInfo> targetBPsInstalled = new ArrayList<ITargetBreakpointInfo>(attrsList.size());

        // Update the breakpoint status when all back-end breakpoints have been installed
    	final CountingRequestMonitor installRM = new CountingRequestMonitor(getExecutor(), rm) {
			@Override
			protected void handleCompleted() {
				// Store successful targetBPs with the platform breakpoint
				if (targetBPsInstalled.size() > 0)
					platformBPs.put(breakpoint, targetBPsInstalled);
				
				// Store all targetBPs, success or failure, in the rm.
				rm.setData(targetBPsAttempted);
		        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 (int _i = 0; _i < attrsList.size(); _i++) {
			final int i = _i;
            fBreakpointsService.insertBreakpoint(
                dmc, attrsList.get(i), 
				new DataRequestMonitor<IBreakpointDMContext>(getExecutor(), installRM) {
				@Override
                protected void handleCompleted() {
					TargetBP targetBP = targetBPsAttempted.get(i);
                    if (isSuccess()) {
						// Add the breakpoint back-end mapping
                    	targetBP.setTargetBreakpoint(getData());
                    	
                    	targetBPsInstalled.add(targetBP);
					} 
                    targetBP.setStatus(getStatus());
                    
					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
	 *            the context for which to remove the breakpoint.
	 * @param breakpoint
	 * @param drm
	 *            contains list of Target breakpoints that are removed
	 *            regardless of success or failure in the removal.
	 */
    private void uninstallBreakpoint(final IBreakpointsTargetDMContext dmc, final IBreakpoint breakpoint, 
        final DataRequestMonitor<List<ITargetBreakpointInfo>> drm)
    {
		// Remove the back-end breakpoints
		final Map<IBreakpoint, List<ITargetBreakpointInfo>> platformBPs = fPlatformBPs.get(dmc);
        if (platformBPs == null) {
            drm.setStatus(new Status(IStatus.ERROR, getPluginID(), INVALID_HANDLE, "Invalid breakpoint", null)); //$NON-NLS-1$
            drm.done();
            return;
        }

        final List<ITargetBreakpointInfo> bpList = platformBPs.get(breakpoint);
        assert bpList != null;

        // Only try to remove those targetBPs that are successfully installed.
        
  		// Remove completion monitor
    	final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), drm) {
			@Override
			protected void handleCompleted() {
				platformBPs.remove(breakpoint);

		        // Complete the request monitor.
		        drm.setData(bpList);
		        drm.done();
			}
		};

        int count = 0;
        for (int i = 0; i < bpList.size(); i++) {
        	final ITargetBreakpointInfo bp = bpList.get(i);
        	if (bp.getTargetBreakpoint() != null) {
        		fBreakpointsService.removeBreakpoint(
        				bp.getTargetBreakpoint(), 
        				new RequestMonitor(getExecutor(), countingRm) {
        					@Override
        					protected void handleCompleted() {
        						// Remember result of the removal, success or failure.
        				        ((TargetBP)bp).setStatus(getStatus());
        				        if (isSuccess()) {
        				            ((TargetBP)bp).setTargetBreakpoint(null);
        				        } 
        				        countingRm.done();
        					}
        				});
        		count++;
        	} else {
        	    ((TargetBP)bp).setStatus(Status.OK_STATUS);
        	}
        }
        countingRm.setDoneCount(count);
    }
	
    ///////////////////////////////////////////////////////////////////////////
    // IBreakpointManagerListener implementation
    ///////////////////////////////////////////////////////////////////////////

    /**
     * @noreference This method is not intended to be referenced by clients.
     */
    @ThreadSafeAndProhibitedFromDsfExecutor("getExecutor()")
    @Override
	public void breakpointsAdded(final IBreakpoint[] bps) {
		doBreakpointsAdded(bps, null, null);
	}
	
	protected void doBreakpointsAdded(final IBreakpoint[] bps, final IBreakpointsTargetDMContext bpsTargetDmc, final RequestMonitor rm) {
		// Collect attributes (which will access system resource)
		// in non DSF dispatch thread.
		//
		final PlatformBreakpointInfo[] bpsInfo = collectBreakpointsInfo(bps);
		
		// Nothing to do
		if (bpsInfo.length == 0) {
			if (rm != null) {
				rm.done();
			}
			return;
		}

		try {
            getExecutor().execute(new DsfRunnable() {
                @Override
				public void run() {
					Collection<IBreakpointsTargetDMContext> dmcs = new ArrayList<IBreakpointsTargetDMContext>();
					if (bpsTargetDmc == null)
						dmcs.addAll(fPlatformBPs.keySet());
					else
						dmcs.add(bpsTargetDmc);

					doBreakpointsAddedInExecutor(bpsInfo, dmcs, rm);
				}
			});
		} catch (RejectedExecutionException e) {
			IStatus status = new Status(IStatus.ERROR, getPluginID(), IDsfStatusConstants.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e);//$NON-NLS-1$ //$NON-NLS-2$
			if (rm != null) {
				rm.setStatus(status);
				rm.done();
			} else {
				getPlugin().getLog().log(status); 
			}
		}
	}
	
	/**
	 * Collect breakpoint info. This method must not be called in DSF dispatch thread.
	 * @param bps
	 * @return
	 */
    private PlatformBreakpointInfo[] collectBreakpointsInfo(IBreakpoint[] bps) {
		List<PlatformBreakpointInfo> bpsInfo = new ArrayList<PlatformBreakpointInfo>(bps.length);
		
		for (IBreakpoint bp : bps) {
			if (bp.getMarker() == null)
				continue;
			
			if (fAttributeTranslator2.supportsBreakpoint(bp)) {
				try {
	        		Map<String, Object> attrs = fAttributeTranslator2.getAllBreakpointAttributes(bp, fBreakpointManager.isEnabled());
	        		boolean enabled = bp.isEnabled() && fBreakpointManager.isEnabled();
					bpsInfo.add(new PlatformBreakpointInfo(bp, enabled, attrs));
				} catch (CoreException e) {
					getPlugin().getLog().log(e.getStatus());
				}
			}
		}
		
		return bpsInfo.toArray(new PlatformBreakpointInfo[bpsInfo.size()]);
	}

	private void doBreakpointsAddedInExecutor(PlatformBreakpointInfo[] bpsInfo, Collection<IBreakpointsTargetDMContext> bpTargetDMCs, final RequestMonitor rm) {
		final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs =  
			new HashMap<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>>(bpsInfo.length, 1);
		
        CountingRequestMonitor processPendingCountingRm = new CountingRequestMonitor(getExecutor(), rm) {
                @Override
                protected void handleCompleted() {
                	processPendingRequests();
                	for (Map.Entry<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventEntry : eventBPs.entrySet()) {
                	    for (Map.Entry<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> bpEntry : eventEntry.getValue().entrySet()) {
                	        fPlatformBPs.get(bpEntry.getKey()).put(eventEntry.getKey(), Arrays.asList( bpEntry.getValue() ));
                	    }
                	}
                	fireUpdateBreakpointsStatus(eventBPs, BreakpointEventType.ADDED);
                	if (rm != null)
                		// don't call this if "rm" is null as this will 
                		// log errors if any and pack Eclipse error 
                		// log view with errors meaningless to user. 
                		super.handleCompleted();
                }
            };	            	
        int processPendingCountingRmCount = 0;
    	
    	for (final PlatformBreakpointInfo bpinfo : bpsInfo) {
    		final Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> targetBPs = 
    			new HashMap<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>(fPlatformBPs.size(), 1);
    		eventBPs.put(bpinfo.breakpoint, targetBPs);	
    	
			// Remember the new attributes of the bp in our global buffer,
			// even if we cannot or fail to install the bp.
			fBreakpointAttributes.put(bpinfo.breakpoint, bpinfo.attributes);
    		
			if (fRunningEvents.contains(bpinfo.breakpoint)) {
				PendingEventInfo pendingEvent = new PendingEventInfo(BreakpointEventType.ADDED, bpinfo, bpTargetDMCs, processPendingCountingRm);
				processPendingCountingRmCount++;
				updatePendingRequest(bpinfo.breakpoint, pendingEvent);
				continue;
			}
			
			processPendingCountingRmCount++;

            // Mark the breakpoint as being updated and go
            fRunningEvents.add(bpinfo.breakpoint);

    		final CountingRequestMonitor bpTargetsCountingRm = new CountingRequestMonitor(getExecutor(), processPendingCountingRm) {
				@Override
				protected void handleCompleted() {
                	// Indicate that the running event has completed
                	fRunningEvents.remove(bpinfo.breakpoint);
                	super.handleCompleted();
				}
    		};

			int bpTargetsCountingRmCount = 0;

			// Install the breakpoint in all the execution contexts
			for (final IBreakpointsTargetDMContext dmc : bpTargetDMCs) {
				
                // Now ask lower level to set the bp.
				//
				// if the breakpoint is disabled, ask back-end if it can set (and manage)
				// disabled breakpoint. If not, just bail out.
				//
				if (! bpinfo.enabled) {
					Map<String, Object> attr = new HashMap<String, Object>(1);
					attr.put(IBreakpoint.ENABLED, Boolean.FALSE);
					Map<String, Object> targetEnablementAttr = fAttributeTranslator2.convertAttributes(attr);
					if (! fAttributeTranslator2.canUpdateAttributes(bpinfo.breakpoint, dmc, targetEnablementAttr)) {
						// bail out. Continue with the next dmc & breakpoint.
						continue;
					}
				}
            	
				// Now do the real work.
				//
				fAttributeTranslator2.resolveBreakpoint(dmc, bpinfo.breakpoint, bpinfo.attributes,
						new DataRequestMonitor<List<Map<String,Object>>>(getExecutor(), bpTargetsCountingRm){
							@Override
							protected void handleSuccess() {
								installBreakpoint(
							    		dmc, bpinfo.breakpoint, getData(), 
							    		new DataRequestMonitor<List<TargetBP>>(getExecutor(), bpTargetsCountingRm) {
							    			@Override
											protected void handleSuccess() {
							    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
							    				super.handleSuccess();
							    			};
							    		});
							}});
				
				bpTargetsCountingRmCount++;
			}
			
			bpTargetsCountingRm.setDoneCount(bpTargetsCountingRmCount);
    	}
    	
    	processPendingCountingRm.setDoneCount(processPendingCountingRmCount);	            	
	}

    /**
     * @noreference This method is not intended to be referenced by clients.
     */
	@ThreadSafeAndProhibitedFromDsfExecutor("getExecutor()")
    @Override
	public void breakpointsChanged(IBreakpoint[] bps, IMarkerDelta[] deltas) {
		if (fAttributeTranslator2 == null)
			return;
		
		final PlatformBreakpointInfo[] bpsInfo = collectBreakpointsInfo(bps);
		
		if (bpsInfo.length == 0) 
			return; // nothing to do
		
		try {
	        getExecutor().execute( new DsfRunnable() { 
	            @Override
	            public void run() {
	            	Map<String, Object> tmp = new HashMap<String, Object>(1);
					tmp.put(IBreakpoint.ENABLED, true);
					final String targetEnablementKey = fAttributeTranslator2.convertAttributes(tmp).keySet().iterator().next();

					for (PlatformBreakpointInfo bpinfo : bpsInfo) {
						/*
						 * We cannot depend on "deltas" for attribute change.
						 * For instance, delta can be null when extended
						 * attributes (e.g. breakpoint thread filter for GDB)
						 * are changed.
						 */
						Map<String, Object> newAttrs = bpinfo.attributes;
						Map<String, Object> oldAttrs = fBreakpointAttributes.get(bpinfo.breakpoint);
						
						// remember the new attributes.
						fBreakpointAttributes.put(bpinfo.breakpoint, newAttrs);
		
						if (oldAttrs == null)
							continue;
						
						final Map<String, Object> attrDelta = getAttributesDelta(oldAttrs, newAttrs);
						if (attrDelta.size() == 0) 
							continue;

						final List<IBreakpointsTargetDMContext> reinstallContexts = new ArrayList<IBreakpointsTargetDMContext>();
						
						List<IBreakpointsTargetDMContext> updateContexts = new ArrayList<IBreakpointsTargetDMContext>();
						
						// Now change the breakpoint for each known context.
						//
						for (final IBreakpointsTargetDMContext btContext : fPlatformBPs.keySet()) {
							
							if (! fAttributeTranslator2.canUpdateAttributes(bpinfo.breakpoint, btContext, attrDelta)) {
								// backend cannot handle at least one of the platform BP attribute change,
								// we'll re-install the bp.
								reinstallContexts.add(btContext);
							}
							else {
								// Backend claims it can handle the attributes change, let it do it.
								updateContexts.add(btContext);
							}
							
						}

						final PlatformBreakpointInfo[] oneBPInfo = new PlatformBreakpointInfo[] {bpinfo};
						IBreakpoint[] oneBP = new IBreakpoint[] {bpinfo.breakpoint};

						if (reinstallContexts.size() > 0) {
							// Check if it's only enablement change (user click enable/disable 
							// button or "Skip all breakpoints" button), which is common operation.
							//
							if (attrDelta.size() == 1 && attrDelta.containsKey(targetEnablementKey)) { // only enablement changed.	
								if (bpinfo.enabled)  {
									// change from disable to enable. Install the bp.
									doBreakpointsAddedInExecutor(oneBPInfo, reinstallContexts, null);
								}
								else {
									// change from enable to disable. Remove the bp.
									doBreakpointsRemovedInExecutor(oneBP,  reinstallContexts, null);
								}
							}
							else {
								doBreakpointsRemovedInExecutor(oneBP, reinstallContexts, new RequestMonitor(getExecutor(), null) {
									// What should we do if removal of some or all targetBP fails ? 
									// Go on with the installation of new targetBPs and let clients (i.e. AttributeTranslators) 
									// handle the errors.
									@Override
									protected void handleCompleted() {
										doBreakpointsAddedInExecutor(oneBPInfo, reinstallContexts, null);
									}});
							}
						}
						
						if (updateContexts.size() > 0)
							modifyTargetBreakpoints(bpinfo.breakpoint, updateContexts, attrDelta);
	            	}
	            }
	        });
	    } catch (RejectedExecutionException e) {
			getPlugin().getLog().log(new Status(IStatus.ERROR, getPluginID(), IDsfStatusConstants.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e)); //$NON-NLS-1$ //$NON-NLS-2$
	    }

	}

	/**
	 * For the given platform BP, ask the backend to modify all its target BPs
	 * with the given attribute change. <br>
	 * This must be called in DSF executor thread.
	 * 
	 * @param bp
	 * @param updateContexts 
	 * 			  target contexts in which to do the modification.
	 * @param targetAttrDelta
	 *            target-recognizable attribute(s) with new values.
	 */
	private void modifyTargetBreakpoints(final IBreakpoint bp, Collection<IBreakpointsTargetDMContext> updateContexts, Map<String, Object> targetAttrDelta) {
		// If the breakpoint is currently being updated, queue the request and exit
    	if (fRunningEvents.contains(bp)) {
    		PendingEventInfo pendingEvent = new PendingEventInfo(BreakpointEventType.MODIFIED, updateContexts, targetAttrDelta);
    		updatePendingRequest(bp, pendingEvent);
			return;
    	}
		
    	CountingRequestMonitor modifyTargetBPCRM = new CountingRequestMonitor(getExecutor(), null) {
			@Override
			protected void handleCompleted() {
				fRunningEvents.remove(bp);
			}};
			
    	int targetBPCount = 0;
    	
    	fRunningEvents.add(bp);
    	
		for (IBreakpointsTargetDMContext context : updateContexts) {
			List<ITargetBreakpointInfo> targetBPs = fPlatformBPs.get(context).get(bp);
			if (targetBPs != null) {
				for (ITargetBreakpointInfo tbp : targetBPs) {
					// this must be an installed breakpoint.
					assert (tbp.getTargetBreakpoint() != null);
					
					targetBPCount++;
					fBreakpointsService.updateBreakpoint(tbp.getTargetBreakpoint(), targetAttrDelta, modifyTargetBPCRM);
				}
			}
		}
		
		modifyTargetBPCRM.setDoneCount(targetBPCount);
	}

	/**
	 * @noreference This method is not intended to be referenced by clients.
	 */
    @ThreadSafeAndProhibitedFromDsfExecutor("getExecutor()")
    @Override
	public void breakpointsRemoved(final IBreakpoint[] bps, IMarkerDelta delta[]) {
		getExecutor().execute(new DsfRunnable() {
		    @Override
			public void run() {
				for (IBreakpoint bp : bps)
					fBreakpointAttributes.remove(bp);
			}
		});
		
		doBreakpointsRemoved(bps, null, null);
	}
	
	private void doBreakpointsRemoved(final IBreakpoint[] bps, final IBreakpointsTargetDMContext bpsTargetDmc, final RequestMonitor rm) {
	
		final List<IBreakpoint> bpCandidates = new ArrayList<IBreakpoint>();
		
		for (int i = 0; i < bps.length; i++) {
			IBreakpoint bp = bps[i];
			
			if (fAttributeTranslator2.supportsBreakpoint(bp)) {
				bpCandidates.add(bp);
			}
		}
		
		if (bpCandidates.isEmpty()) { // nothing to do
			if (rm != null)
				rm.done();
			return;
		}
		
		try {
	        getExecutor().execute(new DsfRunnable() {
	            @Override
	        	public void run() {
					Collection<IBreakpointsTargetDMContext> contexts = new ArrayList<IBreakpointsTargetDMContext>();
					if (bpsTargetDmc == null)
						contexts.addAll(fPlatformBPs.keySet());
					else
						contexts.add(bpsTargetDmc);

					doBreakpointsRemovedInExecutor(bpCandidates.toArray(new IBreakpoint[bpCandidates.size()]), contexts, rm);
	        	}
	        });
        } catch (RejectedExecutionException e) {
			IStatus status = new Status(IStatus.ERROR, getPluginID(), IDsfStatusConstants.INTERNAL_ERROR, 
					"Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", e);//$NON-NLS-1$ //$NON-NLS-2$
			if (rm != null) {
				rm.setStatus(status);
				rm.done();
			} else {
				getPlugin().getLog().log(status); 
			}
        }
	}
	
	private void doBreakpointsRemovedInExecutor(IBreakpoint[] bpCandidates, 
			Collection<IBreakpointsTargetDMContext> targetContexts, final RequestMonitor rm) {
		
		final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs =  
			new HashMap<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>>(bpCandidates.length, 1);

		CountingRequestMonitor processPendingCountingRm = new CountingRequestMonitor(getExecutor(), rm) {
			@Override
			protected void handleCompleted() {
				processPendingRequests();
            	fireUpdateBreakpointsStatus(eventBPs, BreakpointEventType.REMOVED);
                for (Map.Entry<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventEntry : eventBPs.entrySet()) {
                    for (IBreakpointsTargetDMContext bpTarget : eventEntry.getValue().keySet()) {
                        fPlatformBPs.get(bpTarget).remove(eventEntry.getKey());
                    }
                }
            	if (rm != null)
            		// don't call this if "rm" is null as this will 
            		// log errors if any and pack Eclipse error 
            		// log view with errors meaningless to user. 
            		super.handleCompleted();
			}
		};
		int processPendingCountingRmCount = 0;
		
		for (final IBreakpoint breakpoint : bpCandidates) {

			// If the breakpoint is currently being updated, queue the request and exit
        	if (fRunningEvents.contains(breakpoint)) {
        		PendingEventInfo pendingEvent = new PendingEventInfo(BreakpointEventType.REMOVED, null, targetContexts, processPendingCountingRm);
                processPendingCountingRmCount++;
        		updatePendingRequest(breakpoint, pendingEvent);
				continue;	// handle next breakpoint
        	}

            processPendingCountingRmCount++;

            final Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]> targetBPs = 
    			new HashMap<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>(fPlatformBPs.size(), 1);
    		eventBPs.put(breakpoint, targetBPs);	
	
    		CountingRequestMonitor bpTargetsCountingRM = new CountingRequestMonitor(getExecutor(), processPendingCountingRm) {
				@Override
				protected void handleCompleted() {
					// Indicate that the running event has completed
                	fRunningEvents.remove(breakpoint);
                	super.handleCompleted();
				}
			};
            
			int bpTargetsCoutingRMCount = 0;

        	// Mark the breakpoint as being updated and go
            fRunningEvents.add(breakpoint);

    		// Remove the breakpoint in all the execution contexts
    		for (final IBreakpointsTargetDMContext dmc : targetContexts) {
    			
    			if (fPlatformBPs.get(dmc).containsKey(breakpoint)) {		// there are targetBPs installed 
    				// now do time-consuming part of the work.
    				
    				uninstallBreakpoint(
    						dmc, breakpoint,
    						new DataRequestMonitor<List<ITargetBreakpointInfo>>(getExecutor(), bpTargetsCountingRM) {
				    			@Override
								protected void handleSuccess() {
				    				targetBPs.put(dmc, getData().toArray(new ITargetBreakpointInfo[getData().size()]));
				    				super.handleSuccess();
				    			};
    						});
    				bpTargetsCoutingRMCount++;
    			} else {
    				// Breakpoint not installed for given context, do nothing.
    			}
    		}
    		
    		bpTargetsCountingRM.setDoneCount(bpTargetsCoutingRMCount);
		}
		
		processPendingCountingRm.setDoneCount(processPendingCountingRmCount);
	}

	private void updatePendingRequest(IBreakpoint breakpoint, PendingEventInfo pendingEvent) {
		LinkedList<PendingEventInfo> pendingEventsList = fPendingEvents.get(breakpoint);
		if (pendingEventsList == null) {
			pendingEventsList = new LinkedList<PendingEventInfo>();
			fPendingEvents.put(breakpoint, pendingEventsList);
		}
		if (pendingEventsList.size() > 0 &&
				pendingEventsList.getLast().fEventType == BreakpointEventType.MODIFIED) {
			pendingEventsList.removeLast();
		}
		pendingEventsList.add(pendingEvent);
	}
	
	private void processPendingRequests() {
		/*
		 * This will process only first pending request for each breakpoint,
		 * whose RequestMonitor (see "processPendingCountingRm" in such methods as 
		 * doBreakpointsRemovedInExecutor()) will invoke this method again.   
		 */
		if (fPendingEvents.isEmpty()) return;  // Nothing to do
		
		// Make a copy to avoid ConcurrentModificationException
		// as we are deleting element in the loop.
		Set<IBreakpoint> bpsInPendingEvents = new HashSet<IBreakpoint>(fPendingEvents.keySet()); 
		for (IBreakpoint bp : bpsInPendingEvents) {
	    	if (! fRunningEvents.contains(bp)) {
				LinkedList<PendingEventInfo> eventInfoList = fPendingEvents.get(bp);

		    	// Process the first pending request for this breakpoint
		   		PendingEventInfo eventInfo = eventInfoList.removeFirst();
	
				if (eventInfoList.isEmpty())
					fPendingEvents.remove(bp);
	
				switch (eventInfo.fEventType) {
				case ADDED:
					doBreakpointsAddedInExecutor(new PlatformBreakpointInfo[] {eventInfo.fBPInfo}, eventInfo.fBPTargetContexts, eventInfo.fRequestMonitor);
					break;
				case MODIFIED:
					modifyTargetBreakpoints(bp, eventInfo.fBPTargetContexts, eventInfo.fAttributeDelta);
					break;
				case REMOVED:
					doBreakpointsRemovedInExecutor(new IBreakpoint[]{bp}, eventInfo.fBPTargetContexts, eventInfo.fRequestMonitor);
					break;
				}
	    	}
		}
	}
	
	private void fireUpdateBreakpointsStatus(final Map<IBreakpoint, Map<IBreakpointsTargetDMContext, ITargetBreakpointInfo[]>> eventBPs, final BreakpointEventType eventType) {
        // Update breakpoint status
        new Job("Breakpoint status update") { //$NON-NLS-1$
            { setSystem(true); }
            @Override
            protected IStatus run(IProgressMonitor monitor) {
               	fAttributeTranslator2.updateBreakpointsStatus(eventBPs, eventType);
                return Status.OK_STATUS;
            };
        }.schedule();
		
	}

    /**
     * Determine the set of modified attributes.
     * 
     * @param oldAttributes old map of attributes.
     * @param newAttributes new map of attributes.
     * @return new and changed attribute in the new map. May be empty indicating the two maps are equal.
     */
    private Map<String, Object> getAttributesDelta(Map<String, Object> oldAttributes, Map<String, Object> newAttributes) {

        Map<String, Object> delta = new HashMap<String,Object>();

        Set<String> oldKeySet = oldAttributes.keySet();
        Set<String> newKeySet = newAttributes.keySet();

        Set<String> commonKeys  = new HashSet<String>(newKeySet); commonKeys.retainAll(oldKeySet);
        Set<String> addedKeys   = new HashSet<String>(newKeySet); addedKeys.removeAll(oldKeySet);
        Set<String> removedKeys = new HashSet<String>(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);
        }

        return delta;
    }
}

Back to the top