hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/win32/AddressDataSource.java
changeset 10864 17307b96ae38
parent 10779 5037da29fa26
parent 10762 cc1f5ce8e504
child 10865 7f8dd1713604
equal deleted inserted replaced
10779:5037da29fa26 10864:17307b96ae38
     1 /*
       
     2  * Copyright (c) 2000, 2004, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 package sun.jvm.hotspot.debugger.win32;
       
    26 
       
    27 import java.io.*;
       
    28 import sun.jvm.hotspot.debugger.*;
       
    29 import sun.jvm.hotspot.debugger.win32.coff.*;
       
    30 
       
    31 class AddressDataSource implements DataSource {
       
    32   AddressDataSource(Address addr) {
       
    33     this.addr = addr;
       
    34     offset = 0;
       
    35   }
       
    36 
       
    37   public byte readByte() throws IOException {
       
    38     try {
       
    39       byte res = (byte) addr.getCIntegerAt(offset, 1, false);
       
    40       ++offset;
       
    41       return res;
       
    42     } catch (UnmappedAddressException e) {
       
    43       throw (IOException) new IOException("Unmapped address at 0x" + Long.toHexString(e.getAddress())).initCause(e);
       
    44     } catch (DebuggerException e) {
       
    45       throw (IOException) new IOException(e.toString()).initCause(e);
       
    46     }
       
    47   }
       
    48 
       
    49   public short readShort() throws IOException {
       
    50     // NOTE: byte swapping is taken care of at the COFFFileImpl 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 COFFFileImpl 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 COFFFileImpl 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 }