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