0
|
1 /*
|
|
2 * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24 package sun.jvm.hotspot.debugger.posix;
|
|
25
|
|
26 import java.io.*;
|
|
27 import sun.jvm.hotspot.debugger.*;
|
|
28 import sun.jvm.hotspot.debugger.posix.elf.*;
|
|
29
|
|
30 class AddressDataSource implements DataSource {
|
|
31 AddressDataSource(Address addr) {
|
|
32 this.addr = addr;
|
|
33 offset = 0;
|
|
34 }
|
|
35
|
|
36 public byte readByte() throws IOException {
|
|
37 try {
|
|
38 byte res = (byte) addr.getCIntegerAt(offset, 1, false);
|
|
39 ++offset;
|
|
40 return res;
|
|
41 } catch (UnmappedAddressException e) {
|
|
42 throw (IOException) new IOException("Unmapped address at 0x"
|
|
43 + Long.toHexString(e.getAddress())).initCause(e);
|
|
44 } catch (DebuggerException e) {
|
|
45 throw (IOException) new IOException().initCause(e);
|
|
46 }
|
|
47 }
|
|
48
|
|
49 public short readShort() throws IOException {
|
|
50 // NOTE: byte swapping is taken care of at the ELFFileImpl level
|
|
51 int b1 = readByte() & 0xFF;
|
|
52 int b2 = readByte() & 0xFF;
|
|
53 return (short) ((b1 << 8) | b2);
|
|
54 }
|
|
55
|
|
56 public int readInt() throws IOException {
|
|
57 // NOTE: byte swapping is taken care of at the ELFFileImpl level
|
|
58 int b1 = ((int) readByte()) & 0xFF;
|
|
59 int b2 = ((int) readByte()) & 0xFF;
|
|
60 int b3 = ((int) readByte()) & 0xFF;
|
|
61 int b4 = ((int) readByte()) & 0xFF;
|
|
62 return ((b1 << 24) | (b2 << 16) | (b3 << 8) | b4);
|
|
63 }
|
|
64
|
|
65 public long readLong() throws IOException {
|
|
66 // NOTE: byte swapping is taken care of at the ELFFileImpl level
|
|
67 long b1 = ((long) readByte()) & 0xFFL;
|
|
68 long b2 = ((long) readByte()) & 0xFFL;
|
|
69 long b3 = ((long) readByte()) & 0xFFL;
|
|
70 long b4 = ((long) readByte()) & 0xFFL;
|
|
71 long b5 = ((long) readByte()) & 0xFFL;
|
|
72 long b6 = ((long) readByte()) & 0xFFL;
|
|
73 long b7 = ((long) readByte()) & 0xFFL;
|
|
74 long b8 = ((long) readByte()) & 0xFFL;
|
|
75 return (((((b1 << 24) | (b2 << 16) | (b3 << 8) | b4)) << 32) |
|
|
76 ((((b5 << 24) | (b6 << 16) | (b7 << 8) | b8))));
|
|
77 }
|
|
78
|
|
79 public int read(byte[] b) throws IOException {
|
|
80 for (int i = 0; i < b.length; i++) {
|
|
81 b[i] = readByte();
|
|
82 }
|
|
83 return b.length;
|
|
84 }
|
|
85
|
|
86 public void seek(long pos) throws IOException {
|
|
87 offset = pos;
|
|
88 }
|
|
89
|
|
90 public long getFilePointer() throws IOException {
|
|
91 return offset;
|
|
92 }
|
|
93
|
|
94 public void close() throws IOException {
|
|
95 }
|
|
96
|
|
97 private Address addr;
|
|
98 private long offset;
|
|
99 }
|