annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 1748:3e8fbc61cee8

6978355: renaming for 6961697 Summary: This is the renaming part of 6961697 to keep the actual changes small for review. Reviewed-by: kvn, never
author twisti
date Wed, 25 Aug 2010 05:27:54 -0700
parents c18cbe5936b8
children 3582bf76420e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
21 * questions.
0
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;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.math.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.util.regex.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.Type;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.types.Field;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.HotSpotTypeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.types.basic.BasicType;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.types.CIntegerType;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.compiler.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.interpreter.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import sun.jvm.hotspot.utilities.soql.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 import sun.jvm.hotspot.ui.classbrowser.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 import sun.jvm.hotspot.ui.tree.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 import sun.jvm.hotspot.tools.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 import sun.jvm.hotspot.tools.ObjectHistogram;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 import sun.jvm.hotspot.tools.StackTrace;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public class CommandProcessor {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public abstract static class DebuggerInterface {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public abstract HotSpotAgent getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public abstract boolean isAttached();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public abstract void attach(String pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public abstract void attach(String java, String core);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public abstract void detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public abstract void reattach();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 static class Tokens {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 final String input;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 String[] tokens;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 int length;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 String[] splitWhitespace(String cmd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 String[] t = cmd.split("\\s");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (t.length == 1 && t[0].length() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return new String[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void add(String s, ArrayList t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (s.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 t.add(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 Tokens(String cmd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 input = cmd;
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // check for quoting
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int quote = cmd.indexOf('"');
a61af66fc99e Initial load
duke
parents:
diff changeset
87 ArrayList t = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (quote != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 while (cmd.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if (quote != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int endquote = cmd.indexOf('"', quote + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (endquote == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 throw new RuntimeException("mismatched quotes: " + input);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 String before = cmd.substring(0, quote).trim();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 String quoted = cmd.substring(quote + 1, endquote);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 cmd = cmd.substring(endquote + 1).trim();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (before.length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 String[] w = splitWhitespace(before);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (int i = 0; i < w.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 add(w[i], t);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 add(quoted, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 quote = cmd.indexOf('"');
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 String[] w = splitWhitespace(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 for (int i = 0; i < w.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 add(w[i], t);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 cmd = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 String[] w = splitWhitespace(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 for (int i = 0; i < w.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 add(w[i], t);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 tokens = (String[])t.toArray(new String[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 length = tokens.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 //for (int i = 0; i < tokens.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // System.out.println("\"" + tokens[i] + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 //}
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 String nextToken() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return tokens[i++];
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 boolean hasMoreTokens() {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return i < length;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int countTokens() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return length - i;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void trim(int n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (length >= n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 length -= n;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 throw new IndexOutOfBoundsException(String.valueOf(n));
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 String join(String sep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 StringBuffer result = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 for (int w = i; w < length; w++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 result.append(tokens[w]);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (w + 1 < length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 result.append(sep);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return result.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 String at(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (i < 0 || i >= length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 throw new IndexOutOfBoundsException(String.valueOf(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return tokens[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 abstract class Command {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 Command(String n, String u, boolean ok) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 name = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 usage = u;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 okIfDisconnected = ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Command(String n, boolean ok) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 name = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 usage = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 okIfDisconnected = ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 final String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 final String usage;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 final boolean okIfDisconnected;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 abstract void doit(Tokens t);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 out.println("Usage: " + usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 void printOopValue(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (oop != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 Klass k = oop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Symbol s = k.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (s != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 out.print("Oop for " + s.asString() + " @ ");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 out.print("Oop @ ");
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 Oop.printOopAddressOn(oop, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 out.print("null");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 void printNode(SimpleTreeNode node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 int count = node.getChildCount();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 for (int i = 0; i < count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 SimpleTreeNode field = node.getChild(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if (field instanceof OopTreeNodeAdapter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 out.print(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 printOopValue(((OopTreeNodeAdapter)field).getOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
212 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 out.println(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
218 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 void quote(String s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (s.indexOf(" ") == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 out.print(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 out.print("\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 out.print(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 out.print("\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 void dumpType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 out.print("type ");
a61af66fc99e Initial load
duke
parents:
diff changeset
239 quote(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
240 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (type.getSuperclass() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 quote(type.getSuperclass().getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
243 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 out.print("null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 out.print(type.isOopType());
a61af66fc99e Initial load
duke
parents:
diff changeset
248 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (type.isCIntegerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 out.print("true ");
a61af66fc99e Initial load
duke
parents:
diff changeset
251 out.print(((CIntegerType)type).isUnsigned());
a61af66fc99e Initial load
duke
parents:
diff changeset
252 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
253 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 out.print("false false ");
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 out.print(type.getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
257 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 void dumpFields(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 Iterator i = type.getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 Field f = (Field) i.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 out.print("field ");
a61af66fc99e Initial load
duke
parents:
diff changeset
265 quote(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
266 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 out.print(f.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
268 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
269 quote(f.getType().getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
270 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 out.print(f.isStatic());
a61af66fc99e Initial load
duke
parents:
diff changeset
272 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 out.print("0 ");
a61af66fc99e Initial load
duke
parents:
diff changeset
275 out.print(f.getStaticFieldAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
276 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 out.print(f.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
278 out.print(" 0x0");
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 Address lookup(String symbol) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (symbol.indexOf("::") != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 String[] parts = symbol.split("::");
a61af66fc99e Initial load
duke
parents:
diff changeset
288 StringBuffer mangled = new StringBuffer("__1c");
a61af66fc99e Initial load
duke
parents:
diff changeset
289 for (int i = 0; i < parts.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 int len = parts[i].length();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (len >= 26) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 mangled.append((char)('a' + (len / 26)));
a61af66fc99e Initial load
duke
parents:
diff changeset
293 len = len % 26;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 mangled.append((char)('A' + len));
a61af66fc99e Initial load
duke
parents:
diff changeset
296 mangled.append(parts[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 mangled.append("_");
a61af66fc99e Initial load
duke
parents:
diff changeset
299 symbol = mangled.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return VM.getVM().getDebugger().lookup(null, symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 Address parseAddress(String addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return VM.getVM().getDebugger().parseAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 private final Command[] commandList = {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 new Command("reattach", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 int tokens = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (tokens != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 preAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 debugger.reattach();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 postAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320 },
a61af66fc99e Initial load
duke
parents:
diff changeset
321 new Command("attach", "attach pid | exec core", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 int tokens = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 if (tokens == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 preAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 debugger.attach(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
327 postAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 } else if (tokens == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 preAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 debugger.attach(t.nextToken(), t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
331 postAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 },
a61af66fc99e Initial load
duke
parents:
diff changeset
337 new Command("detach", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
341 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345 },
a61af66fc99e Initial load
duke
parents:
diff changeset
346 new Command("examine", "examine [ address/count ] | [ address,address]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 Pattern args1 = Pattern.compile("^(0x[0-9a-f]+)(/([0-9]*)([a-z]*))?$");
a61af66fc99e Initial load
duke
parents:
diff changeset
348 Pattern args2 = Pattern.compile("^(0x[0-9a-f]+),(0x[0-9a-f]+)(/[a-z]*)?$");
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 String fill(Address a, int width) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 String s = "0x0";
a61af66fc99e Initial load
duke
parents:
diff changeset
352 if (a != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 s = a.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (s.length() != width) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return s.substring(0, 2) + "000000000000000000000".substring(0, width - s.length()) + s.substring(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 return s;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 String arg = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 Matcher m1 = args1.matcher(arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 Matcher m2 = args2.matcher(arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 Address start = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 Address end = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 String format = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
371 int formatSize = (int)VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (m1.matches()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 start = VM.getVM().getDebugger().parseAddress(m1.group(1));
a61af66fc99e Initial load
duke
parents:
diff changeset
375 int count = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if (m1.group(2) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 count = Integer.parseInt(m1.group(3));
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 end = start.addOffsetTo(count * formatSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 } else if (m2.matches()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 start = VM.getVM().getDebugger().parseAddress(m2.group(1));
a61af66fc99e Initial load
duke
parents:
diff changeset
382 end = VM.getVM().getDebugger().parseAddress(m2.group(2));
a61af66fc99e Initial load
duke
parents:
diff changeset
383 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 int line = 80;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 int formatWidth = formatSize * 8 / 4 + 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 out.print(fill(start, formatWidth));
a61af66fc99e Initial load
duke
parents:
diff changeset
391 out.print(": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
392 int width = line - formatWidth - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 boolean needsPrintln = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 while (start != null && start.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 Address val = start.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 out.print(fill(val, formatWidth));
a61af66fc99e Initial load
duke
parents:
diff changeset
398 needsPrintln = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
399 width -= formatWidth;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 start = start.addOffsetTo(formatSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (width <= formatWidth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 needsPrintln = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 if (start.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 out.print(fill(start, formatWidth));
a61af66fc99e Initial load
duke
parents:
diff changeset
406 out.print(": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
407 width = line - formatWidth - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
411 width -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (needsPrintln) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419 },
a61af66fc99e Initial load
duke
parents:
diff changeset
420 new Command("findpc", "findpc address", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
426 PointerLocation loc = PointerFinder.find(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 loc.printOn(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430 },
a61af66fc99e Initial load
duke
parents:
diff changeset
431 new Command("flags", "flags [ flag ]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 int tokens = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
434 if (tokens != 0 && tokens != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 String name = tokens > 0 ? t.nextToken() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 VM.Flag[] flags = VM.getVM().getCommandLineFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (flags == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 out.println("Command Flag info not available (use 1.4.1_03 or later)!");
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 boolean printed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 for (int f = 0; f < flags.length; f++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 VM.Flag flag = flags[f];
a61af66fc99e Initial load
duke
parents:
diff changeset
446 if (name == null || flag.getName().equals(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 out.println(flag.getName() + " = " + flag.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
448 printed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (name != null && !printed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 out.println("Couldn't find flag: " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 },
a61af66fc99e Initial load
duke
parents:
diff changeset
458 new Command("help", "help [ command ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 int tokens = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 Command cmd = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (tokens == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 cmd = findCommand(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (cmd != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 cmd.usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 } else if (tokens == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 out.println("Available commands:");
a61af66fc99e Initial load
duke
parents:
diff changeset
470 Object[] keys = commands.keySet().toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
471 Arrays.sort(keys, new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 return o1.toString().compareTo(o2.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 });
a61af66fc99e Initial load
duke
parents:
diff changeset
476 for (int i = 0; i < keys.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 out.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
478 out.println(((Command)commands.get(keys[i])).usage);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 },
a61af66fc99e Initial load
duke
parents:
diff changeset
483 new Command("history", "history", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 int tokens = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (tokens != 0 && (tokens != 1 || !t.nextToken().equals("-h"))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490 boolean printIndex = tokens == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 for (int i = 0; i < history.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (printIndex) out.print(i + " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
493 out.println(history.get(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 },
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
497 new Command("revptrs", "revptrs address", false) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
498 public void doit(Tokens t) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
499 int tokens = t.countTokens();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
500 if (tokens != 1 && (tokens != 2 || !t.nextToken().equals("-c"))) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
501 usage();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
502 return;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
503 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
504 boolean chase = tokens == 2;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
505 ReversePtrs revptrs = VM.getVM().getRevPtrs();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
506 if (revptrs == null) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
507 out.println("Computing reverse pointers...");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
508 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
509 final boolean[] complete = new boolean[1];
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
510 HeapProgressThunk thunk = new HeapProgressThunk() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
511 public void heapIterationFractionUpdate(double d) {}
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
512 public synchronized void heapIterationComplete() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
513 complete[0] = true;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
514 notify();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
515 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
516 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
517 analysis.setHeapProgressThunk(thunk);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
518 analysis.run();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
519 while (!complete[0]) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
520 synchronized (thunk) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
521 try {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
522 thunk.wait();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
523 } catch (Exception e) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
524 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
525 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
526 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
527 revptrs = VM.getVM().getRevPtrs();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
528 out.println("Done.");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
529 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
530 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
531 if (VM.getVM().getUniverse().heap().isInReserved(a)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
532 OopHandle handle = a.addOffsetToAsOopHandle(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
533 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
534 ArrayList ptrs = revptrs.get(oop);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
535 if (ptrs == null) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
536 out.println("no live references to " + a);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
537 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
538 if (chase) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
539 while (ptrs.size() == 1) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
540 LivenessPathElement e = (LivenessPathElement)ptrs.get(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
541 ByteArrayOutputStream bos = new ByteArrayOutputStream();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
542 Oop.printOopValueOn(e.getObj(), new PrintStream(bos));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
543 out.println(bos.toString());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
544 ptrs = revptrs.get(e.getObj());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
545 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
546 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
547 for (int i = 0; i < ptrs.size(); i++) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
548 LivenessPathElement e = (LivenessPathElement)ptrs.get(i);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
549 ByteArrayOutputStream bos = new ByteArrayOutputStream();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
550 Oop.printOopValueOn(e.getObj(), new PrintStream(bos));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
551 out.println(bos.toString());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
552 oop = e.getObj();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
553 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
554 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
555 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
556 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
557 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
558 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
559 new Command("inspect", "inspect expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
565 SimpleTreeNode node = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
566 if (VM.getVM().getUniverse().heap().isInReserved(a)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 OopHandle handle = a.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 node = new OopTreeNodeAdapter(oop, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
570
a61af66fc99e Initial load
duke
parents:
diff changeset
571 out.println("instance of " + node.getValue() + " @ " + a +
a61af66fc99e Initial load
duke
parents:
diff changeset
572 " (size = " + oop.getObjectSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
573 } else if (VM.getVM().getCodeCache().contains(a)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
575 a = blob.headerBegin();
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577 if (node == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 if (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
581 node = new CTypeTreeNodeAdapter(a, type, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (node != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 printNode(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 },
a61af66fc99e Initial load
duke
parents:
diff changeset
590 new Command("jhisto", "jhisto", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
591 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 ObjectHistogram histo = new ObjectHistogram();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 histo.run(out, err);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595 },
a61af66fc99e Initial load
duke
parents:
diff changeset
596 new Command("jstack", "jstack [-v]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 boolean verbose = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602 StackTrace jstack = new StackTrace(verbose, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 jstack.run(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605 },
a61af66fc99e Initial load
duke
parents:
diff changeset
606 new Command("print", "print expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
610 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
612 HTMLGenerator gen = new HTMLGenerator(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
613 out.println(gen.genHTML(a));
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615 }
a61af66fc99e Initial load
duke
parents:
diff changeset
616 },
a61af66fc99e Initial load
duke
parents:
diff changeset
617 new Command("printas", "printas type expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
618 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 if (t.countTokens() != 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
620 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
621 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
622 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
623 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
624 CTypeTreeNodeAdapter node = new CTypeTreeNodeAdapter(a, type, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 out.println("pointer to " + type + " @ " + a +
a61af66fc99e Initial load
duke
parents:
diff changeset
627 " (size = " + type.getSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
628 printNode(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631 },
a61af66fc99e Initial load
duke
parents:
diff changeset
632 new Command("symbol", "symbol name", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
636 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 String symbol = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
638 Address a = lookup(symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
639 out.println(symbol + " = " + a);
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642 },
a61af66fc99e Initial load
duke
parents:
diff changeset
643 new Command("printstatics", "printstatics [ type ]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
644 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 if (t.countTokens() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
647 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 out.println("All known static fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
650 printNode(new CTypeTreeNodeAdapter(agent.getTypeDataBase().getTypes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
651 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
653 out.println("Static fields of " + type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
654 printNode(new CTypeTreeNodeAdapter(type));
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
658 },
a61af66fc99e Initial load
duke
parents:
diff changeset
659 new Command("pmap", "pmap", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
661 PMap pmap = new PMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
662 pmap.run(out, debugger.getAgent().getDebugger());
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664 },
a61af66fc99e Initial load
duke
parents:
diff changeset
665 new Command("pstack", "pstack [-v]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 boolean verbose = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
671 PStack pstack = new PStack(verbose, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
672 pstack.run(out, debugger.getAgent().getDebugger());
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674 },
a61af66fc99e Initial load
duke
parents:
diff changeset
675 new Command("quit", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
679 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
681 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
684 },
a61af66fc99e Initial load
duke
parents:
diff changeset
685 new Command("echo", "echo [ true | false ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 out.println("echo is " + doEcho);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
690 doEcho = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
691 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695 },
a61af66fc99e Initial load
duke
parents:
diff changeset
696 new Command("versioncheck", "versioncheck [ true | false ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 out.println("versioncheck is " +
a61af66fc99e Initial load
duke
parents:
diff changeset
700 (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null));
a61af66fc99e Initial load
duke
parents:
diff changeset
701 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (Boolean.valueOf(t.nextToken()).booleanValue()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", null);
a61af66fc99e Initial load
duke
parents:
diff changeset
704 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", "true");
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 },
a61af66fc99e Initial load
duke
parents:
diff changeset
712 new Command("scanoops", "scanoops start end [ type ]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 if (t.countTokens() != 2 && t.countTokens() != 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
716 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
717 long stride = VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
718 Address base = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
719 Address end = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
720 Klass klass = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
721 if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 klass = SystemDictionaryHelper.findInstanceKlass(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
724 while (base != null && base.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 long step = stride;
a61af66fc99e Initial load
duke
parents:
diff changeset
726 OopHandle handle = base.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
727 if (RobustOopDeterminator.oopLooksValid(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
728 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (klass == null || oop.getKlass().isSubtypeOf(klass))
a61af66fc99e Initial load
duke
parents:
diff changeset
731 out.println(handle.toString() + " " + oop.getKlass().getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
732 step = oop.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
733 } catch (UnknownOopException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // ok
a61af66fc99e Initial load
duke
parents:
diff changeset
735 } catch (RuntimeException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
739 base = base.addOffsetTo(step);
a61af66fc99e Initial load
duke
parents:
diff changeset
740 }
a61af66fc99e Initial load
duke
parents:
diff changeset
741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743 },
a61af66fc99e Initial load
duke
parents:
diff changeset
744 new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
748 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750 if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
752 dumpFields(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 } else if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
754 Iterator i = agent.getTypeDataBase().getTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
755 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
756 dumpFields((Type)i.next());
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 BasicType containingType = (BasicType)agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 String fieldName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 // The field's Type must already be in the database -- no exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
764 Type fieldType = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
765
a61af66fc99e Initial load
duke
parents:
diff changeset
766 boolean isStatic = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
767 long offset = Long.parseLong(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
768 Address staticAddress = parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
769 if (isStatic && staticAddress == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
770 staticAddress = lookup(containingType.getName() + "::" + fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // check to see if the field already exists
a61af66fc99e Initial load
duke
parents:
diff changeset
774 Iterator i = containingType.getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
775 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 Field f = (Field) i.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
777 if (f.getName().equals(fieldName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
778 if (f.isStatic() != isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 throw new RuntimeException("static/nonstatic mismatch: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
782 if (f.getOffset() != offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 throw new RuntimeException("bad redefinition of field offset: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
784 }
a61af66fc99e Initial load
duke
parents:
diff changeset
785 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
786 if (!f.getStaticFieldAddress().equals(staticAddress)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
787 throw new RuntimeException("bad redefinition of field location: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
790 if (f.getType() != fieldType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
791 throw new RuntimeException("bad redefinition of field type: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
793 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // Create field by type
a61af66fc99e Initial load
duke
parents:
diff changeset
798 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
799 db.createField(containingType,
a61af66fc99e Initial load
duke
parents:
diff changeset
800 fieldName, fieldType,
a61af66fc99e Initial load
duke
parents:
diff changeset
801 isStatic,
a61af66fc99e Initial load
duke
parents:
diff changeset
802 offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
803 staticAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
804
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806 }
a61af66fc99e Initial load
duke
parents:
diff changeset
807
a61af66fc99e Initial load
duke
parents:
diff changeset
808 },
a61af66fc99e Initial load
duke
parents:
diff changeset
809 new Command("tokenize", "tokenize ...", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
811 while (t.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 out.println("\"" + t.nextToken() + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815 },
a61af66fc99e Initial load
duke
parents:
diff changeset
816 new Command("type", "type [ type [ name super isOop isInteger isUnsigned size ] ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
818 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
819 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
820 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822 if (t.countTokens() == 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
823 String typeName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
824 String superclassName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
825 if (superclassName.equals("null")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
826 superclassName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
827 }
a61af66fc99e Initial load
duke
parents:
diff changeset
828 boolean isOop = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
829 boolean isInteger = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
830 boolean isUnsigned = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
831 long size = Long.parseLong(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
832
a61af66fc99e Initial load
duke
parents:
diff changeset
833 BasicType type = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
834 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 type = (BasicType)agent.getTypeDataBase().lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
836 } catch (RuntimeException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
838 if (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 if (type.isOopType() != isOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 throw new RuntimeException("oop mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842 if (type.isCIntegerType() != isInteger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
843 throw new RuntimeException("integer type mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
844 }
a61af66fc99e Initial load
duke
parents:
diff changeset
845 if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 throw new RuntimeException("unsigned mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848 if (type.getSuperclass() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
849 if (superclassName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 if (type.getSize() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
851 type.setSuperclass(agent.getTypeDataBase().lookupType(superclassName));
a61af66fc99e Initial load
duke
parents:
diff changeset
852 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
853 throw new RuntimeException("unexpected superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 if (superclassName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 throw new RuntimeException("missing superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
860 if (!type.getSuperclass().getName().equals(superclassName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 throw new RuntimeException("incorrect superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864 if (type.getSize() != size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
865 if (type.getSize() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
866 type.setSize(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
868 throw new RuntimeException("size mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
870 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 // Create type
a61af66fc99e Initial load
duke
parents:
diff changeset
874 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
875 db.createType(typeName, superclassName, isOop, isInteger, isUnsigned, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
877 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
878 dumpType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 Iterator i = agent.getTypeDataBase().getTypes();
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
881 // Make sure the types are emitted in an order than can be read back in
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
882 HashSet emitted = new HashSet();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
883 Stack pending = new Stack();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
884 while (i.hasNext()) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
885 Type n = (Type)i.next();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
886 if (emitted.contains(n.getName())) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
887 continue;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
888 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
889
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
890 while (n != null && !emitted.contains(n.getName())) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
891 pending.push(n);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
892 n = n.getSuperclass();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
893 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
894 while (!pending.empty()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
895 n = (Type)pending.pop();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
896 dumpType(n);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
897 emitted.add(n.getName());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
898 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
899 }
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 },
a61af66fc99e Initial load
duke
parents:
diff changeset
904 new Command("source", "source filename", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
905 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
907 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
908 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910 String file = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
911 BufferedReader savedInput = in;
a61af66fc99e Initial load
duke
parents:
diff changeset
912 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
a61af66fc99e Initial load
duke
parents:
diff changeset
914 in = input;
a61af66fc99e Initial load
duke
parents:
diff changeset
915 run(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
916 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
919 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
921 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
922 in = savedInput;
a61af66fc99e Initial load
duke
parents:
diff changeset
923 }
a61af66fc99e Initial load
duke
parents:
diff changeset
924
a61af66fc99e Initial load
duke
parents:
diff changeset
925 }
a61af66fc99e Initial load
duke
parents:
diff changeset
926 },
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
927 new Command("search", "search [ heap | perm | rawheap | codecache | threads ] value", false) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
928 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if (t.countTokens() != 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 usage();
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
931 return;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
932 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
933 String type = t.nextToken();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
934 final Address value = VM.getVM().getDebugger().parseAddress(t.nextToken());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
935 final long stride = VM.getVM().getAddressSize();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
936 if (type.equals("threads")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
937 Threads threads = VM.getVM().getThreads();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
938 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
939 Address base = thread.getBaseOfStackPointer();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
940 Address end = thread.getLastJavaSP();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
941 if (end == null) continue;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
942 if (end.lessThan(base)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
943 Address tmp = base;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
944 base = end;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
945 end = tmp;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
946 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
947 out.println("Searching " + base + " " + end);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
948 while (base != null && base.lessThan(end)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
949 Address val = base.getAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
950 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
951 out.println(base);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
952 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
953 base = base.addOffsetTo(stride);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
954 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
955 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
956 } else if (type.equals("rawheap")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
957 RawHeapVisitor iterator = new RawHeapVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
958 public void prologue(long used) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
959 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
960
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
961 public void visitAddress(Address addr) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
962 Address val = addr.getAddressAt(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (AddressOps.equal(val, value)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
964 out.println("found at " + addr);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
965 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
966 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
967 public void visitCompOopAddress(Address addr) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
968 Address val = addr.getCompOopAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
969 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
970 out.println("found at " + addr);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
971 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
972 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
973 public void epilogue() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
974 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
975 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
976 VM.getVM().getObjectHeap().iterateRaw(iterator);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
977 } else if (type.equals("heap") || type.equals("perm")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
978 HeapVisitor iterator = new DefaultHeapVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
979 public boolean doObj(Oop obj) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
980 int index = 0;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
981 Address start = obj.getHandle();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
982 long end = obj.getObjectSize();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
983 while (index < end) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
984 Address val = start.getAddressAt(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
985 if (AddressOps.equal(val, value)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
986 out.println("found in " + obj.getHandle());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
987 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
988 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
989 index += 4;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
990 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
991 return false;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
992 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
993 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
994 if (type.equals("heap")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
995 VM.getVM().getObjectHeap().iterate(iterator);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
996 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
997 VM.getVM().getObjectHeap().iteratePerm(iterator);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
998 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
999 } else if (type.equals("codecache")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1000 CodeCacheVisitor v = new CodeCacheVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1001 public void prologue(Address start, Address end) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1002 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1003 public void visit(CodeBlob blob) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1004 boolean printed = false;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1005 Address base = blob.getAddress();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1006 Address end = base.addOffsetTo(blob.getSize());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1007 while (base != null && base.lessThan(end)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1008 Address val = base.getAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1009 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1010 if (!printed) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1011 printed = true;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1012 blob.printOn(out);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1014 out.println("found at " + base + "\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1016 base = base.addOffsetTo(stride);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1018 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1019 public void epilogue() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1020 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1023 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1024 VM.getVM().getCodeCache().iterate(v);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 },
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1029 new Command("dumpcodecache", "dumpcodecache", false) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1030 public void doit(Tokens t) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1031 if (t.countTokens() != 0) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1032 usage();
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1033 } else {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1034 final PrintStream fout = out;
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1035 final HTMLGenerator gen = new HTMLGenerator(false);
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1036 CodeCacheVisitor v = new CodeCacheVisitor() {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1037 public void prologue(Address start, Address end) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1038 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1039 public void visit(CodeBlob blob) {
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1552
diff changeset
1040 fout.println(gen.genHTML(blob.contentBegin()));
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1041 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1042 public void epilogue() {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1043 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1044
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1045
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1046 };
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1047 VM.getVM().getCodeCache().iterate(v);
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1048 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1049 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1050 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 new Command("where", "where { -a | id }", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 String name = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 boolean all = name.equals("-a");
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 thread.printThreadIDOn(new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 if (all || bos.toString().equals(name)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1063 out.println(bos.toString() + " = " + thread.getAddress());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 HTMLGenerator gen = new HTMLGenerator(false);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1065 try {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1066 out.println(gen.genHTMLForJavaStackTrace(thread));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1067 } catch (Exception e) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1068 err.println("Error: " + e);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1069 if (verboseExceptions) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1070 e.printStackTrace(err);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1071 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1072 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 if (!all) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 if (!all) out.println("Couldn't find thread " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 },
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1080 new Command("thread", "thread { -a | id }", false) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1081 public void doit(Tokens t) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1082 if (t.countTokens() != 1) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1083 usage();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1084 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1085 String name = t.nextToken();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1086 Threads threads = VM.getVM().getThreads();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1087 boolean all = name.equals("-a");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1088 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1089 ByteArrayOutputStream bos = new ByteArrayOutputStream();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1090 thread.printThreadIDOn(new PrintStream(bos));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1091 if (all || bos.toString().equals(name)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1092 out.println(bos.toString() + " = " + thread.getAddress());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1093 if (!all) return;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1094 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1095 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1096 out.println("Couldn't find thread " + name);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1097 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1098 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1099 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1100
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 new Command("threads", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 thread.printThreadIDOn(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 out.println(" " + thread.getThreadName());
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1114
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 new Command("livenmethods", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 ArrayList nmethods = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 HTMLGenerator gen = new HTMLGenerator(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 if (vf instanceof CompiledVFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 NMethod c = ((CompiledVFrame)vf).getCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 if (!nmethods.contains(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 nmethods.add(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 out.println(gen.genHTML(c));
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 new Command("universe", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 Universe u = VM.getVM().getUniverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 out.println("Heap Parameters:");
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 u.heap().printOn(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 new Command("verbose", "verbose true | false", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 verboseExceptions = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 new Command("assert", "assert true | false", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 Assert.ASSERTS_ENABLED = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1171
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 private boolean verboseExceptions = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 private ArrayList history = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 private HashMap commands = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 private boolean doEcho = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 private Command findCommand(String key) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 return (Command)commands.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 public void printPrompt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 out.print("hsdb> ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1184
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 private DebuggerInterface debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 private HotSpotAgent agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 private JSJavaScriptEngine jsengine;
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 private BufferedReader in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 private PrintStream out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 private PrintStream err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1191
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 // called before debuggee attach
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 private void preAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 // nothing for now..
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1196
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 // called after debuggee attach
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 private void postAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 // create JavaScript engine and start it
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 jsengine = new JSJavaScriptEngine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 private ObjectReader reader = new ObjectReader();
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 private JSJavaFactory factory = new JSJavaFactoryImpl();
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 public ObjectReader getObjectReader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 return reader;
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 public JSJavaFactory getJSJavaFactory() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 return factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 protected void quit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 protected BufferedReader getInputReader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 return in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 protected PrintStream getOutputStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 return out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 protected PrintStream getErrorStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 jsengine.defineFunction(this,
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 this.getClass().getMethod("registerCommand",
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 new Class[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 String.class, String.class, String.class
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 } catch (NoSuchMethodException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 // should not happen, see below...!!
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 exp.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 jsengine.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1235
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 public void registerCommand(String cmd, String usage, final String func) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 commands.put(cmd, new Command(cmd, usage, false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 final int len = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 Object[] args = new Object[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 args[i] = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 jsengine.call(func, args);
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1248
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 public void setOutput(PrintStream o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 out = o;
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1252
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 public void setErr(PrintStream e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 err = e;
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1256
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 public CommandProcessor(DebuggerInterface debugger, BufferedReader in, PrintStream out, PrintStream err) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 this.debugger = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 this.agent = debugger.getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 this.in = in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 this.out = out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 this.err = err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 for (int i = 0; i < commandList.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 Command c = commandList[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 commands.put(c.name, c);
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 if (debugger.isAttached()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 postAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1271
a61af66fc99e Initial load
duke
parents:
diff changeset
1272
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 public void run(boolean prompt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 // Process interactive commands.
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 if (prompt) printPrompt();
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 String ln = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 ln = in.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 if (ln == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 if (prompt) err.println("Input stream closed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1286
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 executeCommand(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1290
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1291 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1292
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 public void executeCommand(String ln) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 if (ln.indexOf('!') != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 int size = history.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 if (size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 ln = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 err.println("History is empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 StringBuffer result = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 Matcher m = historyPattern.matcher(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 int start = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 while (m.find()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 if (m.start() > start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 result.append(ln.substring(start, m.start() - start));
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 start = m.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
1308
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 String cmd = m.group();
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 if (cmd.equals("!!")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 result.append((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 } else if (cmd.equals("!!-")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 item.trim(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 result.append(item.join(" "));
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 } else if (cmd.equals("!*")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 item.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 result.append(item.join(" "));
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 } else if (cmd.equals("!$")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 result.append(item.at(item.countTokens() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 String tail = cmd.substring(1);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1325 switch (tail.charAt(0)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1326 case '0':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1327 case '1':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1328 case '2':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1329 case '3':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1330 case '4':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1331 case '5':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1332 case '6':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1333 case '7':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1334 case '8':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1335 case '9':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1336 case '-': {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1337 int index = Integer.parseInt(tail);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1338 if (index < 0) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1339 index = history.size() + index;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1340 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1341 if (index > size) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1342 err.println("No such history item");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1343 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1344 result.append((String)history.get(index));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1345 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1346 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1348 default: {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1349 for (int i = history.size() - 1; i >= 0; i--) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1350 String s = (String)history.get(i);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1351 if (s.startsWith(tail)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1352 result.append(s);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1353 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1354 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1355 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 if (result.length() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 err.println("malformed history reference");
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 ln = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 if (start < ln.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 result.append(ln.substring(start));
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 ln = result.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 if (!doEcho) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 out.println(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1373
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 if (doEcho) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 out.println("+ " + ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1377
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 PrintStream redirect = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 Tokens t = new Tokens(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 if (t.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 boolean error = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 history.add(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 int len = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 if (len > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 String r = t.at(len - 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 if (r.equals(">") || r.equals(">>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 boolean append = r.length() == 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 String file = t.at(len - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 redirect = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 t.trim(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 error = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 if (!error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 PrintStream savedout = out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 if (redirect != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 out = redirect;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 executeCommand(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 err.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 e.printStackTrace(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 if (redirect != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 out = savedout;
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 redirect.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1422
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 void executeCommand(Tokens args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 String cmd = args.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1425
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 Command doit = findCommand(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
1427
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 * Check for an unknown command
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 if (doit == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 out.println("Unrecognized command. Try help...");
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 } else if (!debugger.isAttached() && !doit.okIfDisconnected) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 out.println("Command not valid until the attached to a VM");
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 doit.doit(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 }