Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7622e8fc94777f15fe2462bf981bbe0c93d14044 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*******************************************************************************
 * Copyright (c) 2004, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.core.model;


/**
 * A byte of memory in a memory block. Each byte of memory has a value and
 * attributes indicating if the byte is read-only, valid, or if its value has
 * changed.
 * <p>
 * Clients may instantiate this class. Clients may subclass this class to
 * add other attributes to a memory byte, as required.
 * </p>
 * @since 3.1
 * @see org.eclipse.debug.core.model.IMemoryBlockExtension
 */
public class MemoryByte {

    /**
     * Bit mask used to indicate a byte is writable.
     */
	public static final byte	WRITABLE	= 0x01;

	/**
	 * Bit mask used to indicate a byte is readable.
	 * A memory byte is readable when its value and attributes are retrievable.
	 * Otherwise, a byte is considered non-readable.
	 */
	public static final byte	READABLE		= 0x02;

	/**
	 * Bit mask used to indicate a byte has changed since the last
	 * suspend event.
	 *
	 * @see org.eclipse.debug.core.DebugEvent#SUSPEND
	 */
	public static final byte	CHANGED		= 0x04;

	/**
	 * Bit mask used to indicate a memory byte has history to
	 * determine if its value has changed. When a memory byte's
	 * history is unknown, the change state has no meaning.
	 */
	public static final byte 	HISTORY_KNOWN		= 0x08;

	/**
	 * Bit mask used to indicate a this byte of memory
	 * is big endian.  If this byte of memory is little endian,
	 * turn this bit mask to off.
	 */
	public static final byte	BIG_ENDIAN	= 0x10;

	/**
	 * Bit mask used to indicate that the endianess of this byte
	 * of memory is known.  When a memory byte's endianess is
	 * unknown, the endianess of this byte has no meaning.
	 */
	public static final byte	ENDIANESS_KNOWN = 0x20;

	/**
	 * Value of this byte.
	 */
	protected byte value;

	/**
	 * Attribute flags.
	 * <p>
	 * To specify READABLE:  flags |= MemoryByte.READABLE;
	 * To specify WRITABLE:  flags |= MemoryByte.WRITABLE;
	 * </p>
	 */
	protected byte flags;

	/**
	 * Constructs a readable, writable memory byte without a change history,
	 * and a value of 0.  The byte's endianess is known and is little endian
	 * by default.
	 */
	public MemoryByte() {
	    this((byte)0, (byte)(WRITABLE | READABLE | ENDIANESS_KNOWN));
	}

	/**
	 * Constructs a readable, writable memory byte without a change history,
	 * with the given value.  The byte's endianess is known and is little endian
	 * by default.
	 *
	 * @param byteValue value of this memory byte
	 *
	 */
	public MemoryByte(byte byteValue) {
	    this(byteValue, (byte)(WRITABLE | READABLE | ENDIANESS_KNOWN));
	}

	/**
	 * Constructs a memory byte with the given value and attributes.
	 *
	 * @param byteValue value of this memory byte
	 * @param byteFlags attributes of the byte specified as a bit mask
	 */
	public MemoryByte(byte byteValue, byte byteFlags) {
		value = byteValue;
		flags = byteFlags;
	}

	/**
	 * Returns this memory byte's attribute as a bit mask.
	 *
	 * @return this memory byte's attribute as a bit mask
	 */
	public byte getFlags() {
		return flags;
	}
	/**
	 * Sets this memory byte's attributes based on the given bit mask.
	 *
	 * @param flags bit mask of attributes
	 */
	public void setFlags(byte flags) {
		this.flags = flags;
	}

	/**
	 * Returns the value of this memory byte.
	 *
	 * @return the value of this memory byte
	 */
	public byte getValue() {
		return value;
	}

	/**
	 * Sets the value of this memory byte.
	 *
	 * @param value the new value of this memory byte
	 */
	public void setValue(byte value) {
		this.value = value;
	}

	/**
	 * Sets whether this memory byte is readable. A memory byte
	 * is considered readable when its value and attributes are
	 * retrievable.
	 *
	 * @param readable whether this memory byte is readable
	 */
	public void setReadable(boolean readable) {
		flags |= MemoryByte.READABLE;
		if (!readable)
			flags ^= MemoryByte.READABLE;
	}

	/**
	 * Returns whether this memory byte is readable. A memory byte
	 * is considered readable when its value and attributes are
	 * retrievable.
	 *
	 * @return whether this memory byte is readable
	 */
	public boolean isReadable() {
		return ((flags & MemoryByte.READABLE) == MemoryByte.READABLE);
	}

	/**
	 * Sets whether this memory byte is writable.
	 *
	 * @param writable whether this memory byte is writable.
	 */
	public void setWritable(boolean writable) {
		flags |= MemoryByte.WRITABLE;
		if (!writable)
			flags ^= MemoryByte.WRITABLE;
	}

	/**
	 * Returns whether this memory byte is writable.
	 *
	 * @return whether this memory byte is writable
	 */
	public boolean isWritable() {
		return ((flags & MemoryByte.WRITABLE) == MemoryByte.WRITABLE);
	}

	/**
	 * Sets whether this memory byte has changed.
	 *
	 * @param changed whether this memory byte has changed
	 */
	public void setChanged(boolean changed) {
		flags |= MemoryByte.CHANGED;
		if (!changed)
			flags ^= MemoryByte.CHANGED;
	}

	/**
	 * Returns whether this memory byte has changed.
	 *
	 * @return whether this memory byte has changed
	 */
	public boolean isChanged() {
		return ((flags & MemoryByte.CHANGED) == MemoryByte.CHANGED);
	}

	/**
	 * Sets whether the history of this byte is known. When history
	 * is unknown, the change state of a memory byte has no meaning.
	 *
	 * @param known whether the change state of this byte is known
	 */
	public void setHistoryKnown(boolean known) {
		flags |= MemoryByte.HISTORY_KNOWN;
		if (!known)
			flags ^= MemoryByte.HISTORY_KNOWN;
	}

	/**
	 * Returns whether the history of this byte is known. When history
	 * is unknown, the change state of a memory byte has no meaning.
	 *
	 * @return whether the change state of this byte is known
	 */
	public boolean isHistoryKnown() {
		return ((flags & MemoryByte.HISTORY_KNOWN) == MemoryByte.HISTORY_KNOWN);
	}

	/**
	 * Sets whether this byte of memory is big endian.
	 *
	 * @param isBigEndian whether the byte of memory is big endian.
	 */
	public void setBigEndian(boolean isBigEndian)
	{
		flags |= MemoryByte.BIG_ENDIAN;
		if (!isBigEndian)
			flags ^= MemoryByte.BIG_ENDIAN;
	}

	/**
	 * Returns whether this byte of memory is big endian.
	 *
	 * @return whether the byte of memory is big endian.
	 */
	public boolean isBigEndian()
	{
		return ((flags & MemoryByte.BIG_ENDIAN) == MemoryByte.BIG_ENDIAN);
	}

	/**
	 * Sets whether the endianess of this byte of memory is known.
	 * If the endianess is unknown, the endianess of this byte
	 * has no meaning.
	 *
	 * @param isEndianessKnown whether the endianess of this byte is known.
	 */
	public void setEndianessKnown(boolean isEndianessKnown)
	{
		flags |= MemoryByte.ENDIANESS_KNOWN;
		if (!isEndianessKnown)
			flags ^= MemoryByte.ENDIANESS_KNOWN;
	}

	/**
	 * Returns whether the endianess of this byte of memory is known.
	 * If the endianess is unknown, the endianess of this byte
	 * has no meaning.
	 *
	 * @return whether the endianess of this byte of memory is known.
	 */
	public boolean isEndianessKnown()
	{
		return ((flags & MemoryByte.ENDIANESS_KNOWN) == MemoryByte.ENDIANESS_KNOWN);
	}

}

Back to the top