annotate agent/src/share/classes/sun/jvm/hotspot/debugger/DebuggerUtilities.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 /** Common routines for data conversion */
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 public class DebuggerUtilities {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 protected long addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 protected boolean isBigEndian;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public DebuggerUtilities(long addressSize, boolean isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 this.addressSize = addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 this.isBigEndian = isBigEndian;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public String addressValueToString(long address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
40 buf.append("0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 String val;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Make negative addresses have the correct size
a61af66fc99e Initial load
duke
parents:
diff changeset
43 if (addressSize == 8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 val = Long.toHexString(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 val = Integer.toHexString((int) address);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 for (int i = 0; i < ((2 * addressSize) - val.length()); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 buf.append('0');
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51 buf.append(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public void checkAlignment(long address, long alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (address % alignment != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 throw new UnalignedAddressException("Trying to read at address: " +
a61af66fc99e Initial load
duke
parents:
diff changeset
58 addressValueToString(address) +
a61af66fc99e Initial load
duke
parents:
diff changeset
59 " with alignment: " + alignment,
a61af66fc99e Initial load
duke
parents:
diff changeset
60 address);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public long scanAddress(String addrStr) throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 String s = addrStr.trim();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (!s.startsWith("0x")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 throw new NumberFormatException(addrStr);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 long l = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 for (int i = 2; i < s.length(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 int val = charToNibble(s.charAt(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
72 l <<= 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 l |= val;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return l;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public int charToNibble(char ascii) throws NumberFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (ascii >= '0' && ascii <= '9') {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return ascii - '0';
a61af66fc99e Initial load
duke
parents:
diff changeset
81 } else if (ascii >= 'A' && ascii <= 'F') {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return 10 + ascii - 'A';
a61af66fc99e Initial load
duke
parents:
diff changeset
83 } else if (ascii >= 'a' && ascii <= 'f') {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return 10 + ascii - 'a';
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 throw new NumberFormatException(new Character(ascii).toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public boolean dataToJBoolean(byte[] data, long jbooleanSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 checkDataContents(data, jbooleanSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return (data[0] != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public byte dataToJByte(byte[] data, long jbyteSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 checkDataContents(data, jbyteSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return data[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public char dataToJChar(byte[] data, long jcharSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 checkDataContents(data, jcharSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return (char) (((data[0] & 0xFF) << 8) | (data[1] & 0xFF));
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public double dataToJDouble(byte[] data, long jdoubleSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 long longBits = dataToJLong(data, jdoubleSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return Double.longBitsToDouble(longBits);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public float dataToJFloat(byte[] data, long jfloatSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int intBits = dataToJInt(data, jfloatSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return Float.intBitsToFloat(intBits);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 public int dataToJInt(byte[] data, long jintSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 checkDataContents(data, jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return (((data[0] & 0xFF) << 24) | ((data[1] & 0xFF) << 16) | ((data[2] & 0xFF) << 8) | (data[3] & 0xFF));
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public long dataToJLong(byte[] data, long jlongSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 checkDataContents(data, jlongSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return rawDataToJLong(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public short dataToJShort(byte[] data, long jshortSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 checkDataContents(data, jshortSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return (short) (((data[0] & 0xFF) << 8) | (data[1] & 0xFF));
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public long dataToCInteger(byte[] data, boolean isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 checkDataContents(data, data.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // By default we'll be zero-extending.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Therefore we need to check to see whether isUnsigned is false and
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // also the high bit of the data is set.
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if ((data.length < 8) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
164 (isUnsigned == false) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
165 ((data[0] & 0x80) != 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Must sign-extend and right-align the data
a61af66fc99e Initial load
duke
parents:
diff changeset
167 byte[] newData = new byte[8];
a61af66fc99e Initial load
duke
parents:
diff changeset
168 for (int i = 0; i < 8; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if ((7 - i) < data.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 newData[i] = data[i + data.length - 8];
a61af66fc99e Initial load
duke
parents:
diff changeset
171 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 newData[i] = (byte) 0xFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 data = newData;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Now just do the usual loop
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return rawDataToJLong(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public long dataToAddressValue(byte[] data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 checkDataContents(data, addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 byteSwap(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return rawDataToJLong(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 public byte[] jbooleanToData(boolean value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 byte[] res = new byte[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
194 res[0] = (byte) (value ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public byte[] jbyteToData(byte value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 byte[] res = new byte[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
200 res[0] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 public byte[] jcharToData(char value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 byte[] res = new byte[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
206 res[0] = (byte) ((value >> 8) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 res[1] = (byte) value;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 byteSwap(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public byte[] jdoubleToData(double value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return jlongToData(Double.doubleToLongBits(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 public byte[] jfloatToData(float value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return jintToData(Float.floatToIntBits(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 public byte[] jintToData(int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 byte[] res = new byte[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
224 for (int i = 0; i < 4; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 res[3 - i] = (byte) (value & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 value >>>= 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 byteSwap(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 public byte[] jlongToData(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 byte[] res = new byte[8];
a61af66fc99e Initial load
duke
parents:
diff changeset
236 for (int i = 0; i < 8; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 res[7 - i] = (byte) (value & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 value >>>= 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 byteSwap(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 public byte[] jshortToData(short value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 byte[] res = new byte[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
248 res[0] = (byte) ((value >> 8) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 res[1] = (byte) value;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 byteSwap(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public byte[] cIntegerToData(long longNumBytes, long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int numBytes = (int) longNumBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 byte[] res = new byte[numBytes];
a61af66fc99e Initial load
duke
parents:
diff changeset
259 for (int i = 0; i < numBytes; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 res[numBytes - i - 1] = (byte) (value & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 value >>>= 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (!isBigEndian) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 byteSwap(res);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
271 //
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 private void checkDataContents(byte[] data, long len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (data.length != (int) len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 throw new InternalError("Bug in Win32Debugger");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 private void byteSwap(byte[] data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 for (int i = 0; i < (data.length / 2); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 int altIndex = data.length - i - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 byte t = data[altIndex];
a61af66fc99e Initial load
duke
parents:
diff changeset
283 data[altIndex] = data[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
284 data[i] = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 private long rawDataToJLong(byte[] data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 long addr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 for (int i = 0; i < data.length; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 addr <<= 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 addr |= data[i] & 0xFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }