View Javadoc
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.dummy;
26  
27  import java.util.*;
28  import sun.jvm.hotspot.debugger.*;
29  import sun.jvm.hotspot.debugger.cdbg.CDebugger;
30  import sun.jvm.hotspot.utilities.*;
31  
32  /** For testing purposes */
33  
34  public class DummyDebugger extends DebuggerBase {
35    private MachineDescription machDesc;
36  
37    public DummyDebugger(MachineDescription machDesc) {
38      this.machDesc = machDesc;
39    }
40  
41    public boolean hasProcessList() throws DebuggerException {
42      return false;
43    }
44  
45    public List getProcessList() throws DebuggerException {
46      return null;
47    }
48  
49    public void attach(int processID) throws DebuggerException {
50    }
51  
52    public void attach(String executableName, String coreFileName)
53      throws DebuggerException {
54    }
55  
56    public boolean detach() {
57      return true;
58    }
59  
60    public Address parseAddress(String addrStr) {
61      String s = addrStr.trim();
62      if (!s.startsWith("0x")) {
63        throw new NumberFormatException(addrStr);
64      }
65      long l = 0;
66      for (int i = 2; i < s.length(); ++i) {
67        int val = charToNibble(s.charAt(i));
68        l <<= 4;
69        l |= val;
70      }
71      return new DummyAddress(this, l);
72    }
73  
74    public long getAddressValue(Address addr) {
75      if (addr == null) return 0;
76      return ((DummyAddress) addr).getValue();
77    }
78  
79    public String getOS() {
80      return PlatformInfo.getOS();
81    }
82  
83    public String getCPU() {
84      return PlatformInfo.getCPU();
85    }
86  
87    public MachineDescription getMachineDescription() throws DebuggerException {
88      return machDesc;
89    }
90  
91    public boolean hasConsole() {
92      return false;
93    }
94  
95    public String consoleExecuteCommand(String cmd)
96      throws DebuggerException {
97      throw new DebuggerException("unimplemented");
98    }
99  
100   public String getConsolePrompt() throws DebuggerException {
101     throw new DebuggerException("unimplemented");
102   }
103 
104   public CDebugger getCDebugger() throws DebuggerException {
105     return null;
106   }
107 
108   public Address lookup(String objectName, String symbol) {
109     return null;
110   }
111 
112   public OopHandle lookupOop(String objectName, String symbol) {
113     return null;
114   }
115 
116   public ThreadProxy getThreadForIdentifierAddress(Address addr) {
117     return null;
118   }
119 
120   public ThreadProxy getThreadForThreadId(long id) {
121     return null;
122   }
123 
124   public ReadResult readBytesFromProcess(long address, long numBytes)
125                                throws DebuggerException {
126     throw new DebuggerException("Unimplemented");
127   }
128 
129   public void writeBytesToProcess(long a, long b, byte[] buf)
130                                throws DebuggerException {
131     throw new DebuggerException("Unimplemented");
132   }
133 
134   //----------------------------------------------------------------------
135   // Package-internal routines
136   //
137 
138   String addressToString(DummyAddress addr) {
139     StringBuffer buf = new StringBuffer();
140     buf.append("0x");
141     String val;
142     if (addr == null) {
143       val = "0";
144     } else {
145       val = Long.toHexString(addr.getValue());
146     }
147     for (int i = 0; i < ((2 * machDesc.getAddressSize()) - val.length()); i++) {
148       buf.append('0');
149     }
150     buf.append(val);
151     return buf.toString();
152   }
153 
154   //----------------------------------------------------------------------
155   // Internals only below this point
156   //
157 
158   private int charToNibble(char ascii) throws NumberFormatException {
159     if (ascii >= '0' && ascii <= '9') {
160       return ascii - '0';
161     } else if (ascii >= 'A' && ascii <= 'F') {
162       return 10 + ascii - 'A';
163     } else if (ascii >= 'a' && ascii <= 'f') {
164       return 10 + ascii - 'a';
165     }
166     throw new NumberFormatException(new Character(ascii).toString());
167   }
168 }