cdt/cdt_6_0_x/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIBreakpoints.java
author l12wang
Mon, 23 Nov 2009 00:59:16 -0600
changeset 117 09f3d307f081
parent 37 c2bce6dd59e7
child 122 d94b9ba55bed
permissions -rw-r--r--
Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
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 Ericsson 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
 *     Ericsson - Initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
package org.eclipse.cdt.dsf.mi.service;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
import java.util.HashMap;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.Hashtable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import java.util.Map;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    18
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    19
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import org.eclipse.cdt.dsf.concurrent.Immutable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.cdt.dsf.datamodel.AbstractDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.dsf.datamodel.DMContexts;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.dsf.datamodel.IDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import org.eclipse.cdt.dsf.debug.service.IBreakpoints;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
import org.eclipse.cdt.dsf.debug.service.command.ICommandControl;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlShutdownDMEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    32
import org.eclipse.cdt.dsf.mi.service.MIRunControl.SuspendedEvent;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    33
import org.eclipse.cdt.dsf.mi.service.breakpoint.actions.BreakpointActionAdapter;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakAfter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakCondition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakDelete;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakDisable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakEnable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakInsert;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakWatch;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    42
import org.eclipse.cdt.dsf.mi.service.command.events.MIBreakpointHitEvent;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
import org.eclipse.cdt.dsf.mi.service.command.events.MIWatchpointScopeEvent;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    44
import org.eclipse.cdt.dsf.mi.service.command.events.MIWatchpointTriggerEvent;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakListInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
import org.eclipse.cdt.dsf.service.AbstractDsfService;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
import org.eclipse.cdt.dsf.service.DsfSession;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    52
import org.eclipse.core.runtime.CoreException;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    53
import org.eclipse.core.runtime.IProgressMonitor;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
import org.eclipse.core.runtime.IStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
import org.eclipse.core.runtime.Status;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
    56
import org.eclipse.core.runtime.jobs.Job;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
import org.osgi.framework.BundleContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
 * Initial breakpoint service implementation.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
 * Implements the IBreakpoints interface.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
public class MIBreakpoints extends AbstractDsfService implements IBreakpoints
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
     * Breakpoint attributes markers used in the map parameters of insert/updateBreakpoint().
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
     * All are optional with the possible exception of TYPE. It is the responsibility of the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
     * service to ensure that the set of attributes provided is sufficient to create/update
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
     * a valid breakpoint on the back-end.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
    public static final String PREFIX   = "org.eclipse.cdt.dsf.debug.breakpoint"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
    // General markers
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
    public static final String BREAKPOINT_TYPE = PREFIX + ".type";      //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
    public static final String BREAKPOINT      = "breakpoint";          //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
    public static final String WATCHPOINT      = "watchpoint";          //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
    public static final String CATCHPOINT      = "catchpoint";          //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
    // Basic set of breakpoint attribute markers
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
    public static final String FILE_NAME     = PREFIX + ".fileName";    //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    81
    public static final String LINE_NUMBER   = PREFIX + ".lineNumber";  //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
    public static final String FUNCTION      = PREFIX + ".function";    //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
    public static final String ADDRESS       = PREFIX + ".address";     //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    84
    public static final String CONDITION     = PREFIX + ".condition";   //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
    public static final String IGNORE_COUNT  = PREFIX + ".ignoreCount"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
    public static final String IS_ENABLED    = PREFIX + ".isEnabled";   //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
    // Basic set of watchpoint attribute markers
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    89
    public static final String EXPRESSION    = PREFIX + ".expression";  //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
    public static final String READ          = PREFIX + ".read";        //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    91
    public static final String WRITE         = PREFIX + ".write";       //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    93
	// Services
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    94
	ICommandControl fConnection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    95
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    96
	// Service breakpoints tracking
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
	// The breakpoints are stored per context and keyed on the back-end breakpoint reference
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    98
	private Map<IBreakpointsTargetDMContext, Map<Integer, MIBreakpointDMData>> fBreakpoints =
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
		new HashMap<IBreakpointsTargetDMContext, Map<Integer, MIBreakpointDMData>>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
	// Error messages
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
	final String NULL_STRING = ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   103
	final String UNKNOWN_EXECUTION_CONTEXT    = "Unknown execution context";    //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   104
	final String UNKNOWN_BREAKPOINT_CONTEXT   = "Unknown breakpoint context";   //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   105
	final String UNKNOWN_BREAKPOINT_TYPE      = "Unknown breakpoint type";      //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   106
	final String UNKNOWN_BREAKPOINT           = "Unknown breakpoint";           //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   107
	final String BREAKPOINT_INSERTION_FAILURE = "Breakpoint insertion failure"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   108
	final String WATCHPOINT_INSERTION_FAILURE = "Watchpoint insertion failure"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   109
	final String INVALID_CONDITION            = "Invalid condition";            //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   110
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   111
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   112
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   113
	// Breakpoint Events
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
    public class BreakpointsChangedEvent extends AbstractDMEvent<IBreakpointsTargetDMContext> implements IBreakpointsChangedEvent {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   117
    	private IBreakpointDMContext[] fEventBreakpoints;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   118
 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   119
		public BreakpointsChangedEvent(IBreakpointDMContext bp) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   120
			super(DMContexts.getAncestorOfType(bp, IBreakpointsTargetDMContext.class));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   121
			fEventBreakpoints = new IBreakpointDMContext[] { bp };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   122
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   123
		public IBreakpointDMContext[] getBreakpoints() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   124
			return fEventBreakpoints;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   125
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   126
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   127
    
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   128
    public class BreakpointAddedEvent extends BreakpointsChangedEvent implements IBreakpointsAddedEvent {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   129
    	public BreakpointAddedEvent(IBreakpointDMContext context) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   130
            super(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   131
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   132
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   133
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   134
    public class BreakpointUpdatedEvent extends BreakpointsChangedEvent implements IBreakpointsUpdatedEvent {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   135
        public BreakpointUpdatedEvent(IBreakpointDMContext context) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   136
            super(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   137
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   138
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   139
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   140
    public class BreakpointRemovedEvent extends BreakpointsChangedEvent implements IBreakpointsRemovedEvent {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   141
        public BreakpointRemovedEvent(IBreakpointDMContext context) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   142
            super(context);
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
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   146
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
	// IBreakpointDMContext
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
	// Used to hold the back-end breakpoint references. The reference can then
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
	// be used to get the actual DsfMIBreakpoint.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
	@Immutable
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
    public static final class MIBreakpointDMContext extends AbstractDMContext implements IBreakpointDMContext {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   153
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   154
    	// The breakpoint reference
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
    	private final Integer fReference;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
    	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
    	 * @param service       the Breakpoint service
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
    	 * @param parents       the parent contexts
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
    	 * @param reference     the DsfMIBreakpoint reference
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   161
    	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   162
    	public MIBreakpointDMContext(MIBreakpoints service, IDMContext[] parents, int reference) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   163
            super(service.getSession().getId(), parents);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   164
            fReference = reference;
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
		/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   168
    	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints.IDsfBreakpointDMContext#getReference()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   169
    	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   170
    	public int getReference() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   171
    		return fReference;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   172
    	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   173
 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
        /* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
         * @see org.eclipse.cdt.dsf.datamodel.AbstractDMContext#equals(java.lang.Object)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
         */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   178
        public boolean equals(Object obj) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   179
            return baseEquals(obj) && (fReference == ((MIBreakpointDMContext) obj).fReference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
        /* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
         * @see org.eclipse.cdt.dsf.datamodel.AbstractDMContext#hashCode()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
         */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
        public int hashCode() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
            return baseHashCode() + fReference.hashCode();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
        /* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
         * @see java.lang.Object#toString()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
         */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   194
        public String toString() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   195
            return baseToString() + ".reference(" + fReference + ")";  //$NON-NLS-1$//$NON-NLS-2$*/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   196
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   197
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
	// AbstractDsfService
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
	 * The service constructor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
	 * @param session           The debugging session
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
	public MIBreakpoints(DsfSession session) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
		super(session);
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
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#initialize(org.eclipse.cdt.dsf.concurrent.RequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
	public void initialize(final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
		super.initialize(new RequestMonitor(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
			protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
				doInitialize(rm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
	 * Asynchronous service initialization
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
	private void doInitialize(final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
    	// Get the services references
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
		fConnection = getServicesTracker().getService(ICommandControl.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   233
        // Register for the useful events
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   234
		getSession().addServiceEventListener(this, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   235
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   236
		// Register this service
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   237
		register(new String[] { IBreakpoints.class.getName(), MIBreakpoints.class.getName() },
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   238
				new Hashtable<String, String>());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   239
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   240
		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   241
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   242
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   243
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   244
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#shutdown(org.eclipse.cdt.dsf.concurrent.RequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   245
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   246
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   247
	public void shutdown(final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   248
		unregister();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   249
		getSession().removeServiceEventListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   250
		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   251
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   252
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   253
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   254
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#getBundleContext()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
	protected BundleContext getBundleContext() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
		return GdbPlugin.getBundleContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
    // IServiceEventListener
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
    ///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
     * This method is left for API compatibility only.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
     * @nooverride This method is not intended to be re-implemented or extended by clients.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
     * @noreference This method is not intended to be referenced by clients.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
	@DsfServiceEventHandler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
	public void eventDispatched(MIWatchpointScopeEvent e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
	    // When a watchpoint goes out of scope, it is automatically removed from
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
	    // the back-end. To keep our internal state synchronized, we have to
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
	    // remove it from our breakpoints map.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
	    IBreakpointsTargetDMContext bpContext = DMContexts.getAncestorOfType(e.getDMContext(), IBreakpointsTargetDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
	    if (bpContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
	        Map<Integer, MIBreakpointDMData> contextBps = fBreakpoints.get(bpContext);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
	        if (contextBps != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
	            contextBps.remove(e.getNumber());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   280
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   281
	    }
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
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   285
     * @since 1.1
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   286
     * @nooverride This method is not intended to be re-implemented or extended by clients.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   287
     * @noreference This method is not intended to be referenced by clients.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   288
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   289
    @DsfServiceEventHandler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   290
    public void eventDispatched(ICommandControlShutdownDMEvent e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   291
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   292
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   293
	@DsfServiceEventHandler 
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   294
    public void eventDispatched(SuspendedEvent e) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   295
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   296
		if (e.getMIEvent() instanceof MIBreakpointHitEvent) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   297
			MIBreakpointHitEvent evt = (MIBreakpointHitEvent) e.getMIEvent();
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   298
	        performBreakpointAction(evt.getDMContext(), evt.getNumber());
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   299
	        return;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   300
		}
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   301
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   302
		if (e.getMIEvent() instanceof MIWatchpointTriggerEvent) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   303
			MIWatchpointTriggerEvent evt = (MIWatchpointTriggerEvent) e.getMIEvent();
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   304
	        performBreakpointAction(evt.getDMContext(), evt.getNumber());
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   305
	        return;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   306
		}
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   307
	}
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   308
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   309
    private void performBreakpointAction(final IDMContext context, int number) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   310
        // Identify the platform breakpoint
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   311
        final ICBreakpoint breakpoint = findPlatformBreakpoint(context, number);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   312
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   313
        // Perform the actions asynchronously (otherwise we can have a deadlock...)
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   314
        new Job("Breakpoint action") { //$NON-NLS-1$
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   315
            { setSystem(true); }
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   316
            @Override
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   317
            protected IStatus run(IProgressMonitor monitor) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   318
            	CDebugCorePlugin.getDefault().getBreakpointActionManager().executeActions(breakpoint, new BreakpointActionAdapter(getExecutor(), getServicesTracker(), context));
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   319
                return Status.OK_STATUS;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   320
            };
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   321
        }.schedule();
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   322
    }
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   323
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   324
    // Helper function to locate the platform breakpoint corresponding
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   325
    // to the target breakpoint/watchpoint that was just hit
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   326
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   327
    // FIXME: (Bug228703) Need a way to identify the correct context where the BP was hit
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   328
    private ICBreakpoint findPlatformBreakpoint(IDMContext context, int targetBreakpointID) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   329
    	// Hmm, the service has no tracking of MIBreakpointDMContext. So this workaround.
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   330
    	IBreakpointsTargetDMContext btDMC = DMContexts.getAncestorOfType(context, IBreakpointsTargetDMContext.class);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   331
    	assert btDMC != null;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   332
    	IBreakpointDMContext dmc = new MIBreakpointDMContext(MIBreakpoints.this, new IDMContext[] { btDMC }, targetBreakpointID);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   333
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   334
		MIBreakpointsManager bpMediator = getServicesTracker().getService(MIBreakpointsManager.class);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   335
		ICBreakpoint cdtBP = (ICBreakpoint)bpMediator.getPlatformBreakpoint(btDMC, dmc);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   336
    	
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   337
        return cdtBP;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   338
    }
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   339
    
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   340
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   341
	// IBreakpoints interface
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   342
	///////////////////////////////////////////////////////////////////////////
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   343
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   344
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   345
	// getBreakpoints
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   346
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   347
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   348
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   349
	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints#getBreakpoints(org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext, org.eclipse.cdt.dsf.concurrent.DataRequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   350
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   351
	public void getBreakpoints(final IBreakpointsTargetDMContext context, final DataRequestMonitor<IBreakpointDMContext[]> drm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   352
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   353
		// Validate the context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   354
		if (context == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   355
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_EXECUTION_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   356
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   357
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   358
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   359
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   360
		// Select the breakpoints context map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   361
		// If it doesn't exist then no breakpoint was ever inserted for this breakpoint space.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   362
		// In that case, return an empty list.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   363
		final Map<Integer, MIBreakpointDMData> breakpointContext = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   364
		if (breakpointContext == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   365
       		drm.setData(new IBreakpointDMContext[0]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   366
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   367
			return;
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
		// Execute the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   371
		fConnection.queueCommand(new MIBreakList(context),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   372
			new DataRequestMonitor<MIBreakListInfo>(getExecutor(), drm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   373
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   374
				protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   375
					// Refresh the breakpoints map and format the result
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   376
					breakpointContext.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   377
					MIBreakpoint[] breakpoints = getData().getMIBreakpoints();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   378
					IBreakpointDMContext[] result = new IBreakpointDMContext[breakpoints.length];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   379
					for (int i = 0; i < breakpoints.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   380
						MIBreakpointDMData breakpoint = new MIBreakpointDMData(breakpoints[i]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   381
						int reference = breakpoint.getReference();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   382
						result[i] = new MIBreakpointDMContext(MIBreakpoints.this, new IDMContext[] { context }, reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   383
						breakpointContext.put(reference, breakpoint);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   384
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   385
					drm.setData(result);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   386
					drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   387
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   388
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   389
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   390
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   391
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   392
	// getBreakpointDMData
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   393
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   394
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   395
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   396
	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints#getBreakpointDMData(org.eclipse.cdt.dsf.debug.service.IBreakpoints.IDsfBreakpointDMContext, org.eclipse.cdt.dsf.concurrent.DataRequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   397
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   398
	public void getBreakpointDMData(IBreakpointDMContext dmc, DataRequestMonitor<IBreakpointDMData> drm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   399
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   400
		// Validate the breakpoint context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   401
		if (dmc == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   402
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   403
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   404
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   405
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   406
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   407
		// Validate the breakpoint type
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   408
		MIBreakpointDMContext breakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   409
		if (dmc instanceof MIBreakpointDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   410
			breakpoint = (MIBreakpointDMContext) dmc;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   411
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   412
		else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   413
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_TYPE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   414
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   415
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   416
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   417
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   418
		// Validate the target context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   419
		IBreakpointsTargetDMContext context = DMContexts.getAncestorOfType(breakpoint, IBreakpointsTargetDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   420
		if (context == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   421
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_EXECUTION_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   422
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   423
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   424
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   425
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   426
		// Select the breakpoints context map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   427
		Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   428
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   429
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   430
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   431
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   432
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   433
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   434
		// No need to go to the back-end for this one
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   435
		IBreakpointDMData breakpointCopy = new MIBreakpointDMData(contextBreakpoints.get(breakpoint.getReference()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   436
		drm.setData(breakpointCopy);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   437
		drm.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
	// insertBreakpoint
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
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   445
	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints#insertBreakpoint(org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext, java.util.Map, org.eclipse.cdt.dsf.concurrent.DataRequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   446
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   447
	public void insertBreakpoint(IBreakpointsTargetDMContext context, Map<String, Object> attributes, DataRequestMonitor<IBreakpointDMContext> drm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   448
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   449
		// Validate the context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   450
		if (context == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   451
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_EXECUTION_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   452
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   453
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   454
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   455
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   456
		// Select the breakpoints context map. If it doesn't exist, create it.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   457
		Map<Integer, MIBreakpointDMData> breakpointContext = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   458
		if (breakpointContext == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   459
			breakpointContext = new HashMap<Integer, MIBreakpointDMData>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   460
			fBreakpoints.put(context, breakpointContext);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   461
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   462
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   463
		// Validate the breakpoint type
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   464
		String type = (String) attributes.get(BREAKPOINT_TYPE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   465
		if (type == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   466
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_TYPE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   467
   			drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   468
   			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   469
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   470
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   471
		// And go...
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   472
		if (type.equals(BREAKPOINT)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   473
			addBreakpoint(context, attributes, drm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   474
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   475
		else if (type.equals(WATCHPOINT)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   476
			addWatchpoint(context, attributes, drm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   477
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   478
		else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   479
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_TYPE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   480
   			drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   481
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   482
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   483
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   484
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   485
	 * @param map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   486
	 * @param key
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   487
	 * @param defaultValue
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   488
	 * @return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   489
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   490
	public Object getProperty(Map<String, Object> map, String key, Object defaultValue) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   491
		return (map.containsKey(key) && (map.get(key) != null)) ? map.get(key) : defaultValue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   492
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   493
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   494
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   495
	 * @param attributes
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
	private String formatLocation(Map<String, Object> attributes) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   499
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   500
		// Unlikely default location
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   501
		String location = (String)  getProperty(attributes, ADDRESS, NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   502
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   503
		// Get the relevant parameters
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   504
		String  fileName   = (String)  getProperty(attributes, FILE_NAME, NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   505
		Integer lineNumber = (Integer) getProperty(attributes, LINE_NUMBER, -1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   506
		String  function   = (String)  getProperty(attributes, FUNCTION,  NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   507
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   508
		// Fix for Bug264721
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   509
		if (fileName.contains(" ")) { //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   510
			fileName = "\"" + fileName + "\"";  //$NON-NLS-1$//$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   511
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   512
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   513
		if (!fileName.equals(NULL_STRING)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   514
			if (lineNumber != -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   515
				location = fileName + ":" + lineNumber; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   516
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   517
				location = fileName + ":" + function;   //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   518
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   519
		} else if (!function.equals(NULL_STRING)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   520
			// function location without source
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   521
			location = function;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   522
		} else if (location.length() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   523
			// address location
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   524
			if (Character.isDigit(location.charAt(0))) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   525
				// numeric address needs '*' prefix
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   526
				location = '*' + location;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   527
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   528
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   529
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   530
		return location;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   531
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   532
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   533
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   534
	 * Add a breakpoint of type BREAKPOINT
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   535
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   536
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   537
	 * @param breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   538
	 * @param drm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   539
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   540
	private void addBreakpoint(final IBreakpointsTargetDMContext context, final Map<String, Object> attributes, final DataRequestMonitor<IBreakpointDMContext> drm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   541
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   542
		// Select the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   543
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   544
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   545
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   546
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   547
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   548
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   549
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   550
		// Extract the relevant parameters (providing default values to avoid potential NPEs)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   551
		String location = formatLocation(attributes);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   552
		if (location.equals(NULL_STRING)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   553
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   554
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   555
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   556
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   557
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   558
		Boolean isTemporary    = (Boolean) getProperty(attributes, MIBreakpointDMData.IS_TEMPORARY, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   559
		Boolean isHardware     = (Boolean) getProperty(attributes, MIBreakpointDMData.IS_HARDWARE,  false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   560
		final String condition = (String)  getProperty(attributes, CONDITION,    NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   561
		Integer ignoreCount    = (Integer) getProperty(attributes, IGNORE_COUNT,          0 );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   562
		String  threadId       = (String)  getProperty(attributes, MIBreakpointDMData.THREAD_ID,      "0"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   563
		int     tid            = Integer.parseInt(threadId);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   564
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   565
		// The DataRequestMonitor for the add request
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   566
		DataRequestMonitor<MIBreakInsertInfo> addBreakpointDRM =
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   567
			new DataRequestMonitor<MIBreakInsertInfo>(getExecutor(), drm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   568
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   569
	            protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   570
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   571
	            	// With MI, an invalid location won't generate an error
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   572
                	if (getData().getMIBreakpoints().length == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   573
                   		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, BREAKPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   574
                   		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   575
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   576
                    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   577
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   578
                	// Create a breakpoint object and store it in the map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   579
                	final MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(getData().getMIBreakpoints()[0]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   580
                	int reference = newBreakpoint.getNumber();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   581
                	if (reference == -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   582
                   		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, BREAKPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   583
                   		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   584
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   585
                	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   586
                	contextBreakpoints.put(reference, newBreakpoint);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   587
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   588
               		// Format the return value
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   589
               		MIBreakpointDMContext dmc = new MIBreakpointDMContext(MIBreakpoints.this, new IDMContext[] { context }, reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   590
               		drm.setData(dmc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   591
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   592
               		// Flag the event
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   593
					getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   594
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   595
					// By default the breakpoint is enabled at creation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   596
                	// If it wasn't supposed to be, then disable it right away
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   597
               		Map<String,Object> delta = new HashMap<String,Object>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   598
               		delta.put(IS_ENABLED, getProperty(attributes, IS_ENABLED, true));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   599
               		modifyBreakpoint(dmc, delta, drm, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   600
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   601
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   602
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   603
	            protected void handleError() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   604
               		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, BREAKPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   605
               		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   606
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   607
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   608
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   609
		// Execute the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   610
        fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   611
            new MIBreakInsert(context, isTemporary, isHardware, condition, ignoreCount, location, tid), addBreakpointDRM);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   612
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   613
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   614
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   615
	 * Add a breakpoint of type WATCHPOINT
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   616
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   617
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   618
	 * @param watchpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   619
	 * @param drm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   620
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   621
	private void addWatchpoint(final IBreakpointsTargetDMContext context, final Map<String, Object> attributes, final DataRequestMonitor<IBreakpointDMContext> drm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   622
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   623
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   624
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   625
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   626
       		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   627
       		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   628
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   629
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   630
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   631
		// Extract the relevant parameters (providing default values to avoid potential NPEs)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   632
		String expression = (String)  getProperty(attributes, EXPRESSION, NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   633
		boolean isRead    = (Boolean) getProperty(attributes, READ,    false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   634
		boolean isWrite   = (Boolean) getProperty(attributes, WRITE,   false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   635
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   636
		// The DataRequestMonitor for the add request
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   637
		DataRequestMonitor<MIBreakInsertInfo> addWatchpointDRM =
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   638
			new DataRequestMonitor<MIBreakInsertInfo>(getExecutor(), drm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   639
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   640
	            protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   641
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   642
	            	// With MI, an invalid location won't generate an error
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   643
                	if (getData().getMIBreakpoints().length == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   644
                   		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, WATCHPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   645
                   		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   646
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   647
                    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   648
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   649
                	// Create a breakpoint object and store it in the map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   650
                	final MIBreakpointDMData newBreakpoint = new MIBreakpointDMData(getData().getMIBreakpoints()[0]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   651
                	int reference = newBreakpoint.getNumber();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   652
                	if (reference == -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   653
                   		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, WATCHPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   654
                   		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   655
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   656
                	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   657
                	contextBreakpoints.put(reference, newBreakpoint);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   658
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   659
               		// Format the return value
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   660
               		IBreakpointDMContext dmc = new MIBreakpointDMContext(MIBreakpoints.this, new IDMContext[] { context }, reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   661
               		drm.setData(dmc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   662
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   663
               		// Flag the event
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   664
					getSession().dispatchEvent(new BreakpointAddedEvent(dmc), getProperties());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   665
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   666
               		// Condition, ignore count and state can not be specified at watchpoint creation time.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   667
               		// Therefore, we have to update the watchpoint if any of these is present
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   668
               		Map<String,Object> delta = new HashMap<String,Object>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   669
               		delta.put(CONDITION,    getProperty(attributes, CONDITION, NULL_STRING));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   670
               		delta.put(IGNORE_COUNT, getProperty(attributes, IGNORE_COUNT, 0 ));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   671
               		delta.put(IS_ENABLED,   getProperty(attributes, IS_ENABLED, true));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   672
               		modifyBreakpoint(dmc, delta, drm, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   673
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   674
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   675
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   676
	            protected void handleError() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   677
               		drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, WATCHPOINT_INSERTION_FAILURE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   678
               		drm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   679
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   680
			};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   681
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   682
			// Execute the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   683
	        fConnection.queueCommand(new MIBreakWatch(context, isRead, isWrite, expression), addWatchpointDRM);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   684
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   685
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   686
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   687
	// removeBreakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   688
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   689
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   690
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   691
	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints#removeBreakpoint(org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext, org.eclipse.cdt.dsf.concurrent.RequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   692
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   693
	public void removeBreakpoint(final IBreakpointDMContext dmc, final RequestMonitor rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   694
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   695
		// Validate the breakpoint context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   696
		if (dmc == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   697
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   698
			rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   699
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   700
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   701
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   702
		// Validate the breakpoint type
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   703
		MIBreakpointDMContext breakpointCtx;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   704
		if (dmc instanceof MIBreakpointDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   705
			breakpointCtx = (MIBreakpointDMContext) dmc;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   706
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   707
		else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   708
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_TYPE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   709
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   710
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   711
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   712
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   713
		// Validate the target context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   714
        IBreakpointsTargetDMContext context = DMContexts.getAncestorOfType(dmc, IBreakpointsTargetDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   715
		if (context == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   716
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_EXECUTION_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   717
			rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   718
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   719
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   720
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   721
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   722
		final Map<Integer,MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   723
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   724
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   725
			rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   726
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   727
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   728
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   729
		// Validate the breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   730
		final int reference = breakpointCtx.getReference();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   731
		MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   732
		if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   733
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   734
			rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   735
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   736
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   737
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   738
		// Queue the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   739
		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   740
			new MIBreakDelete(context, new int[] { reference }),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   741
			new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   742
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   743
				protected void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   744
					if (isSuccess()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   745
						getSession().dispatchEvent(new BreakpointRemovedEvent(dmc), getProperties());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   746
						contextBreakpoints.remove(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   747
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   748
					rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   749
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   750
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   751
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   752
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   753
	// -------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   754
	// updateBreakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   755
	//-------------------------------------------------------------------------
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   756
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   757
	/* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   758
	 * @see org.eclipse.cdt.dsf.debug.service.IBreakpoints#updateBreakpoint(org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext, java.util.Map, org.eclipse.cdt.dsf.concurrent.RequestMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   759
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   760
	public void updateBreakpoint(IBreakpointDMContext dmc, Map<String, Object> properties, RequestMonitor rm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   761
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   762
		// Validate the breakpoint context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   763
		if (dmc == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   764
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   765
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   766
			return;
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
		// Validate the breakpoint type
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   770
		MIBreakpointDMContext breakpointCtx;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   771
		if (dmc instanceof MIBreakpointDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   772
			breakpointCtx = (MIBreakpointDMContext) dmc;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   773
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   774
		else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   775
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_TYPE, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   776
			rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   777
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   778
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   779
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   780
		// Validate the context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   781
        IBreakpointsTargetDMContext context = DMContexts.getAncestorOfType(dmc, IBreakpointsTargetDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   782
		if (context == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   783
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_EXECUTION_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   784
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   785
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   786
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   787
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   788
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   789
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   790
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   791
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   792
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   793
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   794
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   795
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   796
		// Validate the breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   797
		final int reference = breakpointCtx.getReference();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   798
		MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   799
		if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   800
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   801
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   802
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   803
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   804
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   805
        modifyBreakpoint(dmc, properties, rm, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   806
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   807
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   808
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   809
	 * @param dmc
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   810
	 * @param properties
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   811
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   812
	 * @param generateUpdateEvent
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   813
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   814
	private void modifyBreakpoint(final IBreakpointDMContext dmc, Map<String, Object> attributes, final RequestMonitor rm, final boolean generateUpdateEvent)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   815
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   816
		// Use a working copy of the attributes since we are going to tamper happily with them
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   817
		Map<String, Object> properties = new HashMap<String, Object>(attributes);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   818
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   819
		// Retrieve the breakpoint parameters
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   820
		// At this point, we know their are OK so there is no need to re-validate
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   821
		MIBreakpointDMContext breakpointCtx = (MIBreakpointDMContext) dmc;
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   822
        final IBreakpointsTargetDMContext context = DMContexts.getAncestorOfType(dmc, IBreakpointsTargetDMContext.class);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   823
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   824
		final int reference = breakpointCtx.getReference();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   825
		MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   826
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   827
		// Track the number of change requests
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   828
		int numberOfChanges = 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   829
        final CountingRequestMonitor countingRm = new CountingRequestMonitor(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   830
            @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   831
            protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   832
           		if (generateUpdateEvent)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   833
           			getSession().dispatchEvent(new BreakpointUpdatedEvent(dmc), getProperties());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   834
        		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   835
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   836
        };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   837
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   838
        // Determine if the breakpoint condition changed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   839
		String conditionAttribute = CONDITION;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   840
		if (properties.containsKey(conditionAttribute)) {
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   841
			final String oldValue = breakpoint.getCondition();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   842
			String newValue = (String) properties.get(conditionAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   843
			if (newValue == null) newValue = NULL_STRING;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   844
	        if (!oldValue.equals(newValue)) {
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   845
	        	changeCondition(context, reference, newValue, new RequestMonitor(getExecutor(), countingRm){
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   846
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   847
					@Override
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   848
					protected void handleError() {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   849
						// Failed to change the condition, restore the old condition.
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   850
						// See comment in changeCondition() for more.
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   851
						MIBreakpointsManager bpMediator = getServicesTracker().getService(MIBreakpointsManager.class);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   852
						final ICBreakpoint cdtBP = (ICBreakpoint)bpMediator.getPlatformBreakpoint(context, dmc);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   853
						rollbackCondition(cdtBP, oldValue);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   854
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   855
						countingRm.done();
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   856
					}});
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   857
	        	numberOfChanges++;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   858
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   859
			properties.remove(conditionAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   860
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   861
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   862
        // Determine if the breakpoint ignore count changed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   863
		String ignoreCountAttribute = IGNORE_COUNT;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   864
		if (properties.containsKey(ignoreCountAttribute)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   865
			Integer oldValue = breakpoint.getIgnoreCount();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   866
			Integer newValue = (Integer) properties.get(ignoreCountAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   867
			if (newValue == null) newValue = 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   868
	        if (!oldValue.equals(newValue)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   869
	        	changeIgnoreCount(context, reference, newValue, countingRm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   870
	        	numberOfChanges++;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   871
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   872
			properties.remove(ignoreCountAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   873
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   874
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   875
        // Determine if the breakpoint state changed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   876
		String enableAttribute = IS_ENABLED;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   877
		if (properties.containsKey(enableAttribute)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   878
			Boolean oldValue = breakpoint.isEnabled();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   879
			Boolean newValue = (Boolean) properties.get(enableAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   880
			if (newValue == null) newValue = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   881
	        if (!oldValue.equals(newValue)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   882
	        	numberOfChanges++;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   883
				if (newValue)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   884
					enableBreakpoint(context, reference, countingRm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   885
				else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   886
					disableBreakpoint(context, reference, countingRm);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   887
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   888
			properties.remove(enableAttribute);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   889
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   890
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   891
		// Set the number of completions required
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   892
        countingRm.setDoneCount(numberOfChanges);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   893
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   894
117
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   895
	private void rollbackCondition(final ICBreakpoint cdtBP, final String oldValue) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   896
		if (cdtBP == null)
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   897
			return;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   898
		
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   899
		new Job("rollback breakpont condition") { //$NON-NLS-1$
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   900
			{ setSystem(true); }
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   901
			@Override
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   902
			protected IStatus run(IProgressMonitor monitor) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   903
				try {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   904
					if (oldValue != null)
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   905
						cdtBP.setCondition(oldValue);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   906
					else
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   907
						cdtBP.setCondition(NULL_STRING);
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   908
				} catch (CoreException e) {
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   909
					// ignore
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   910
				}
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   911
				return Status.OK_STATUS;
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   912
			}}.schedule(); 
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   913
	}
09f3d307f081 Overhauled BreakpointsMediator to support both EDC and GDB properly. See Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292468
l12wang
parents: 37
diff changeset
   914
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   915
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   916
	 * Update the breakpoint condition
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   917
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   918
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   919
	 * @param dmc
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   920
	 * @param condition
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   921
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   922
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   923
	private void changeCondition(final IBreakpointsTargetDMContext context,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   924
			final int reference, final String condition, final RequestMonitor rm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   925
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   926
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   927
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   928
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   929
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   930
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   931
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   932
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   933
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   934
		// Queue the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   935
		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   936
			new MIBreakCondition(context, reference, condition),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   937
		    new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   938
		        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   939
		        protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   940
		        	MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   941
		        	if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   942
		        		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   943
                   		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   944
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   945
		        	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   946
			        breakpoint.setCondition(condition);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   947
		            rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   948
		        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   949
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   950
		        // In case of error (new condition could not be installed for whatever reason),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   951
		        // GDB "offers" different behaviours depending on its version: it can either keep
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   952
		        // the original condition (the right thing to do) or keep the invalid condition.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   953
		        // Our sole option is to remove the condition in case of error and rely on the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   954
		        // upper layer to re-install the right condition.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   955
		        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   956
		        protected void handleError() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   957
		        	MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   958
		        	if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   959
		        		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   960
                   		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   961
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   962
		        	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   963
		        	// Remove invalid condition from the back-end breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   964
			        breakpoint.setCondition(NULL_STRING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   965
		    		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   966
		    				new MIBreakCondition(context, reference, NULL_STRING),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   967
		    			    new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   968
		    			        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   969
		    			        // The report the initial problem
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   970
		    			        protected void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   971
		    			    		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, INVALID_CONDITION, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   972
		    			            rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   973
		    			        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   974
		    				});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   975
		        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   976
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   977
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   978
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   979
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   980
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   981
	 * Update the breakpoint ignoreCount
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   982
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   983
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   984
	 * @param reference
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   985
	 * @param ignoreCount
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   986
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   987
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   988
	private void changeIgnoreCount(IBreakpointsTargetDMContext context,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   989
			final int reference, final int ignoreCount, final RequestMonitor rm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   990
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   991
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   992
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   993
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   994
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   995
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   996
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   997
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   998
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   999
		// Queue the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1000
		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1001
			new MIBreakAfter(context, reference, ignoreCount),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1002
		    new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1003
		        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1004
		        protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1005
		        	MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1006
		        	if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1007
		        		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1008
                   		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1009
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1010
		        	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1011
			        breakpoint.setIgnoreCount(ignoreCount);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1012
		            rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1013
		        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1014
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1015
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1016
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1017
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1018
	 * Enable the breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1019
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1020
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1021
	 * @param reference
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1022
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1023
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1024
	private void enableBreakpoint(IBreakpointsTargetDMContext context,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1025
			final int reference, final RequestMonitor rm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1026
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1027
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1028
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1029
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1030
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1031
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1032
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1033
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1034
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1035
		// Queue the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1036
		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1037
			new MIBreakEnable(context, new int[] { reference }),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1038
		    new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1039
		        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1040
		        protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1041
		        	MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1042
		        	if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1043
		        		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1044
                   		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1045
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1046
		        	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1047
			        breakpoint.setEnabled(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1048
		            rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1049
		        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1050
        });
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1051
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1052
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1053
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1054
	 * Disable the breakpoint
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1055
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1056
	 * @param context
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1057
	 * @param dmc
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1058
	 * @param rm
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1059
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1060
	private void disableBreakpoint(IBreakpointsTargetDMContext context,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1061
			final int reference, final RequestMonitor rm)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1062
	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1063
		// Pick the context breakpoints map
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1064
		final Map<Integer, MIBreakpointDMData> contextBreakpoints = fBreakpoints.get(context);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1065
		if (contextBreakpoints == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1066
       		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT_CONTEXT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1067
       		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1068
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1069
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1070
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1071
		// Queue the command
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1072
		fConnection.queueCommand(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1073
			new MIBreakDisable(context, new int[] { reference }),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1074
		    new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1075
		        @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1076
		        protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1077
		        	MIBreakpointDMData breakpoint = contextBreakpoints.get(reference);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1078
		        	if (breakpoint == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1079
		        		rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, REQUEST_FAILED, UNKNOWN_BREAKPOINT, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1080
                   		rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1081
                   		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1082
		        	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1083
			        breakpoint.setEnabled(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1084
		            rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1085
		        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1086
        });
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1087
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1088
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1089
}