Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6f2e064feb0460cb9bf887816ab9adf7551c044a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************************
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi.model;

import java.math.BigInteger;

import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDICondition;
import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint;
import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint2;
import org.eclipse.cdt.debug.mi.core.output.MIBreakpoint;

/**
 */
public class Watchpoint extends Breakpoint implements ICDIWatchpoint2 {

	int watchType;
	String expression;
	String memorySpace;
	BigInteger range;
	String derivedExpression;

	public Watchpoint(Target target, String expression, int type,
			int watchType, ICDICondition condition, boolean enabled) {
		this(target, expression, "", BigInteger.ZERO, type, watchType, condition, enabled); //$NON-NLS-1$
	}

	public Watchpoint(Target target, String expression, String memorySpace,
			BigInteger range, int type, int watchType, ICDICondition cond,
			boolean enabled) {
		super(target, type, cond, enabled);
		this.watchType = watchType;
		this.expression = expression;
		this.memorySpace = memorySpace;
		this.range = range;
		
		// If the range and/or memory space are specified, cast the expression, e.g.,
		// (@data char[4])(*0x402000)
		derivedExpression = ""; //$NON-NLS-1$
		boolean doSpecifyMemorySpace = memorySpace.length() > 0;
		boolean doSpecifyRange = range.compareTo(BigInteger.ZERO) > 0;
		boolean doSpecify = doSpecifyMemorySpace || doSpecifyRange;
		if ( doSpecify ) {
			derivedExpression += "("; //$NON-NLS-1$
			if ( doSpecifyMemorySpace ) {
				derivedExpression += "@" + memorySpace; //$NON-NLS-1$
				if ( doSpecifyRange ) {
					derivedExpression += " "; //$NON-NLS-1$
				}
			}
			if ( doSpecifyRange ) {
				derivedExpression += "char[" + range.toString() + "]";  //$NON-NLS-1$	//$NON-NLS-2$
			}
			derivedExpression += ")("; //$NON-NLS-1$
		}
		
		try {
			// Check if this an address watchpoint, and add a '*'
			Integer.decode(expression);
			derivedExpression += '*';
		} catch (NumberFormatException e) {
		}
		derivedExpression += expression;
		if ( doSpecify ) {
			derivedExpression += ")"; //$NON-NLS-1$
		}
	}

	/**
	 * @see org.eclipse.cdt.debug.core.cdi.ICDIWatchpoint#getWatchExpression()
	 */
	@Override
	public String getWatchExpression() throws CDIException {
		if (expression == null) {
			MIBreakpoint[] miPoints = getMIBreakpoints();
			if (miPoints != null && miPoints.length > 0) {
				return miPoints[0].getWhat();
			}
		}
		return expression;
	}

	/**
	 * @see org.eclipse.cdt.debug.core.cdi.ICDIWatchpoint#isReadType()
	 */
	@Override
	public boolean isReadType() {
		return ((watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ);
//		MIBreakpoint miPoint = getMIBreakpoint();
//		if (miPoint != null)
//			return getMIBreakpoint().isReadWatchpoint() || getMIBreakpoint().isAccessWatchpoint();
//		return ((watchType & ICDIWatchpoint.READ) == ICDIWatchpoint.READ);
	}

	/**
	 * @see org.eclipse.cdt.debug.core.cdi.ICDIWatchpoint#isWriteType()
	 */
	@Override
	public boolean isWriteType() {
		return ((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE);
//		MIBreakpoint miPoint = getMIBreakpoint();
//		if (miPoint != null)
//			return getMIBreakpoint().isAccessWatchpoint() || getMIBreakpoint().isWriteWatchpoint();
//		return ((watchType & ICDIWatchpoint.WRITE) == ICDIWatchpoint.WRITE);
	}

	@Override
	public String getMemorySpace() throws CDIException {
		return memorySpace;
	}

	@Override
	public BigInteger getRange() throws CDIException {
		return range;
	}

	public String getDerivedExpression() {
		return derivedExpression;
	}
}

Back to the top