2
|
1 |
/*
|
715
|
2 |
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.example.debug.tty;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.connect.Connector;
|
|
30 |
import com.sun.jdi.request.*;
|
|
31 |
import com.sun.tools.example.debug.expr.ExpressionParser;
|
|
32 |
import com.sun.tools.example.debug.expr.ParseException;
|
|
33 |
|
|
34 |
import java.text.*;
|
|
35 |
import java.util.*;
|
|
36 |
import java.io.*;
|
|
37 |
|
|
38 |
class Commands {
|
|
39 |
|
|
40 |
abstract class AsyncExecution {
|
|
41 |
abstract void action();
|
|
42 |
|
|
43 |
AsyncExecution() {
|
|
44 |
execute();
|
|
45 |
}
|
|
46 |
|
|
47 |
void execute() {
|
|
48 |
/*
|
|
49 |
* Save current thread and stack frame. (BugId 4296031)
|
|
50 |
*/
|
|
51 |
final ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
52 |
final int stackFrame = threadInfo == null? 0 : threadInfo.getCurrentFrameIndex();
|
|
53 |
Thread thread = new Thread("asynchronous jdb command") {
|
|
54 |
public void run() {
|
|
55 |
try {
|
|
56 |
action();
|
|
57 |
} catch (UnsupportedOperationException uoe) {
|
|
58 |
//(BugId 4453329)
|
|
59 |
MessageOutput.println("Operation is not supported on the target VM");
|
|
60 |
} catch (Exception e) {
|
|
61 |
MessageOutput.println("Internal exception during operation:",
|
|
62 |
e.getMessage());
|
|
63 |
} finally {
|
|
64 |
/*
|
|
65 |
* This was an asynchronous command. Events may have been
|
|
66 |
* processed while it was running. Restore the thread and
|
|
67 |
* stack frame the user was looking at. (BugId 4296031)
|
|
68 |
*/
|
|
69 |
if (threadInfo != null) {
|
|
70 |
ThreadInfo.setCurrentThreadInfo(threadInfo);
|
|
71 |
try {
|
|
72 |
threadInfo.setCurrentFrameIndex(stackFrame);
|
|
73 |
} catch (IncompatibleThreadStateException e) {
|
|
74 |
MessageOutput.println("Current thread isnt suspended.");
|
|
75 |
} catch (ArrayIndexOutOfBoundsException e) {
|
|
76 |
MessageOutput.println("Requested stack frame is no longer active:",
|
|
77 |
new Object []{new Integer(stackFrame)});
|
|
78 |
}
|
|
79 |
}
|
|
80 |
MessageOutput.printPrompt();
|
|
81 |
}
|
|
82 |
}
|
|
83 |
};
|
|
84 |
thread.start();
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
Commands() {
|
|
89 |
}
|
|
90 |
|
|
91 |
private Value evaluate(String expr) {
|
|
92 |
Value result = null;
|
|
93 |
ExpressionParser.GetFrame frameGetter = null;
|
|
94 |
try {
|
|
95 |
final ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
96 |
if ((threadInfo != null) && (threadInfo.getCurrentFrame() != null)) {
|
|
97 |
frameGetter = new ExpressionParser.GetFrame() {
|
|
98 |
public StackFrame get() throws IncompatibleThreadStateException {
|
|
99 |
return threadInfo.getCurrentFrame();
|
|
100 |
}
|
|
101 |
};
|
|
102 |
}
|
|
103 |
result = ExpressionParser.evaluate(expr, Env.vm(), frameGetter);
|
|
104 |
} catch (InvocationException ie) {
|
|
105 |
MessageOutput.println("Exception in expression:",
|
|
106 |
ie.exception().referenceType().name());
|
|
107 |
} catch (Exception ex) {
|
|
108 |
String exMessage = ex.getMessage();
|
|
109 |
if (exMessage == null) {
|
|
110 |
MessageOutput.printException(exMessage, ex);
|
|
111 |
} else {
|
|
112 |
String s;
|
|
113 |
try {
|
|
114 |
s = MessageOutput.format(exMessage);
|
|
115 |
} catch (MissingResourceException mex) {
|
|
116 |
s = ex.toString();
|
|
117 |
}
|
|
118 |
MessageOutput.printDirectln(s);// Special case: use printDirectln()
|
|
119 |
}
|
|
120 |
}
|
|
121 |
return result;
|
|
122 |
}
|
|
123 |
|
|
124 |
private String getStringValue() {
|
|
125 |
Value val = null;
|
|
126 |
String valStr = null;
|
|
127 |
try {
|
|
128 |
val = ExpressionParser.getMassagedValue();
|
|
129 |
valStr = val.toString();
|
|
130 |
} catch (ParseException e) {
|
|
131 |
String msg = e.getMessage();
|
|
132 |
if (msg == null) {
|
|
133 |
MessageOutput.printException(msg, e);
|
|
134 |
} else {
|
|
135 |
String s;
|
|
136 |
try {
|
|
137 |
s = MessageOutput.format(msg);
|
|
138 |
} catch (MissingResourceException mex) {
|
|
139 |
s = e.toString();
|
|
140 |
}
|
|
141 |
MessageOutput.printDirectln(s);
|
|
142 |
}
|
|
143 |
}
|
|
144 |
return valStr;
|
|
145 |
}
|
|
146 |
|
|
147 |
private ThreadInfo doGetThread(String idToken) {
|
|
148 |
ThreadInfo threadInfo = ThreadInfo.getThreadInfo(idToken);
|
|
149 |
if (threadInfo == null) {
|
|
150 |
MessageOutput.println("is not a valid thread id", idToken);
|
|
151 |
}
|
|
152 |
return threadInfo;
|
|
153 |
}
|
|
154 |
|
|
155 |
String typedName(Method method) {
|
|
156 |
StringBuffer buf = new StringBuffer();
|
|
157 |
buf.append(method.name());
|
|
158 |
buf.append("(");
|
|
159 |
|
51
|
160 |
List<String> args = method.argumentTypeNames();
|
2
|
161 |
int lastParam = args.size() - 1;
|
|
162 |
// output param types except for the last
|
|
163 |
for (int ii = 0; ii < lastParam; ii++) {
|
51
|
164 |
buf.append(args.get(ii));
|
2
|
165 |
buf.append(", ");
|
|
166 |
}
|
|
167 |
if (lastParam >= 0) {
|
|
168 |
// output the last param
|
51
|
169 |
String lastStr = args.get(lastParam);
|
2
|
170 |
if (method.isVarArgs()) {
|
|
171 |
// lastParam is an array. Replace the [] with ...
|
|
172 |
buf.append(lastStr.substring(0, lastStr.length() - 2));
|
|
173 |
buf.append("...");
|
|
174 |
} else {
|
|
175 |
buf.append(lastStr);
|
|
176 |
}
|
|
177 |
}
|
|
178 |
buf.append(")");
|
|
179 |
return buf.toString();
|
|
180 |
}
|
|
181 |
|
|
182 |
void commandConnectors(VirtualMachineManager vmm) {
|
51
|
183 |
Collection<Connector> ccs = vmm.allConnectors();
|
|
184 |
if (ccs.isEmpty()) {
|
2
|
185 |
MessageOutput.println("Connectors available");
|
|
186 |
}
|
51
|
187 |
for (Connector cc : ccs) {
|
2
|
188 |
String transportName =
|
|
189 |
cc.transport() == null ? "null" : cc.transport().name();
|
|
190 |
MessageOutput.println();
|
|
191 |
MessageOutput.println("Connector and Transport name",
|
|
192 |
new Object [] {cc.name(), transportName});
|
|
193 |
MessageOutput.println("Connector description", cc.description());
|
|
194 |
|
51
|
195 |
for (Connector.Argument aa : cc.defaultArguments().values()) {
|
2
|
196 |
MessageOutput.println();
|
|
197 |
|
|
198 |
boolean requiredArgument = aa.mustSpecify();
|
|
199 |
if (aa.value() == null || aa.value() == "") {
|
|
200 |
//no current value and no default.
|
|
201 |
MessageOutput.println(requiredArgument ?
|
|
202 |
"Connector required argument nodefault" :
|
|
203 |
"Connector argument nodefault", aa.name());
|
|
204 |
} else {
|
|
205 |
MessageOutput.println(requiredArgument ?
|
|
206 |
"Connector required argument default" :
|
|
207 |
"Connector argument default",
|
|
208 |
new Object [] {aa.name(), aa.value()});
|
|
209 |
}
|
|
210 |
MessageOutput.println("Connector description", aa.description());
|
|
211 |
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
}
|
|
216 |
|
|
217 |
void commandClasses() {
|
|
218 |
StringBuffer classList = new StringBuffer();
|
51
|
219 |
for (ReferenceType refType : Env.vm().allClasses()) {
|
2
|
220 |
classList.append(refType.name());
|
|
221 |
classList.append("\n");
|
|
222 |
}
|
|
223 |
MessageOutput.print("** classes list **", classList.toString());
|
|
224 |
}
|
|
225 |
|
|
226 |
void commandClass(StringTokenizer t) {
|
51
|
227 |
List<ReferenceType> list = Env.vm().allClasses();
|
2
|
228 |
|
|
229 |
if (!t.hasMoreTokens()) {
|
|
230 |
MessageOutput.println("No class specified.");
|
|
231 |
return;
|
|
232 |
}
|
|
233 |
|
|
234 |
String idClass = t.nextToken();
|
|
235 |
boolean showAll = false;
|
|
236 |
|
|
237 |
if (t.hasMoreTokens()) {
|
|
238 |
if (t.nextToken().toLowerCase().equals("all")) {
|
|
239 |
showAll = true;
|
|
240 |
} else {
|
|
241 |
MessageOutput.println("Invalid option on class command");
|
|
242 |
return;
|
|
243 |
}
|
|
244 |
}
|
|
245 |
ReferenceType type = Env.getReferenceTypeFromToken(idClass);
|
|
246 |
if (type == null) {
|
|
247 |
MessageOutput.println("is not a valid id or class name", idClass);
|
|
248 |
return;
|
|
249 |
}
|
|
250 |
if (type instanceof ClassType) {
|
|
251 |
ClassType clazz = (ClassType)type;
|
|
252 |
MessageOutput.println("Class:", clazz.name());
|
|
253 |
|
|
254 |
ClassType superclass = clazz.superclass();
|
|
255 |
while (superclass != null) {
|
|
256 |
MessageOutput.println("extends:", superclass.name());
|
|
257 |
superclass = showAll ? superclass.superclass() : null;
|
|
258 |
}
|
|
259 |
|
51
|
260 |
List<InterfaceType> interfaces =
|
|
261 |
showAll ? clazz.allInterfaces() : clazz.interfaces();
|
|
262 |
for (InterfaceType interfaze : interfaces) {
|
2
|
263 |
MessageOutput.println("implements:", interfaze.name());
|
|
264 |
}
|
|
265 |
|
51
|
266 |
for (ClassType sub : clazz.subclasses()) {
|
2
|
267 |
MessageOutput.println("subclass:", sub.name());
|
|
268 |
}
|
51
|
269 |
for (ReferenceType nest : clazz.nestedTypes()) {
|
2
|
270 |
MessageOutput.println("nested:", nest.name());
|
|
271 |
}
|
|
272 |
} else if (type instanceof InterfaceType) {
|
|
273 |
InterfaceType interfaze = (InterfaceType)type;
|
|
274 |
MessageOutput.println("Interface:", interfaze.name());
|
51
|
275 |
for (InterfaceType superinterface : interfaze.superinterfaces()) {
|
2
|
276 |
MessageOutput.println("extends:", superinterface.name());
|
|
277 |
}
|
51
|
278 |
for (InterfaceType sub : interfaze.subinterfaces()) {
|
2
|
279 |
MessageOutput.println("subinterface:", sub.name());
|
|
280 |
}
|
51
|
281 |
for (ClassType implementor : interfaze.implementors()) {
|
2
|
282 |
MessageOutput.println("implementor:", implementor.name());
|
|
283 |
}
|
51
|
284 |
for (ReferenceType nest : interfaze.nestedTypes()) {
|
2
|
285 |
MessageOutput.println("nested:", nest.name());
|
|
286 |
}
|
|
287 |
} else { // array type
|
|
288 |
ArrayType array = (ArrayType)type;
|
|
289 |
MessageOutput.println("Array:", array.name());
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
void commandMethods(StringTokenizer t) {
|
|
294 |
if (!t.hasMoreTokens()) {
|
|
295 |
MessageOutput.println("No class specified.");
|
|
296 |
return;
|
|
297 |
}
|
|
298 |
|
|
299 |
String idClass = t.nextToken();
|
|
300 |
ReferenceType cls = Env.getReferenceTypeFromToken(idClass);
|
|
301 |
if (cls != null) {
|
|
302 |
StringBuffer methodsList = new StringBuffer();
|
51
|
303 |
for (Method method : cls.allMethods()) {
|
2
|
304 |
methodsList.append(method.declaringType().name());
|
|
305 |
methodsList.append(" ");
|
|
306 |
methodsList.append(typedName(method));
|
|
307 |
methodsList.append('\n');
|
|
308 |
}
|
|
309 |
MessageOutput.print("** methods list **", methodsList.toString());
|
|
310 |
} else {
|
|
311 |
MessageOutput.println("is not a valid id or class name", idClass);
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
void commandFields(StringTokenizer t) {
|
|
316 |
if (!t.hasMoreTokens()) {
|
|
317 |
MessageOutput.println("No class specified.");
|
|
318 |
return;
|
|
319 |
}
|
|
320 |
|
|
321 |
String idClass = t.nextToken();
|
|
322 |
ReferenceType cls = Env.getReferenceTypeFromToken(idClass);
|
|
323 |
if (cls != null) {
|
51
|
324 |
List<Field> fields = cls.allFields();
|
|
325 |
List<Field> visible = cls.visibleFields();
|
2
|
326 |
StringBuffer fieldsList = new StringBuffer();
|
51
|
327 |
for (Field field : fields) {
|
2
|
328 |
String s;
|
|
329 |
if (!visible.contains(field)) {
|
|
330 |
s = MessageOutput.format("list field typename and name hidden",
|
|
331 |
new Object [] {field.typeName(),
|
|
332 |
field.name()});
|
|
333 |
} else if (!field.declaringType().equals(cls)) {
|
|
334 |
s = MessageOutput.format("list field typename and name inherited",
|
|
335 |
new Object [] {field.typeName(),
|
|
336 |
field.name(),
|
|
337 |
field.declaringType().name()});
|
|
338 |
} else {
|
|
339 |
s = MessageOutput.format("list field typename and name",
|
|
340 |
new Object [] {field.typeName(),
|
|
341 |
field.name()});
|
|
342 |
}
|
|
343 |
fieldsList.append(s);
|
|
344 |
}
|
|
345 |
MessageOutput.print("** fields list **", fieldsList.toString());
|
|
346 |
} else {
|
|
347 |
MessageOutput.println("is not a valid id or class name", idClass);
|
|
348 |
}
|
|
349 |
}
|
|
350 |
|
|
351 |
private void printThreadGroup(ThreadGroupReference tg) {
|
|
352 |
ThreadIterator threadIter = new ThreadIterator(tg);
|
|
353 |
|
|
354 |
MessageOutput.println("Thread Group:", tg.name());
|
|
355 |
int maxIdLength = 0;
|
|
356 |
int maxNameLength = 0;
|
|
357 |
while (threadIter.hasNext()) {
|
51
|
358 |
ThreadReference thr = threadIter.next();
|
2
|
359 |
maxIdLength = Math.max(maxIdLength,
|
|
360 |
Env.description(thr).length());
|
|
361 |
maxNameLength = Math.max(maxNameLength,
|
|
362 |
thr.name().length());
|
|
363 |
}
|
|
364 |
|
|
365 |
threadIter = new ThreadIterator(tg);
|
|
366 |
while (threadIter.hasNext()) {
|
51
|
367 |
ThreadReference thr = threadIter.next();
|
2
|
368 |
if (thr.threadGroup() == null) {
|
|
369 |
continue;
|
|
370 |
}
|
|
371 |
// Note any thread group changes
|
|
372 |
if (!thr.threadGroup().equals(tg)) {
|
|
373 |
tg = thr.threadGroup();
|
|
374 |
MessageOutput.println("Thread Group:", tg.name());
|
|
375 |
}
|
|
376 |
|
|
377 |
/*
|
|
378 |
* Do a bit of filling with whitespace to get thread ID
|
|
379 |
* and thread names to line up in the listing, and also
|
|
380 |
* allow for proper localization. This also works for
|
|
381 |
* very long thread names, at the possible cost of lines
|
|
382 |
* being wrapped by the display device.
|
|
383 |
*/
|
|
384 |
StringBuffer idBuffer = new StringBuffer(Env.description(thr));
|
|
385 |
for (int i = idBuffer.length(); i < maxIdLength; i++) {
|
|
386 |
idBuffer.append(" ");
|
|
387 |
}
|
|
388 |
StringBuffer nameBuffer = new StringBuffer(thr.name());
|
|
389 |
for (int i = nameBuffer.length(); i < maxNameLength; i++) {
|
|
390 |
nameBuffer.append(" ");
|
|
391 |
}
|
|
392 |
|
|
393 |
/*
|
|
394 |
* Select the output format to use based on thread status
|
|
395 |
* and breakpoint.
|
|
396 |
*/
|
|
397 |
String statusFormat;
|
|
398 |
switch (thr.status()) {
|
|
399 |
case ThreadReference.THREAD_STATUS_UNKNOWN:
|
|
400 |
if (thr.isAtBreakpoint()) {
|
|
401 |
statusFormat = "Thread description name unknownStatus BP";
|
|
402 |
} else {
|
|
403 |
statusFormat = "Thread description name unknownStatus";
|
|
404 |
}
|
|
405 |
break;
|
|
406 |
case ThreadReference.THREAD_STATUS_ZOMBIE:
|
|
407 |
if (thr.isAtBreakpoint()) {
|
|
408 |
statusFormat = "Thread description name zombieStatus BP";
|
|
409 |
} else {
|
|
410 |
statusFormat = "Thread description name zombieStatus";
|
|
411 |
}
|
|
412 |
break;
|
|
413 |
case ThreadReference.THREAD_STATUS_RUNNING:
|
|
414 |
if (thr.isAtBreakpoint()) {
|
|
415 |
statusFormat = "Thread description name runningStatus BP";
|
|
416 |
} else {
|
|
417 |
statusFormat = "Thread description name runningStatus";
|
|
418 |
}
|
|
419 |
break;
|
|
420 |
case ThreadReference.THREAD_STATUS_SLEEPING:
|
|
421 |
if (thr.isAtBreakpoint()) {
|
|
422 |
statusFormat = "Thread description name sleepingStatus BP";
|
|
423 |
} else {
|
|
424 |
statusFormat = "Thread description name sleepingStatus";
|
|
425 |
}
|
|
426 |
break;
|
|
427 |
case ThreadReference.THREAD_STATUS_MONITOR:
|
|
428 |
if (thr.isAtBreakpoint()) {
|
|
429 |
statusFormat = "Thread description name waitingStatus BP";
|
|
430 |
} else {
|
|
431 |
statusFormat = "Thread description name waitingStatus";
|
|
432 |
}
|
|
433 |
break;
|
|
434 |
case ThreadReference.THREAD_STATUS_WAIT:
|
|
435 |
if (thr.isAtBreakpoint()) {
|
|
436 |
statusFormat = "Thread description name condWaitstatus BP";
|
|
437 |
} else {
|
|
438 |
statusFormat = "Thread description name condWaitstatus";
|
|
439 |
}
|
|
440 |
break;
|
|
441 |
default:
|
|
442 |
throw new InternalError(MessageOutput.format("Invalid thread status."));
|
|
443 |
}
|
|
444 |
MessageOutput.println(statusFormat,
|
|
445 |
new Object [] {idBuffer.toString(),
|
|
446 |
nameBuffer.toString()});
|
|
447 |
}
|
|
448 |
}
|
|
449 |
|
|
450 |
void commandThreads(StringTokenizer t) {
|
|
451 |
if (!t.hasMoreTokens()) {
|
|
452 |
printThreadGroup(ThreadInfo.group());
|
|
453 |
return;
|
|
454 |
}
|
|
455 |
String name = t.nextToken();
|
|
456 |
ThreadGroupReference tg = ThreadGroupIterator.find(name);
|
|
457 |
if (tg == null) {
|
|
458 |
MessageOutput.println("is not a valid threadgroup name", name);
|
|
459 |
} else {
|
|
460 |
printThreadGroup(tg);
|
|
461 |
}
|
|
462 |
}
|
|
463 |
|
|
464 |
void commandThreadGroups() {
|
|
465 |
ThreadGroupIterator it = new ThreadGroupIterator();
|
|
466 |
int cnt = 0;
|
|
467 |
while (it.hasNext()) {
|
|
468 |
ThreadGroupReference tg = it.nextThreadGroup();
|
|
469 |
++cnt;
|
|
470 |
MessageOutput.println("thread group number description name",
|
|
471 |
new Object [] { new Integer (cnt),
|
|
472 |
Env.description(tg),
|
|
473 |
tg.name()});
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
void commandThread(StringTokenizer t) {
|
|
478 |
if (!t.hasMoreTokens()) {
|
|
479 |
MessageOutput.println("Thread number not specified.");
|
|
480 |
return;
|
|
481 |
}
|
|
482 |
ThreadInfo threadInfo = doGetThread(t.nextToken());
|
|
483 |
if (threadInfo != null) {
|
|
484 |
ThreadInfo.setCurrentThreadInfo(threadInfo);
|
|
485 |
}
|
|
486 |
}
|
|
487 |
|
|
488 |
void commandThreadGroup(StringTokenizer t) {
|
|
489 |
if (!t.hasMoreTokens()) {
|
|
490 |
MessageOutput.println("Threadgroup name not specified.");
|
|
491 |
return;
|
|
492 |
}
|
|
493 |
String name = t.nextToken();
|
|
494 |
ThreadGroupReference tg = ThreadGroupIterator.find(name);
|
|
495 |
if (tg == null) {
|
|
496 |
MessageOutput.println("is not a valid threadgroup name", name);
|
|
497 |
} else {
|
|
498 |
ThreadInfo.setThreadGroup(tg);
|
|
499 |
}
|
|
500 |
}
|
|
501 |
|
|
502 |
void commandRun(StringTokenizer t) {
|
|
503 |
/*
|
|
504 |
* The 'run' command makes little sense in a
|
|
505 |
* that doesn't support restarts or multiple VMs. However,
|
|
506 |
* this is an attempt to emulate the behavior of the old
|
|
507 |
* JDB as much as possible. For new users and implementations
|
|
508 |
* it is much more straightforward to launch immedidately
|
|
509 |
* with the -launch option.
|
|
510 |
*/
|
|
511 |
VMConnection connection = Env.connection();
|
|
512 |
if (!connection.isLaunch()) {
|
|
513 |
if (!t.hasMoreTokens()) {
|
|
514 |
commandCont();
|
|
515 |
} else {
|
|
516 |
MessageOutput.println("run <args> command is valid only with launched VMs");
|
|
517 |
}
|
|
518 |
return;
|
|
519 |
}
|
|
520 |
if (connection.isOpen()) {
|
|
521 |
MessageOutput.println("VM already running. use cont to continue after events.");
|
|
522 |
return;
|
|
523 |
}
|
|
524 |
|
|
525 |
/*
|
|
526 |
* Set the main class and any arguments. Note that this will work
|
|
527 |
* only with the standard launcher, "com.sun.jdi.CommandLineLauncher"
|
|
528 |
*/
|
|
529 |
String args;
|
|
530 |
if (t.hasMoreTokens()) {
|
|
531 |
args = t.nextToken("");
|
|
532 |
boolean argsSet = connection.setConnectorArg("main", args);
|
|
533 |
if (!argsSet) {
|
|
534 |
MessageOutput.println("Unable to set main class and arguments");
|
|
535 |
return;
|
|
536 |
}
|
|
537 |
} else {
|
|
538 |
args = connection.connectorArg("main");
|
|
539 |
if (args.length() == 0) {
|
|
540 |
MessageOutput.println("Main class and arguments must be specified");
|
|
541 |
return;
|
|
542 |
}
|
|
543 |
}
|
|
544 |
MessageOutput.println("run", args);
|
|
545 |
|
|
546 |
/*
|
|
547 |
* Launch the VM.
|
|
548 |
*/
|
|
549 |
connection.open();
|
|
550 |
|
|
551 |
}
|
|
552 |
|
|
553 |
void commandLoad(StringTokenizer t) {
|
|
554 |
MessageOutput.println("The load command is no longer supported.");
|
|
555 |
}
|
|
556 |
|
|
557 |
private List<ThreadReference> allThreads(ThreadGroupReference group) {
|
|
558 |
List<ThreadReference> list = new ArrayList<ThreadReference>();
|
|
559 |
list.addAll(group.threads());
|
51
|
560 |
for (ThreadGroupReference child : group.threadGroups()) {
|
2
|
561 |
list.addAll(allThreads(child));
|
|
562 |
}
|
|
563 |
return list;
|
|
564 |
}
|
|
565 |
|
|
566 |
void commandSuspend(StringTokenizer t) {
|
|
567 |
if (!t.hasMoreTokens()) {
|
|
568 |
Env.vm().suspend();
|
|
569 |
MessageOutput.println("All threads suspended.");
|
|
570 |
} else {
|
|
571 |
while (t.hasMoreTokens()) {
|
|
572 |
ThreadInfo threadInfo = doGetThread(t.nextToken());
|
|
573 |
if (threadInfo != null) {
|
|
574 |
threadInfo.getThread().suspend();
|
|
575 |
}
|
|
576 |
}
|
|
577 |
}
|
|
578 |
}
|
|
579 |
|
|
580 |
void commandResume(StringTokenizer t) {
|
|
581 |
if (!t.hasMoreTokens()) {
|
|
582 |
ThreadInfo.invalidateAll();
|
|
583 |
Env.vm().resume();
|
|
584 |
MessageOutput.println("All threads resumed.");
|
|
585 |
} else {
|
|
586 |
while (t.hasMoreTokens()) {
|
|
587 |
ThreadInfo threadInfo = doGetThread(t.nextToken());
|
|
588 |
if (threadInfo != null) {
|
|
589 |
threadInfo.invalidate();
|
|
590 |
threadInfo.getThread().resume();
|
|
591 |
}
|
|
592 |
}
|
|
593 |
}
|
|
594 |
}
|
|
595 |
|
|
596 |
void commandCont() {
|
|
597 |
if (ThreadInfo.getCurrentThreadInfo() == null) {
|
|
598 |
MessageOutput.println("Nothing suspended.");
|
|
599 |
return;
|
|
600 |
}
|
|
601 |
ThreadInfo.invalidateAll();
|
|
602 |
Env.vm().resume();
|
|
603 |
}
|
|
604 |
|
|
605 |
void clearPreviousStep(ThreadReference thread) {
|
|
606 |
/*
|
|
607 |
* A previous step may not have completed on this thread;
|
|
608 |
* if so, it gets removed here.
|
|
609 |
*/
|
|
610 |
EventRequestManager mgr = Env.vm().eventRequestManager();
|
51
|
611 |
for (StepRequest request : mgr.stepRequests()) {
|
2
|
612 |
if (request.thread().equals(thread)) {
|
|
613 |
mgr.deleteEventRequest(request);
|
|
614 |
break;
|
|
615 |
}
|
|
616 |
}
|
|
617 |
}
|
|
618 |
/* step
|
|
619 |
*
|
|
620 |
*/
|
|
621 |
void commandStep(StringTokenizer t) {
|
|
622 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
623 |
if (threadInfo == null) {
|
|
624 |
MessageOutput.println("Nothing suspended.");
|
|
625 |
return;
|
|
626 |
}
|
|
627 |
int depth;
|
|
628 |
if (t.hasMoreTokens() &&
|
|
629 |
t.nextToken().toLowerCase().equals("up")) {
|
|
630 |
depth = StepRequest.STEP_OUT;
|
|
631 |
} else {
|
|
632 |
depth = StepRequest.STEP_INTO;
|
|
633 |
}
|
|
634 |
|
|
635 |
clearPreviousStep(threadInfo.getThread());
|
|
636 |
EventRequestManager reqMgr = Env.vm().eventRequestManager();
|
|
637 |
StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(),
|
|
638 |
StepRequest.STEP_LINE, depth);
|
|
639 |
if (depth == StepRequest.STEP_INTO) {
|
|
640 |
Env.addExcludes(request);
|
|
641 |
}
|
|
642 |
// We want just the next step event and no others
|
|
643 |
request.addCountFilter(1);
|
|
644 |
request.enable();
|
|
645 |
ThreadInfo.invalidateAll();
|
|
646 |
Env.vm().resume();
|
|
647 |
}
|
|
648 |
|
|
649 |
/* stepi
|
|
650 |
* step instruction.
|
|
651 |
*/
|
|
652 |
void commandStepi() {
|
|
653 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
654 |
if (threadInfo == null) {
|
|
655 |
MessageOutput.println("Nothing suspended.");
|
|
656 |
return;
|
|
657 |
}
|
|
658 |
clearPreviousStep(threadInfo.getThread());
|
|
659 |
EventRequestManager reqMgr = Env.vm().eventRequestManager();
|
|
660 |
StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(),
|
|
661 |
StepRequest.STEP_MIN,
|
|
662 |
StepRequest.STEP_INTO);
|
|
663 |
Env.addExcludes(request);
|
|
664 |
// We want just the next step event and no others
|
|
665 |
request.addCountFilter(1);
|
|
666 |
request.enable();
|
|
667 |
ThreadInfo.invalidateAll();
|
|
668 |
Env.vm().resume();
|
|
669 |
}
|
|
670 |
|
|
671 |
void commandNext() {
|
|
672 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
673 |
if (threadInfo == null) {
|
|
674 |
MessageOutput.println("Nothing suspended.");
|
|
675 |
return;
|
|
676 |
}
|
|
677 |
clearPreviousStep(threadInfo.getThread());
|
|
678 |
EventRequestManager reqMgr = Env.vm().eventRequestManager();
|
|
679 |
StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(),
|
|
680 |
StepRequest.STEP_LINE,
|
|
681 |
StepRequest.STEP_OVER);
|
|
682 |
Env.addExcludes(request);
|
|
683 |
// We want just the next step event and no others
|
|
684 |
request.addCountFilter(1);
|
|
685 |
request.enable();
|
|
686 |
ThreadInfo.invalidateAll();
|
|
687 |
Env.vm().resume();
|
|
688 |
}
|
|
689 |
|
|
690 |
void doKill(ThreadReference thread, StringTokenizer t) {
|
|
691 |
if (!t.hasMoreTokens()) {
|
|
692 |
MessageOutput.println("No exception object specified.");
|
|
693 |
return;
|
|
694 |
}
|
|
695 |
String expr = t.nextToken("");
|
|
696 |
Value val = evaluate(expr);
|
|
697 |
if ((val != null) && (val instanceof ObjectReference)) {
|
|
698 |
try {
|
|
699 |
thread.stop((ObjectReference)val);
|
|
700 |
MessageOutput.println("killed", thread.toString());
|
|
701 |
} catch (InvalidTypeException e) {
|
|
702 |
MessageOutput.println("Invalid exception object");
|
|
703 |
}
|
|
704 |
} else {
|
|
705 |
MessageOutput.println("Expression must evaluate to an object");
|
|
706 |
}
|
|
707 |
}
|
|
708 |
|
|
709 |
void doKillThread(final ThreadReference threadToKill,
|
|
710 |
final StringTokenizer tokenizer) {
|
|
711 |
new AsyncExecution() {
|
|
712 |
void action() {
|
|
713 |
doKill(threadToKill, tokenizer);
|
|
714 |
}
|
|
715 |
};
|
|
716 |
}
|
|
717 |
|
|
718 |
void commandKill(StringTokenizer t) {
|
|
719 |
if (!t.hasMoreTokens()) {
|
|
720 |
MessageOutput.println("Usage: kill <thread id> <throwable>");
|
|
721 |
return;
|
|
722 |
}
|
|
723 |
ThreadInfo threadInfo = doGetThread(t.nextToken());
|
|
724 |
if (threadInfo != null) {
|
|
725 |
MessageOutput.println("killing thread:", threadInfo.getThread().name());
|
|
726 |
doKillThread(threadInfo.getThread(), t);
|
|
727 |
return;
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
void listCaughtExceptions() {
|
|
732 |
boolean noExceptions = true;
|
|
733 |
|
|
734 |
// Print a listing of the catch patterns currently in place
|
51
|
735 |
for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
|
2
|
736 |
if (spec instanceof ExceptionSpec) {
|
|
737 |
if (noExceptions) {
|
|
738 |
noExceptions = false;
|
|
739 |
MessageOutput.println("Exceptions caught:");
|
|
740 |
}
|
|
741 |
MessageOutput.println("tab", spec.toString());
|
|
742 |
}
|
|
743 |
}
|
|
744 |
if (noExceptions) {
|
|
745 |
MessageOutput.println("No exceptions caught.");
|
|
746 |
}
|
|
747 |
}
|
|
748 |
|
|
749 |
private EventRequestSpec parseExceptionSpec(StringTokenizer t) {
|
|
750 |
String notification = t.nextToken();
|
|
751 |
boolean notifyCaught = false;
|
|
752 |
boolean notifyUncaught = false;
|
|
753 |
EventRequestSpec spec = null;
|
|
754 |
String classPattern = null;
|
|
755 |
|
|
756 |
if (notification.equals("uncaught")) {
|
|
757 |
notifyCaught = false;
|
|
758 |
notifyUncaught = true;
|
|
759 |
} else if (notification.equals("caught")) {
|
|
760 |
notifyCaught = true;
|
|
761 |
notifyUncaught = false;
|
|
762 |
} else if (notification.equals("all")) {
|
|
763 |
notifyCaught = true;
|
|
764 |
notifyUncaught = true;
|
|
765 |
} else {
|
|
766 |
/*
|
|
767 |
* Handle the same as "all" for backward
|
|
768 |
* compatibility with existing .jdbrc files.
|
|
769 |
*
|
|
770 |
* Insert an "all" and take the current token as the
|
|
771 |
* intended classPattern
|
|
772 |
*
|
|
773 |
*/
|
|
774 |
notifyCaught = true;
|
|
775 |
notifyUncaught = true;
|
|
776 |
classPattern = notification;
|
|
777 |
}
|
|
778 |
if (classPattern == null && t.hasMoreTokens()) {
|
|
779 |
classPattern = t.nextToken();
|
|
780 |
}
|
|
781 |
if ((classPattern != null) && (notifyCaught || notifyUncaught)) {
|
|
782 |
try {
|
|
783 |
spec = Env.specList.createExceptionCatch(classPattern,
|
|
784 |
notifyCaught,
|
|
785 |
notifyUncaught);
|
|
786 |
} catch (ClassNotFoundException exc) {
|
|
787 |
MessageOutput.println("is not a valid class name", classPattern);
|
|
788 |
}
|
|
789 |
}
|
|
790 |
return spec;
|
|
791 |
}
|
|
792 |
|
|
793 |
void commandCatchException(StringTokenizer t) {
|
|
794 |
if (!t.hasMoreTokens()) {
|
|
795 |
listCaughtExceptions();
|
|
796 |
} else {
|
|
797 |
EventRequestSpec spec = parseExceptionSpec(t);
|
|
798 |
if (spec != null) {
|
|
799 |
resolveNow(spec);
|
|
800 |
} else {
|
|
801 |
MessageOutput.println("Usage: catch exception");
|
|
802 |
}
|
|
803 |
}
|
|
804 |
}
|
|
805 |
|
|
806 |
void commandIgnoreException(StringTokenizer t) {
|
|
807 |
if (!t.hasMoreTokens()) {
|
|
808 |
listCaughtExceptions();
|
|
809 |
} else {
|
|
810 |
EventRequestSpec spec = parseExceptionSpec(t);
|
|
811 |
if (Env.specList.delete(spec)) {
|
|
812 |
MessageOutput.println("Removed:", spec.toString());
|
|
813 |
} else {
|
|
814 |
if (spec != null) {
|
|
815 |
MessageOutput.println("Not found:", spec.toString());
|
|
816 |
}
|
|
817 |
MessageOutput.println("Usage: ignore exception");
|
|
818 |
}
|
|
819 |
}
|
|
820 |
}
|
|
821 |
|
|
822 |
void commandUp(StringTokenizer t) {
|
|
823 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
824 |
if (threadInfo == null) {
|
|
825 |
MessageOutput.println("Current thread not set.");
|
|
826 |
return;
|
|
827 |
}
|
|
828 |
|
|
829 |
int nLevels = 1;
|
|
830 |
if (t.hasMoreTokens()) {
|
|
831 |
String idToken = t.nextToken();
|
|
832 |
int i;
|
|
833 |
try {
|
|
834 |
NumberFormat nf = NumberFormat.getNumberInstance();
|
|
835 |
nf.setParseIntegerOnly(true);
|
|
836 |
Number n = nf.parse(idToken);
|
|
837 |
i = n.intValue();
|
|
838 |
} catch (java.text.ParseException jtpe) {
|
|
839 |
i = 0;
|
|
840 |
}
|
|
841 |
if (i <= 0) {
|
|
842 |
MessageOutput.println("Usage: up [n frames]");
|
|
843 |
return;
|
|
844 |
}
|
|
845 |
nLevels = i;
|
|
846 |
}
|
|
847 |
|
|
848 |
try {
|
|
849 |
threadInfo.up(nLevels);
|
|
850 |
} catch (IncompatibleThreadStateException e) {
|
|
851 |
MessageOutput.println("Current thread isnt suspended.");
|
|
852 |
} catch (ArrayIndexOutOfBoundsException e) {
|
|
853 |
MessageOutput.println("End of stack.");
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
void commandDown(StringTokenizer t) {
|
|
858 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
859 |
if (threadInfo == null) {
|
|
860 |
MessageOutput.println("Current thread not set.");
|
|
861 |
return;
|
|
862 |
}
|
|
863 |
|
|
864 |
int nLevels = 1;
|
|
865 |
if (t.hasMoreTokens()) {
|
|
866 |
String idToken = t.nextToken();
|
|
867 |
int i;
|
|
868 |
try {
|
|
869 |
NumberFormat nf = NumberFormat.getNumberInstance();
|
|
870 |
nf.setParseIntegerOnly(true);
|
|
871 |
Number n = nf.parse(idToken);
|
|
872 |
i = n.intValue();
|
|
873 |
} catch (java.text.ParseException jtpe) {
|
|
874 |
i = 0;
|
|
875 |
}
|
|
876 |
if (i <= 0) {
|
|
877 |
MessageOutput.println("Usage: down [n frames]");
|
|
878 |
return;
|
|
879 |
}
|
|
880 |
nLevels = i;
|
|
881 |
}
|
|
882 |
|
|
883 |
try {
|
|
884 |
threadInfo.down(nLevels);
|
|
885 |
} catch (IncompatibleThreadStateException e) {
|
|
886 |
MessageOutput.println("Current thread isnt suspended.");
|
|
887 |
} catch (ArrayIndexOutOfBoundsException e) {
|
|
888 |
MessageOutput.println("End of stack.");
|
|
889 |
}
|
|
890 |
}
|
|
891 |
|
|
892 |
private void dumpStack(ThreadInfo threadInfo, boolean showPC) {
|
51
|
893 |
List<StackFrame> stack = null;
|
2
|
894 |
try {
|
|
895 |
stack = threadInfo.getStack();
|
|
896 |
} catch (IncompatibleThreadStateException e) {
|
|
897 |
MessageOutput.println("Current thread isnt suspended.");
|
|
898 |
return;
|
|
899 |
}
|
|
900 |
if (stack == null) {
|
|
901 |
MessageOutput.println("Thread is not running (no stack).");
|
|
902 |
} else {
|
|
903 |
int nFrames = stack.size();
|
|
904 |
for (int i = threadInfo.getCurrentFrameIndex(); i < nFrames; i++) {
|
51
|
905 |
StackFrame frame = stack.get(i);
|
2
|
906 |
dumpFrame (i, showPC, frame);
|
|
907 |
}
|
|
908 |
}
|
|
909 |
}
|
|
910 |
|
|
911 |
private void dumpFrame (int frameNumber, boolean showPC, StackFrame frame) {
|
|
912 |
Location loc = frame.location();
|
|
913 |
long pc = -1;
|
|
914 |
if (showPC) {
|
|
915 |
pc = loc.codeIndex();
|
|
916 |
}
|
|
917 |
Method meth = loc.method();
|
|
918 |
|
|
919 |
long lineNumber = loc.lineNumber();
|
|
920 |
String methodInfo = null;
|
51
|
921 |
if (meth.isNative()) {
|
2
|
922 |
methodInfo = MessageOutput.format("native method");
|
|
923 |
} else if (lineNumber != -1) {
|
|
924 |
try {
|
|
925 |
methodInfo = loc.sourceName() +
|
|
926 |
MessageOutput.format("line number",
|
|
927 |
new Object [] {new Long(lineNumber)});
|
|
928 |
} catch (AbsentInformationException e) {
|
|
929 |
methodInfo = MessageOutput.format("unknown");
|
|
930 |
}
|
|
931 |
}
|
|
932 |
if (pc != -1) {
|
|
933 |
MessageOutput.println("stack frame dump with pc",
|
|
934 |
new Object [] {new Integer(frameNumber + 1),
|
|
935 |
meth.declaringType().name(),
|
|
936 |
meth.name(),
|
|
937 |
methodInfo,
|
|
938 |
new Long(pc)});
|
|
939 |
} else {
|
|
940 |
MessageOutput.println("stack frame dump",
|
|
941 |
new Object [] {new Integer(frameNumber + 1),
|
|
942 |
meth.declaringType().name(),
|
|
943 |
meth.name(),
|
|
944 |
methodInfo});
|
|
945 |
}
|
|
946 |
}
|
|
947 |
|
|
948 |
void commandWhere(StringTokenizer t, boolean showPC) {
|
|
949 |
if (!t.hasMoreTokens()) {
|
|
950 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
951 |
if (threadInfo == null) {
|
|
952 |
MessageOutput.println("No thread specified.");
|
|
953 |
return;
|
|
954 |
}
|
|
955 |
dumpStack(threadInfo, showPC);
|
|
956 |
} else {
|
|
957 |
String token = t.nextToken();
|
|
958 |
if (token.toLowerCase().equals("all")) {
|
51
|
959 |
for (ThreadInfo threadInfo : ThreadInfo.threads()) {
|
2
|
960 |
MessageOutput.println("Thread:",
|
|
961 |
threadInfo.getThread().name());
|
|
962 |
dumpStack(threadInfo, showPC);
|
|
963 |
}
|
|
964 |
} else {
|
|
965 |
ThreadInfo threadInfo = doGetThread(token);
|
|
966 |
if (threadInfo != null) {
|
|
967 |
ThreadInfo.setCurrentThreadInfo(threadInfo);
|
|
968 |
dumpStack(threadInfo, showPC);
|
|
969 |
}
|
|
970 |
}
|
|
971 |
}
|
|
972 |
}
|
|
973 |
|
|
974 |
void commandInterrupt(StringTokenizer t) {
|
|
975 |
if (!t.hasMoreTokens()) {
|
|
976 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
977 |
if (threadInfo == null) {
|
|
978 |
MessageOutput.println("No thread specified.");
|
|
979 |
return;
|
|
980 |
}
|
|
981 |
threadInfo.getThread().interrupt();
|
|
982 |
} else {
|
|
983 |
ThreadInfo threadInfo = doGetThread(t.nextToken());
|
|
984 |
if (threadInfo != null) {
|
|
985 |
threadInfo.getThread().interrupt();
|
|
986 |
}
|
|
987 |
}
|
|
988 |
}
|
|
989 |
|
|
990 |
void commandMemory() {
|
|
991 |
MessageOutput.println("The memory command is no longer supported.");
|
|
992 |
}
|
|
993 |
|
|
994 |
void commandGC() {
|
|
995 |
MessageOutput.println("The gc command is no longer necessary.");
|
|
996 |
}
|
|
997 |
|
|
998 |
/*
|
|
999 |
* The next two methods are used by this class and by EventHandler
|
|
1000 |
* to print consistent locations and error messages.
|
|
1001 |
*/
|
|
1002 |
static String locationString(Location loc) {
|
|
1003 |
return MessageOutput.format("locationString",
|
|
1004 |
new Object [] {loc.declaringType().name(),
|
|
1005 |
loc.method().name(),
|
|
1006 |
new Integer (loc.lineNumber()),
|
|
1007 |
new Long (loc.codeIndex())});
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
void listBreakpoints() {
|
|
1011 |
boolean noBreakpoints = true;
|
|
1012 |
|
|
1013 |
// Print set breakpoints
|
51
|
1014 |
for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
|
2
|
1015 |
if (spec instanceof BreakpointSpec) {
|
|
1016 |
if (noBreakpoints) {
|
|
1017 |
noBreakpoints = false;
|
|
1018 |
MessageOutput.println("Breakpoints set:");
|
|
1019 |
}
|
|
1020 |
MessageOutput.println("tab", spec.toString());
|
|
1021 |
}
|
|
1022 |
}
|
|
1023 |
if (noBreakpoints) {
|
|
1024 |
MessageOutput.println("No breakpoints set.");
|
|
1025 |
}
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
|
|
1029 |
private void printBreakpointCommandUsage(String atForm, String inForm) {
|
|
1030 |
MessageOutput.println("printbreakpointcommandusage",
|
|
1031 |
new Object [] {atForm, inForm});
|
|
1032 |
}
|
|
1033 |
|
|
1034 |
protected BreakpointSpec parseBreakpointSpec(StringTokenizer t,
|
|
1035 |
String atForm, String inForm) {
|
51
|
1036 |
BreakpointSpec breakpoint = null;
|
2
|
1037 |
try {
|
|
1038 |
String token = t.nextToken(":( \t\n\r");
|
|
1039 |
|
|
1040 |
// We can't use hasMoreTokens here because it will cause any leading
|
|
1041 |
// paren to be lost.
|
|
1042 |
String rest;
|
|
1043 |
try {
|
|
1044 |
rest = t.nextToken("").trim();
|
|
1045 |
} catch (NoSuchElementException e) {
|
|
1046 |
rest = null;
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
if ((rest != null) && rest.startsWith(":")) {
|
|
1050 |
t = new StringTokenizer(rest.substring(1));
|
|
1051 |
String classId = token;
|
|
1052 |
String lineToken = t.nextToken();
|
|
1053 |
|
|
1054 |
NumberFormat nf = NumberFormat.getNumberInstance();
|
|
1055 |
nf.setParseIntegerOnly(true);
|
|
1056 |
Number n = nf.parse(lineToken);
|
|
1057 |
int lineNumber = n.intValue();
|
|
1058 |
|
|
1059 |
if (t.hasMoreTokens()) {
|
|
1060 |
printBreakpointCommandUsage(atForm, inForm);
|
|
1061 |
return null;
|
|
1062 |
}
|
|
1063 |
try {
|
|
1064 |
breakpoint = Env.specList.createBreakpoint(classId,
|
|
1065 |
lineNumber);
|
|
1066 |
} catch (ClassNotFoundException exc) {
|
|
1067 |
MessageOutput.println("is not a valid class name", classId);
|
|
1068 |
}
|
|
1069 |
} else {
|
|
1070 |
// Try stripping method from class.method token.
|
|
1071 |
int idot = token.lastIndexOf(".");
|
|
1072 |
if ( (idot <= 0) || /* No dot or dot in first char */
|
|
1073 |
(idot >= token.length() - 1) ) { /* dot in last char */
|
|
1074 |
printBreakpointCommandUsage(atForm, inForm);
|
|
1075 |
return null;
|
|
1076 |
}
|
|
1077 |
String methodName = token.substring(idot + 1);
|
|
1078 |
String classId = token.substring(0, idot);
|
|
1079 |
List<String> argumentList = null;
|
|
1080 |
if (rest != null) {
|
|
1081 |
if (!rest.startsWith("(") || !rest.endsWith(")")) {
|
|
1082 |
MessageOutput.println("Invalid method specification:",
|
|
1083 |
methodName + rest);
|
|
1084 |
printBreakpointCommandUsage(atForm, inForm);
|
|
1085 |
return null;
|
|
1086 |
}
|
|
1087 |
// Trim the parens
|
|
1088 |
rest = rest.substring(1, rest.length() - 1);
|
|
1089 |
|
|
1090 |
argumentList = new ArrayList<String>();
|
|
1091 |
t = new StringTokenizer(rest, ",");
|
|
1092 |
while (t.hasMoreTokens()) {
|
|
1093 |
argumentList.add(t.nextToken());
|
|
1094 |
}
|
|
1095 |
}
|
|
1096 |
try {
|
|
1097 |
breakpoint = Env.specList.createBreakpoint(classId,
|
|
1098 |
methodName,
|
|
1099 |
argumentList);
|
|
1100 |
} catch (MalformedMemberNameException exc) {
|
|
1101 |
MessageOutput.println("is not a valid method name", methodName);
|
|
1102 |
} catch (ClassNotFoundException exc) {
|
|
1103 |
MessageOutput.println("is not a valid class name", classId);
|
|
1104 |
}
|
|
1105 |
}
|
|
1106 |
} catch (Exception e) {
|
|
1107 |
printBreakpointCommandUsage(atForm, inForm);
|
|
1108 |
return null;
|
|
1109 |
}
|
51
|
1110 |
return breakpoint;
|
2
|
1111 |
}
|
|
1112 |
|
|
1113 |
private void resolveNow(EventRequestSpec spec) {
|
|
1114 |
boolean success = Env.specList.addEagerlyResolve(spec);
|
|
1115 |
if (success && !spec.isResolved()) {
|
|
1116 |
MessageOutput.println("Deferring.", spec.toString());
|
|
1117 |
}
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
void commandStop(StringTokenizer t) {
|
|
1121 |
Location bploc;
|
|
1122 |
String atIn;
|
|
1123 |
byte suspendPolicy = EventRequest.SUSPEND_ALL;
|
|
1124 |
|
|
1125 |
if (t.hasMoreTokens()) {
|
|
1126 |
atIn = t.nextToken();
|
|
1127 |
if (atIn.equals("go") && t.hasMoreTokens()) {
|
|
1128 |
suspendPolicy = EventRequest.SUSPEND_NONE;
|
|
1129 |
atIn = t.nextToken();
|
|
1130 |
} else if (atIn.equals("thread") && t.hasMoreTokens()) {
|
|
1131 |
suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
|
|
1132 |
atIn = t.nextToken();
|
|
1133 |
}
|
|
1134 |
} else {
|
|
1135 |
listBreakpoints();
|
|
1136 |
return;
|
|
1137 |
}
|
|
1138 |
|
|
1139 |
BreakpointSpec spec = parseBreakpointSpec(t, "stop at", "stop in");
|
|
1140 |
if (spec != null) {
|
|
1141 |
// Enforcement of "at" vs. "in". The distinction is really
|
|
1142 |
// unnecessary and we should consider not checking for this
|
|
1143 |
// (and making "at" and "in" optional).
|
|
1144 |
if (atIn.equals("at") && spec.isMethodBreakpoint()) {
|
|
1145 |
MessageOutput.println("Use stop at to set a breakpoint at a line number");
|
|
1146 |
printBreakpointCommandUsage("stop at", "stop in");
|
|
1147 |
return;
|
|
1148 |
}
|
|
1149 |
spec.suspendPolicy = suspendPolicy;
|
|
1150 |
resolveNow(spec);
|
|
1151 |
}
|
|
1152 |
}
|
|
1153 |
|
|
1154 |
void commandClear(StringTokenizer t) {
|
|
1155 |
if (!t.hasMoreTokens()) {
|
|
1156 |
listBreakpoints();
|
|
1157 |
return;
|
|
1158 |
}
|
|
1159 |
|
|
1160 |
BreakpointSpec spec = parseBreakpointSpec(t, "clear", "clear");
|
|
1161 |
if (spec != null) {
|
|
1162 |
if (Env.specList.delete(spec)) {
|
|
1163 |
MessageOutput.println("Removed:", spec.toString());
|
|
1164 |
} else {
|
|
1165 |
MessageOutput.println("Not found:", spec.toString());
|
|
1166 |
}
|
|
1167 |
}
|
|
1168 |
}
|
|
1169 |
|
51
|
1170 |
private List<WatchpointSpec> parseWatchpointSpec(StringTokenizer t) {
|
|
1171 |
List<WatchpointSpec> list = new ArrayList<WatchpointSpec>();
|
2
|
1172 |
boolean access = false;
|
|
1173 |
boolean modification = false;
|
|
1174 |
int suspendPolicy = EventRequest.SUSPEND_ALL;
|
|
1175 |
|
|
1176 |
String fieldName = t.nextToken();
|
|
1177 |
if (fieldName.equals("go")) {
|
|
1178 |
suspendPolicy = EventRequest.SUSPEND_NONE;
|
|
1179 |
fieldName = t.nextToken();
|
|
1180 |
} else if (fieldName.equals("thread")) {
|
|
1181 |
suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
|
|
1182 |
fieldName = t.nextToken();
|
|
1183 |
}
|
|
1184 |
if (fieldName.equals("access")) {
|
|
1185 |
access = true;
|
|
1186 |
fieldName = t.nextToken();
|
|
1187 |
} else if (fieldName.equals("all")) {
|
|
1188 |
access = true;
|
|
1189 |
modification = true;
|
|
1190 |
fieldName = t.nextToken();
|
|
1191 |
} else {
|
|
1192 |
modification = true;
|
|
1193 |
}
|
|
1194 |
int dot = fieldName.lastIndexOf('.');
|
|
1195 |
if (dot < 0) {
|
|
1196 |
MessageOutput.println("Class containing field must be specified.");
|
|
1197 |
return list;
|
|
1198 |
}
|
|
1199 |
String className = fieldName.substring(0, dot);
|
|
1200 |
fieldName = fieldName.substring(dot+1);
|
|
1201 |
|
|
1202 |
try {
|
51
|
1203 |
WatchpointSpec spec;
|
2
|
1204 |
if (access) {
|
|
1205 |
spec = Env.specList.createAccessWatchpoint(className,
|
|
1206 |
fieldName);
|
|
1207 |
spec.suspendPolicy = suspendPolicy;
|
|
1208 |
list.add(spec);
|
|
1209 |
}
|
|
1210 |
if (modification) {
|
|
1211 |
spec = Env.specList.createModificationWatchpoint(className,
|
|
1212 |
fieldName);
|
|
1213 |
spec.suspendPolicy = suspendPolicy;
|
|
1214 |
list.add(spec);
|
|
1215 |
}
|
|
1216 |
} catch (MalformedMemberNameException exc) {
|
|
1217 |
MessageOutput.println("is not a valid field name", fieldName);
|
|
1218 |
} catch (ClassNotFoundException exc) {
|
|
1219 |
MessageOutput.println("is not a valid class name", className);
|
|
1220 |
}
|
|
1221 |
return list;
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
void commandWatch(StringTokenizer t) {
|
|
1225 |
if (!t.hasMoreTokens()) {
|
|
1226 |
MessageOutput.println("Field to watch not specified");
|
|
1227 |
return;
|
|
1228 |
}
|
|
1229 |
|
51
|
1230 |
for (WatchpointSpec spec : parseWatchpointSpec(t)) {
|
|
1231 |
resolveNow(spec);
|
2
|
1232 |
}
|
|
1233 |
}
|
|
1234 |
|
|
1235 |
void commandUnwatch(StringTokenizer t) {
|
|
1236 |
if (!t.hasMoreTokens()) {
|
|
1237 |
MessageOutput.println("Field to unwatch not specified");
|
|
1238 |
return;
|
|
1239 |
}
|
|
1240 |
|
51
|
1241 |
for (WatchpointSpec spec : parseWatchpointSpec(t)) {
|
2
|
1242 |
if (Env.specList.delete(spec)) {
|
|
1243 |
MessageOutput.println("Removed:", spec.toString());
|
|
1244 |
} else {
|
|
1245 |
MessageOutput.println("Not found:", spec.toString());
|
|
1246 |
}
|
|
1247 |
}
|
|
1248 |
}
|
|
1249 |
|
|
1250 |
void turnOnExitTrace(ThreadInfo threadInfo, int suspendPolicy) {
|
|
1251 |
EventRequestManager erm = Env.vm().eventRequestManager();
|
|
1252 |
MethodExitRequest exit = erm.createMethodExitRequest();
|
|
1253 |
if (threadInfo != null) {
|
|
1254 |
exit.addThreadFilter(threadInfo.getThread());
|
|
1255 |
}
|
|
1256 |
Env.addExcludes(exit);
|
|
1257 |
exit.setSuspendPolicy(suspendPolicy);
|
|
1258 |
exit.enable();
|
|
1259 |
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
static String methodTraceCommand = null;
|
|
1263 |
|
|
1264 |
void commandTrace(StringTokenizer t) {
|
|
1265 |
String modif;
|
|
1266 |
int suspendPolicy = EventRequest.SUSPEND_ALL;
|
|
1267 |
ThreadInfo threadInfo = null;
|
|
1268 |
String goStr = " ";
|
|
1269 |
|
|
1270 |
/*
|
|
1271 |
* trace [go] methods [thread]
|
|
1272 |
* trace [go] method exit | exits [thread]
|
|
1273 |
*/
|
|
1274 |
if (t.hasMoreTokens()) {
|
|
1275 |
modif = t.nextToken();
|
|
1276 |
if (modif.equals("go")) {
|
|
1277 |
suspendPolicy = EventRequest.SUSPEND_NONE;
|
|
1278 |
goStr = " go ";
|
|
1279 |
if (t.hasMoreTokens()) {
|
|
1280 |
modif = t.nextToken();
|
|
1281 |
}
|
|
1282 |
} else if (modif.equals("thread")) {
|
|
1283 |
// this is undocumented as it doesn't work right.
|
|
1284 |
suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
|
|
1285 |
if (t.hasMoreTokens()) {
|
|
1286 |
modif = t.nextToken();
|
|
1287 |
}
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
if (modif.equals("method")) {
|
|
1291 |
String traceCmd = null;
|
|
1292 |
|
|
1293 |
if (t.hasMoreTokens()) {
|
|
1294 |
String modif1 = t.nextToken();
|
|
1295 |
if (modif1.equals("exits") || modif1.equals("exit")) {
|
|
1296 |
if (t.hasMoreTokens()) {
|
|
1297 |
threadInfo = doGetThread(t.nextToken());
|
|
1298 |
}
|
|
1299 |
if (modif1.equals("exit")) {
|
|
1300 |
StackFrame frame;
|
|
1301 |
try {
|
|
1302 |
frame = ThreadInfo.getCurrentThreadInfo().getCurrentFrame();
|
|
1303 |
} catch (IncompatibleThreadStateException ee) {
|
|
1304 |
MessageOutput.println("Current thread isnt suspended.");
|
|
1305 |
return;
|
|
1306 |
}
|
|
1307 |
Env.setAtExitMethod(frame.location().method());
|
|
1308 |
traceCmd = MessageOutput.format("trace" +
|
|
1309 |
goStr + "method exit " +
|
|
1310 |
"in effect for",
|
|
1311 |
Env.atExitMethod().toString());
|
|
1312 |
} else {
|
|
1313 |
traceCmd = MessageOutput.format("trace" +
|
|
1314 |
goStr + "method exits " +
|
|
1315 |
"in effect");
|
|
1316 |
}
|
|
1317 |
commandUntrace(new StringTokenizer("methods"));
|
|
1318 |
turnOnExitTrace(threadInfo, suspendPolicy);
|
|
1319 |
methodTraceCommand = traceCmd;
|
|
1320 |
return;
|
|
1321 |
}
|
|
1322 |
} else {
|
|
1323 |
MessageOutput.println("Can only trace");
|
|
1324 |
return;
|
|
1325 |
}
|
|
1326 |
}
|
|
1327 |
if (modif.equals("methods")) {
|
|
1328 |
// Turn on method entry trace
|
|
1329 |
MethodEntryRequest entry;
|
|
1330 |
EventRequestManager erm = Env.vm().eventRequestManager();
|
|
1331 |
if (t.hasMoreTokens()) {
|
|
1332 |
threadInfo = doGetThread(t.nextToken());
|
|
1333 |
}
|
|
1334 |
if (threadInfo != null) {
|
|
1335 |
/*
|
|
1336 |
* To keep things simple we want each 'trace' to cancel
|
|
1337 |
* previous traces. However in this case, we don't do that
|
|
1338 |
* to preserve backward compatibility with pre JDK 6.0.
|
|
1339 |
* IE, you can currently do
|
|
1340 |
* trace methods 0x21
|
|
1341 |
* trace methods 0x22
|
|
1342 |
* and you will get xxx traced just on those two threads
|
|
1343 |
* But this feature is kind of broken because if you then do
|
|
1344 |
* untrace 0x21
|
|
1345 |
* it turns off both traces instead of just the one.
|
|
1346 |
* Another bogosity is that if you do
|
|
1347 |
* trace methods
|
|
1348 |
* trace methods
|
|
1349 |
* and you will get two traces.
|
|
1350 |
*/
|
|
1351 |
|
|
1352 |
entry = erm.createMethodEntryRequest();
|
|
1353 |
entry.addThreadFilter(threadInfo.getThread());
|
|
1354 |
} else {
|
|
1355 |
commandUntrace(new StringTokenizer("methods"));
|
|
1356 |
entry = erm.createMethodEntryRequest();
|
|
1357 |
}
|
|
1358 |
Env.addExcludes(entry);
|
|
1359 |
entry.setSuspendPolicy(suspendPolicy);
|
|
1360 |
entry.enable();
|
|
1361 |
turnOnExitTrace(threadInfo, suspendPolicy);
|
|
1362 |
methodTraceCommand = MessageOutput.format("trace" + goStr +
|
|
1363 |
"methods in effect");
|
|
1364 |
|
|
1365 |
return;
|
|
1366 |
}
|
|
1367 |
|
|
1368 |
MessageOutput.println("Can only trace");
|
|
1369 |
return;
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
// trace all by itself.
|
|
1373 |
if (methodTraceCommand != null) {
|
|
1374 |
MessageOutput.printDirectln(methodTraceCommand);
|
|
1375 |
}
|
|
1376 |
|
|
1377 |
// More trace lines can be added here.
|
|
1378 |
}
|
|
1379 |
|
|
1380 |
void commandUntrace(StringTokenizer t) {
|
|
1381 |
// untrace
|
|
1382 |
// untrace methods
|
|
1383 |
|
|
1384 |
String modif = null;
|
|
1385 |
EventRequestManager erm = Env.vm().eventRequestManager();
|
|
1386 |
if (t.hasMoreTokens()) {
|
|
1387 |
modif = t.nextToken();
|
|
1388 |
}
|
|
1389 |
if (modif == null || modif.equals("methods")) {
|
|
1390 |
erm.deleteEventRequests(erm.methodEntryRequests());
|
|
1391 |
erm.deleteEventRequests(erm.methodExitRequests());
|
|
1392 |
Env.setAtExitMethod(null);
|
|
1393 |
methodTraceCommand = null;
|
|
1394 |
}
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
void commandList(StringTokenizer t) {
|
|
1398 |
StackFrame frame = null;
|
|
1399 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
1400 |
if (threadInfo == null) {
|
|
1401 |
MessageOutput.println("No thread specified.");
|
|
1402 |
return;
|
|
1403 |
}
|
|
1404 |
try {
|
|
1405 |
frame = threadInfo.getCurrentFrame();
|
|
1406 |
} catch (IncompatibleThreadStateException e) {
|
|
1407 |
MessageOutput.println("Current thread isnt suspended.");
|
|
1408 |
return;
|
|
1409 |
}
|
|
1410 |
|
|
1411 |
if (frame == null) {
|
|
1412 |
MessageOutput.println("No frames on the current call stack");
|
|
1413 |
return;
|
|
1414 |
}
|
|
1415 |
|
|
1416 |
Location loc = frame.location();
|
|
1417 |
if (loc.method().isNative()) {
|
|
1418 |
MessageOutput.println("Current method is native");
|
|
1419 |
return;
|
|
1420 |
}
|
|
1421 |
|
|
1422 |
String sourceFileName = null;
|
|
1423 |
try {
|
|
1424 |
sourceFileName = loc.sourceName();
|
|
1425 |
|
|
1426 |
ReferenceType refType = loc.declaringType();
|
|
1427 |
int lineno = loc.lineNumber();
|
|
1428 |
|
|
1429 |
if (t.hasMoreTokens()) {
|
|
1430 |
String id = t.nextToken();
|
|
1431 |
|
|
1432 |
// See if token is a line number.
|
|
1433 |
try {
|
|
1434 |
NumberFormat nf = NumberFormat.getNumberInstance();
|
|
1435 |
nf.setParseIntegerOnly(true);
|
|
1436 |
Number n = nf.parse(id);
|
|
1437 |
lineno = n.intValue();
|
|
1438 |
} catch (java.text.ParseException jtpe) {
|
|
1439 |
// It isn't -- see if it's a method name.
|
51
|
1440 |
List<Method> meths = refType.methodsByName(id);
|
2
|
1441 |
if (meths == null || meths.size() == 0) {
|
|
1442 |
MessageOutput.println("is not a valid line number or method name for",
|
|
1443 |
new Object [] {id, refType.name()});
|
|
1444 |
return;
|
|
1445 |
} else if (meths.size() > 1) {
|
|
1446 |
MessageOutput.println("is an ambiguous method name in",
|
|
1447 |
new Object [] {id, refType.name()});
|
|
1448 |
return;
|
|
1449 |
}
|
51
|
1450 |
loc = meths.get(0).location();
|
2
|
1451 |
lineno = loc.lineNumber();
|
|
1452 |
}
|
|
1453 |
}
|
|
1454 |
int startLine = Math.max(lineno - 4, 1);
|
|
1455 |
int endLine = startLine + 9;
|
|
1456 |
if (lineno < 0) {
|
|
1457 |
MessageOutput.println("Line number information not available for");
|
|
1458 |
} else if (Env.sourceLine(loc, lineno) == null) {
|
|
1459 |
MessageOutput.println("is an invalid line number for",
|
|
1460 |
new Object [] {new Integer (lineno),
|
|
1461 |
refType.name()});
|
|
1462 |
} else {
|
|
1463 |
for (int i = startLine; i <= endLine; i++) {
|
|
1464 |
String sourceLine = Env.sourceLine(loc, i);
|
|
1465 |
if (sourceLine == null) {
|
|
1466 |
break;
|
|
1467 |
}
|
|
1468 |
if (i == lineno) {
|
|
1469 |
MessageOutput.println("source line number current line and line",
|
|
1470 |
new Object [] {new Integer (i),
|
|
1471 |
sourceLine});
|
|
1472 |
} else {
|
|
1473 |
MessageOutput.println("source line number and line",
|
|
1474 |
new Object [] {new Integer (i),
|
|
1475 |
sourceLine});
|
|
1476 |
}
|
|
1477 |
}
|
|
1478 |
}
|
|
1479 |
} catch (AbsentInformationException e) {
|
|
1480 |
MessageOutput.println("No source information available for:", loc.toString());
|
|
1481 |
} catch(FileNotFoundException exc) {
|
|
1482 |
MessageOutput.println("Source file not found:", sourceFileName);
|
|
1483 |
} catch(IOException exc) {
|
|
1484 |
MessageOutput.println("I/O exception occurred:", exc.toString());
|
|
1485 |
}
|
|
1486 |
}
|
|
1487 |
|
|
1488 |
void commandLines(StringTokenizer t) { // Undocumented command: useful for testing
|
|
1489 |
if (!t.hasMoreTokens()) {
|
|
1490 |
MessageOutput.println("Specify class and method");
|
|
1491 |
} else {
|
|
1492 |
String idClass = t.nextToken();
|
|
1493 |
String idMethod = t.hasMoreTokens() ? t.nextToken() : null;
|
|
1494 |
try {
|
|
1495 |
ReferenceType refType = Env.getReferenceTypeFromToken(idClass);
|
|
1496 |
if (refType != null) {
|
51
|
1497 |
List<Location> lines = null;
|
2
|
1498 |
if (idMethod == null) {
|
|
1499 |
lines = refType.allLineLocations();
|
|
1500 |
} else {
|
51
|
1501 |
for (Method method : refType.allMethods()) {
|
2
|
1502 |
if (method.name().equals(idMethod)) {
|
|
1503 |
lines = method.allLineLocations();
|
|
1504 |
}
|
|
1505 |
}
|
|
1506 |
if (lines == null) {
|
|
1507 |
MessageOutput.println("is not a valid method name", idMethod);
|
|
1508 |
}
|
|
1509 |
}
|
51
|
1510 |
for (Location line : lines) {
|
2
|
1511 |
MessageOutput.printDirectln(line.toString());// Special case: use printDirectln()
|
|
1512 |
}
|
|
1513 |
} else {
|
|
1514 |
MessageOutput.println("is not a valid id or class name", idClass);
|
|
1515 |
}
|
|
1516 |
} catch (AbsentInformationException e) {
|
|
1517 |
MessageOutput.println("Line number information not available for", idClass);
|
|
1518 |
}
|
|
1519 |
}
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
void commandClasspath(StringTokenizer t) {
|
|
1523 |
if (Env.vm() instanceof PathSearchingVirtualMachine) {
|
|
1524 |
PathSearchingVirtualMachine vm = (PathSearchingVirtualMachine)Env.vm();
|
|
1525 |
MessageOutput.println("base directory:", vm.baseDirectory());
|
|
1526 |
MessageOutput.println("classpath:", vm.classPath().toString());
|
|
1527 |
MessageOutput.println("bootclasspath:", vm.bootClassPath().toString());
|
|
1528 |
} else {
|
|
1529 |
MessageOutput.println("The VM does not use paths");
|
|
1530 |
}
|
|
1531 |
}
|
|
1532 |
|
|
1533 |
/* Get or set the source file path list. */
|
|
1534 |
void commandUse(StringTokenizer t) {
|
|
1535 |
if (!t.hasMoreTokens()) {
|
|
1536 |
MessageOutput.printDirectln(Env.getSourcePath());// Special case: use printDirectln()
|
|
1537 |
} else {
|
|
1538 |
/*
|
|
1539 |
* Take the remainder of the command line, minus
|
|
1540 |
* leading or trailing whitespace. Embedded
|
|
1541 |
* whitespace is fine.
|
|
1542 |
*/
|
|
1543 |
Env.setSourcePath(t.nextToken("").trim());
|
|
1544 |
}
|
|
1545 |
}
|
|
1546 |
|
|
1547 |
/* Print a stack variable */
|
|
1548 |
private void printVar(LocalVariable var, Value value) {
|
|
1549 |
MessageOutput.println("expr is value",
|
|
1550 |
new Object [] {var.name(),
|
|
1551 |
value == null ? "null" : value.toString()});
|
|
1552 |
}
|
|
1553 |
|
|
1554 |
/* Print all local variables in current stack frame. */
|
|
1555 |
void commandLocals() {
|
|
1556 |
StackFrame frame;
|
|
1557 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
1558 |
if (threadInfo == null) {
|
|
1559 |
MessageOutput.println("No default thread specified:");
|
|
1560 |
return;
|
|
1561 |
}
|
|
1562 |
try {
|
|
1563 |
frame = threadInfo.getCurrentFrame();
|
|
1564 |
if (frame == null) {
|
|
1565 |
throw new AbsentInformationException();
|
|
1566 |
}
|
|
1567 |
List<LocalVariable> vars = frame.visibleVariables();
|
|
1568 |
|
|
1569 |
if (vars.size() == 0) {
|
|
1570 |
MessageOutput.println("No local variables");
|
|
1571 |
return;
|
|
1572 |
}
|
51
|
1573 |
Map<LocalVariable, Value> values = frame.getValues(vars);
|
2
|
1574 |
|
|
1575 |
MessageOutput.println("Method arguments:");
|
51
|
1576 |
for (LocalVariable var : vars) {
|
2
|
1577 |
if (var.isArgument()) {
|
51
|
1578 |
Value val = values.get(var);
|
2
|
1579 |
printVar(var, val);
|
|
1580 |
}
|
|
1581 |
}
|
|
1582 |
MessageOutput.println("Local variables:");
|
51
|
1583 |
for (LocalVariable var : vars) {
|
2
|
1584 |
if (!var.isArgument()) {
|
51
|
1585 |
Value val = values.get(var);
|
2
|
1586 |
printVar(var, val);
|
|
1587 |
}
|
|
1588 |
}
|
|
1589 |
} catch (AbsentInformationException aie) {
|
|
1590 |
MessageOutput.println("Local variable information not available.");
|
|
1591 |
} catch (IncompatibleThreadStateException exc) {
|
|
1592 |
MessageOutput.println("Current thread isnt suspended.");
|
|
1593 |
}
|
|
1594 |
}
|
|
1595 |
|
|
1596 |
private void dump(ObjectReference obj, ReferenceType refType,
|
|
1597 |
ReferenceType refTypeBase) {
|
51
|
1598 |
for (Field field : refType.fields()) {
|
2
|
1599 |
StringBuffer o = new StringBuffer();
|
|
1600 |
o.append(" ");
|
|
1601 |
if (!refType.equals(refTypeBase)) {
|
|
1602 |
o.append(refType.name());
|
|
1603 |
o.append(".");
|
|
1604 |
}
|
|
1605 |
o.append(field.name());
|
|
1606 |
o.append(MessageOutput.format("colon space"));
|
|
1607 |
o.append(obj.getValue(field));
|
|
1608 |
MessageOutput.printDirectln(o.toString()); // Special case: use printDirectln()
|
|
1609 |
}
|
|
1610 |
if (refType instanceof ClassType) {
|
|
1611 |
ClassType sup = ((ClassType)refType).superclass();
|
|
1612 |
if (sup != null) {
|
|
1613 |
dump(obj, sup, refTypeBase);
|
|
1614 |
}
|
|
1615 |
} else if (refType instanceof InterfaceType) {
|
51
|
1616 |
for (InterfaceType sup : ((InterfaceType)refType).superinterfaces()) {
|
|
1617 |
dump(obj, sup, refTypeBase);
|
2
|
1618 |
}
|
|
1619 |
} else {
|
|
1620 |
/* else refType is an instanceof ArrayType */
|
|
1621 |
if (obj instanceof ArrayReference) {
|
51
|
1622 |
for (Iterator<Value> it = ((ArrayReference)obj).getValues().iterator();
|
2
|
1623 |
it.hasNext(); ) {
|
|
1624 |
MessageOutput.printDirect(it.next().toString());// Special case: use printDirect()
|
|
1625 |
if (it.hasNext()) {
|
|
1626 |
MessageOutput.printDirect(", ");// Special case: use printDirect()
|
|
1627 |
}
|
|
1628 |
}
|
|
1629 |
MessageOutput.println();
|
|
1630 |
}
|
|
1631 |
}
|
|
1632 |
}
|
|
1633 |
|
|
1634 |
/* Print a specified reference.
|
|
1635 |
*/
|
|
1636 |
void doPrint(StringTokenizer t, boolean dumpObject) {
|
|
1637 |
if (!t.hasMoreTokens()) {
|
|
1638 |
MessageOutput.println("No objects specified.");
|
|
1639 |
return;
|
|
1640 |
}
|
|
1641 |
|
|
1642 |
while (t.hasMoreTokens()) {
|
|
1643 |
String expr = t.nextToken("");
|
|
1644 |
Value val = evaluate(expr);
|
|
1645 |
if (val == null) {
|
|
1646 |
MessageOutput.println("expr is null", expr.toString());
|
|
1647 |
} else if (dumpObject && (val instanceof ObjectReference) &&
|
|
1648 |
!(val instanceof StringReference)) {
|
|
1649 |
ObjectReference obj = (ObjectReference)val;
|
|
1650 |
ReferenceType refType = obj.referenceType();
|
|
1651 |
MessageOutput.println("expr is value",
|
|
1652 |
new Object [] {expr.toString(),
|
|
1653 |
MessageOutput.format("grouping begin character")});
|
|
1654 |
dump(obj, refType, refType);
|
|
1655 |
MessageOutput.println("grouping end character");
|
|
1656 |
} else {
|
|
1657 |
String strVal = getStringValue();
|
|
1658 |
if (strVal != null) {
|
|
1659 |
MessageOutput.println("expr is value", new Object [] {expr.toString(),
|
|
1660 |
strVal});
|
|
1661 |
}
|
|
1662 |
}
|
|
1663 |
}
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
void commandPrint(final StringTokenizer t, final boolean dumpObject) {
|
|
1667 |
new AsyncExecution() {
|
|
1668 |
void action() {
|
|
1669 |
doPrint(t, dumpObject);
|
|
1670 |
}
|
|
1671 |
};
|
|
1672 |
}
|
|
1673 |
|
|
1674 |
void commandSet(final StringTokenizer t) {
|
|
1675 |
String all = t.nextToken("");
|
|
1676 |
|
|
1677 |
/*
|
|
1678 |
* Bare bones error checking.
|
|
1679 |
*/
|
|
1680 |
if (all.indexOf('=') == -1) {
|
|
1681 |
MessageOutput.println("Invalid assignment syntax");
|
|
1682 |
MessageOutput.printPrompt();
|
|
1683 |
return;
|
|
1684 |
}
|
|
1685 |
|
|
1686 |
/*
|
|
1687 |
* The set command is really just syntactic sugar. Pass it on to the
|
|
1688 |
* print command.
|
|
1689 |
*/
|
|
1690 |
commandPrint(new StringTokenizer(all), false);
|
|
1691 |
}
|
|
1692 |
|
|
1693 |
void doLock(StringTokenizer t) {
|
|
1694 |
if (!t.hasMoreTokens()) {
|
|
1695 |
MessageOutput.println("No object specified.");
|
|
1696 |
return;
|
|
1697 |
}
|
|
1698 |
|
|
1699 |
String expr = t.nextToken("");
|
|
1700 |
Value val = evaluate(expr);
|
|
1701 |
|
|
1702 |
try {
|
|
1703 |
if ((val != null) && (val instanceof ObjectReference)) {
|
|
1704 |
ObjectReference object = (ObjectReference)val;
|
|
1705 |
String strVal = getStringValue();
|
|
1706 |
if (strVal != null) {
|
|
1707 |
MessageOutput.println("Monitor information for expr",
|
|
1708 |
new Object [] {expr.trim(),
|
|
1709 |
strVal});
|
|
1710 |
}
|
|
1711 |
ThreadReference owner = object.owningThread();
|
|
1712 |
if (owner == null) {
|
|
1713 |
MessageOutput.println("Not owned");
|
|
1714 |
} else {
|
|
1715 |
MessageOutput.println("Owned by:",
|
|
1716 |
new Object [] {owner.name(),
|
|
1717 |
new Integer (object.entryCount())});
|
|
1718 |
}
|
51
|
1719 |
List<ThreadReference> waiters = object.waitingThreads();
|
2
|
1720 |
if (waiters.size() == 0) {
|
|
1721 |
MessageOutput.println("No waiters");
|
|
1722 |
} else {
|
51
|
1723 |
for (ThreadReference waiter : waiters) {
|
2
|
1724 |
MessageOutput.println("Waiting thread:", waiter.name());
|
|
1725 |
}
|
|
1726 |
}
|
|
1727 |
} else {
|
|
1728 |
MessageOutput.println("Expression must evaluate to an object");
|
|
1729 |
}
|
|
1730 |
} catch (IncompatibleThreadStateException e) {
|
|
1731 |
MessageOutput.println("Threads must be suspended");
|
|
1732 |
}
|
|
1733 |
}
|
|
1734 |
|
|
1735 |
void commandLock(final StringTokenizer t) {
|
|
1736 |
new AsyncExecution() {
|
|
1737 |
void action() {
|
|
1738 |
doLock(t);
|
|
1739 |
}
|
|
1740 |
};
|
|
1741 |
}
|
|
1742 |
|
|
1743 |
private void printThreadLockInfo(ThreadInfo threadInfo) {
|
|
1744 |
ThreadReference thread = threadInfo.getThread();
|
|
1745 |
try {
|
|
1746 |
MessageOutput.println("Monitor information for thread", thread.name());
|
51
|
1747 |
List<ObjectReference> owned = thread.ownedMonitors();
|
2
|
1748 |
if (owned.size() == 0) {
|
|
1749 |
MessageOutput.println("No monitors owned");
|
|
1750 |
} else {
|
51
|
1751 |
for (ObjectReference monitor : owned) {
|
2
|
1752 |
MessageOutput.println("Owned monitor:", monitor.toString());
|
|
1753 |
}
|
|
1754 |
}
|
|
1755 |
ObjectReference waiting = thread.currentContendedMonitor();
|
|
1756 |
if (waiting == null) {
|
|
1757 |
MessageOutput.println("Not waiting for a monitor");
|
|
1758 |
} else {
|
|
1759 |
MessageOutput.println("Waiting for monitor:", waiting.toString());
|
|
1760 |
}
|
|
1761 |
} catch (IncompatibleThreadStateException e) {
|
|
1762 |
MessageOutput.println("Threads must be suspended");
|
|
1763 |
}
|
|
1764 |
}
|
|
1765 |
|
|
1766 |
void commandThreadlocks(final StringTokenizer t) {
|
|
1767 |
if (!t.hasMoreTokens()) {
|
|
1768 |
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
1769 |
if (threadInfo == null) {
|
|
1770 |
MessageOutput.println("Current thread not set.");
|
|
1771 |
} else {
|
|
1772 |
printThreadLockInfo(threadInfo);
|
|
1773 |
}
|
|
1774 |
return;
|
|
1775 |
}
|
|
1776 |
String token = t.nextToken();
|
|
1777 |
if (token.toLowerCase().equals("all")) {
|
51
|
1778 |
for (ThreadInfo threadInfo : ThreadInfo.threads()) {
|
2
|
1779 |
printThreadLockInfo(threadInfo);
|
|
1780 |
}
|
|
1781 |
} else {
|
|
1782 |
ThreadInfo threadInfo = doGetThread(token);
|
|
1783 |
if (threadInfo != null) {
|
|
1784 |
ThreadInfo.setCurrentThreadInfo(threadInfo);
|
|
1785 |
printThreadLockInfo(threadInfo);
|
|
1786 |
}
|
|
1787 |
}
|
|
1788 |
}
|
|
1789 |
|
|
1790 |
void doDisableGC(StringTokenizer t) {
|
|
1791 |
if (!t.hasMoreTokens()) {
|
|
1792 |
MessageOutput.println("No object specified.");
|
|
1793 |
return;
|
|
1794 |
}
|
|
1795 |
|
|
1796 |
String expr = t.nextToken("");
|
|
1797 |
Value val = evaluate(expr);
|
|
1798 |
if ((val != null) && (val instanceof ObjectReference)) {
|
|
1799 |
ObjectReference object = (ObjectReference)val;
|
|
1800 |
object.disableCollection();
|
|
1801 |
String strVal = getStringValue();
|
|
1802 |
if (strVal != null) {
|
|
1803 |
MessageOutput.println("GC Disabled for", strVal);
|
|
1804 |
}
|
|
1805 |
} else {
|
|
1806 |
MessageOutput.println("Expression must evaluate to an object");
|
|
1807 |
}
|
|
1808 |
}
|
|
1809 |
|
|
1810 |
void commandDisableGC(final StringTokenizer t) {
|
|
1811 |
new AsyncExecution() {
|
|
1812 |
void action() {
|
|
1813 |
doDisableGC(t);
|
|
1814 |
}
|
|
1815 |
};
|
|
1816 |
}
|
|
1817 |
|
|
1818 |
void doEnableGC(StringTokenizer t) {
|
|
1819 |
if (!t.hasMoreTokens()) {
|
|
1820 |
MessageOutput.println("No object specified.");
|
|
1821 |
return;
|
|
1822 |
}
|
|
1823 |
|
|
1824 |
String expr = t.nextToken("");
|
|
1825 |
Value val = evaluate(expr);
|
|
1826 |
if ((val != null) && (val instanceof ObjectReference)) {
|
|
1827 |
ObjectReference object = (ObjectReference)val;
|
|
1828 |
object.enableCollection();
|
|
1829 |
String strVal = getStringValue();
|
|
1830 |
if (strVal != null) {
|
|
1831 |
MessageOutput.println("GC Enabled for", strVal);
|
|
1832 |
}
|
|
1833 |
} else {
|
|
1834 |
MessageOutput.println("Expression must evaluate to an object");
|
|
1835 |
}
|
|
1836 |
}
|
|
1837 |
|
|
1838 |
void commandEnableGC(final StringTokenizer t) {
|
|
1839 |
new AsyncExecution() {
|
|
1840 |
void action() {
|
|
1841 |
doEnableGC(t);
|
|
1842 |
}
|
|
1843 |
};
|
|
1844 |
}
|
|
1845 |
|
|
1846 |
void doSave(StringTokenizer t) {// Undocumented command: useful for testing.
|
|
1847 |
if (!t.hasMoreTokens()) {
|
|
1848 |
MessageOutput.println("No save index specified.");
|
|
1849 |
return;
|
|
1850 |
}
|
|
1851 |
|
|
1852 |
String key = t.nextToken();
|
|
1853 |
|
|
1854 |
if (!t.hasMoreTokens()) {
|
|
1855 |
MessageOutput.println("No expression specified.");
|
|
1856 |
return;
|
|
1857 |
}
|
|
1858 |
String expr = t.nextToken("");
|
|
1859 |
Value val = evaluate(expr);
|
|
1860 |
if (val != null) {
|
|
1861 |
Env.setSavedValue(key, val);
|
|
1862 |
String strVal = getStringValue();
|
|
1863 |
if (strVal != null) {
|
|
1864 |
MessageOutput.println("saved", strVal);
|
|
1865 |
}
|
|
1866 |
} else {
|
|
1867 |
MessageOutput.println("Expression cannot be void");
|
|
1868 |
}
|
|
1869 |
}
|
|
1870 |
|
|
1871 |
void commandSave(final StringTokenizer t) { // Undocumented command: useful for testing.
|
|
1872 |
if (!t.hasMoreTokens()) {
|
51
|
1873 |
Set<String> keys = Env.getSaveKeys();
|
|
1874 |
if (keys.isEmpty()) {
|
2
|
1875 |
MessageOutput.println("No saved values");
|
|
1876 |
return;
|
|
1877 |
}
|
51
|
1878 |
for (String key : keys) {
|
2
|
1879 |
Value value = Env.getSavedValue(key);
|
|
1880 |
if ((value instanceof ObjectReference) &&
|
|
1881 |
((ObjectReference)value).isCollected()) {
|
|
1882 |
MessageOutput.println("expr is value <collected>",
|
|
1883 |
new Object [] {key, value.toString()});
|
|
1884 |
} else {
|
|
1885 |
if (value == null){
|
|
1886 |
MessageOutput.println("expr is null", key);
|
|
1887 |
} else {
|
|
1888 |
MessageOutput.println("expr is value",
|
|
1889 |
new Object [] {key, value.toString()});
|
|
1890 |
}
|
|
1891 |
}
|
|
1892 |
}
|
|
1893 |
} else {
|
|
1894 |
new AsyncExecution() {
|
|
1895 |
void action() {
|
|
1896 |
doSave(t);
|
|
1897 |
}
|
|
1898 |
};
|
|
1899 |
}
|
|
1900 |
|
|
1901 |
}
|
|
1902 |
|
|
1903 |
void commandBytecodes(final StringTokenizer t) { // Undocumented command: useful for testing.
|
|
1904 |
if (!t.hasMoreTokens()) {
|
|
1905 |
MessageOutput.println("No class specified.");
|
|
1906 |
return;
|
|
1907 |
}
|
|
1908 |
String className = t.nextToken();
|
|
1909 |
|
|
1910 |
if (!t.hasMoreTokens()) {
|
|
1911 |
MessageOutput.println("No method specified.");
|
|
1912 |
return;
|
|
1913 |
}
|
|
1914 |
// Overloading is not handled here.
|
|
1915 |
String methodName = t.nextToken();
|
|
1916 |
|
51
|
1917 |
List<ReferenceType> classes = Env.vm().classesByName(className);
|
2
|
1918 |
// TO DO: handle multiple classes found
|
|
1919 |
if (classes.size() == 0) {
|
|
1920 |
if (className.indexOf('.') < 0) {
|
|
1921 |
MessageOutput.println("not found (try the full name)", className);
|
|
1922 |
} else {
|
|
1923 |
MessageOutput.println("not found", className);
|
|
1924 |
}
|
|
1925 |
return;
|
|
1926 |
}
|
|
1927 |
|
51
|
1928 |
ReferenceType rt = classes.get(0);
|
2
|
1929 |
if (!(rt instanceof ClassType)) {
|
|
1930 |
MessageOutput.println("not a class", className);
|
|
1931 |
return;
|
|
1932 |
}
|
|
1933 |
|
|
1934 |
byte[] bytecodes = null;
|
51
|
1935 |
for (Method method : rt.methodsByName(methodName)) {
|
2
|
1936 |
if (!method.isAbstract()) {
|
|
1937 |
bytecodes = method.bytecodes();
|
|
1938 |
break;
|
|
1939 |
}
|
|
1940 |
}
|
|
1941 |
|
|
1942 |
StringBuffer line = new StringBuffer(80);
|
|
1943 |
line.append("0000: ");
|
|
1944 |
for (int i = 0; i < bytecodes.length; i++) {
|
|
1945 |
if ((i > 0) && (i % 16 == 0)) {
|
|
1946 |
MessageOutput.printDirectln(line.toString());// Special case: use printDirectln()
|
|
1947 |
line.setLength(0);
|
|
1948 |
line.append(String.valueOf(i));
|
|
1949 |
line.append(": ");
|
|
1950 |
int len = line.length();
|
|
1951 |
for (int j = 0; j < 6 - len; j++) {
|
|
1952 |
line.insert(0, '0');
|
|
1953 |
}
|
|
1954 |
}
|
|
1955 |
int val = 0xff & bytecodes[i];
|
|
1956 |
String str = Integer.toHexString(val);
|
|
1957 |
if (str.length() == 1) {
|
|
1958 |
line.append('0');
|
|
1959 |
}
|
|
1960 |
line.append(str);
|
|
1961 |
line.append(' ');
|
|
1962 |
}
|
|
1963 |
if (line.length() > 6) {
|
|
1964 |
MessageOutput.printDirectln(line.toString());// Special case: use printDirectln()
|
|
1965 |
}
|
|
1966 |
}
|
|
1967 |
|
|
1968 |
void commandExclude(StringTokenizer t) {
|
|
1969 |
if (!t.hasMoreTokens()) {
|
|
1970 |
MessageOutput.printDirectln(Env.excludesString());// Special case: use printDirectln()
|
|
1971 |
} else {
|
|
1972 |
String rest = t.nextToken("");
|
|
1973 |
if (rest.equals("none")) {
|
|
1974 |
rest = "";
|
|
1975 |
}
|
|
1976 |
Env.setExcludes(rest);
|
|
1977 |
}
|
|
1978 |
}
|
|
1979 |
|
|
1980 |
void commandRedefine(StringTokenizer t) {
|
|
1981 |
if (!t.hasMoreTokens()) {
|
|
1982 |
MessageOutput.println("Specify classes to redefine");
|
|
1983 |
} else {
|
|
1984 |
String className = t.nextToken();
|
51
|
1985 |
List<ReferenceType> classes = Env.vm().classesByName(className);
|
2
|
1986 |
if (classes.size() == 0) {
|
|
1987 |
MessageOutput.println("No class named", className);
|
|
1988 |
return;
|
|
1989 |
}
|
|
1990 |
if (classes.size() > 1) {
|
|
1991 |
MessageOutput.println("More than one class named", className);
|
|
1992 |
return;
|
|
1993 |
}
|
|
1994 |
Env.setSourcePath(Env.getSourcePath());
|
51
|
1995 |
ReferenceType refType = classes.get(0);
|
2
|
1996 |
if (!t.hasMoreTokens()) {
|
|
1997 |
MessageOutput.println("Specify file name for class", className);
|
|
1998 |
return;
|
|
1999 |
}
|
|
2000 |
String fileName = t.nextToken();
|
|
2001 |
File phyl = new File(fileName);
|
|
2002 |
byte[] bytes = new byte[(int)phyl.length()];
|
|
2003 |
try {
|
|
2004 |
InputStream in = new FileInputStream(phyl);
|
|
2005 |
in.read(bytes);
|
|
2006 |
in.close();
|
|
2007 |
} catch (Exception exc) {
|
|
2008 |
MessageOutput.println("Error reading file",
|
|
2009 |
new Object [] {fileName, exc.toString()});
|
|
2010 |
return;
|
|
2011 |
}
|
51
|
2012 |
Map<ReferenceType, byte[]> map
|
|
2013 |
= new HashMap<ReferenceType, byte[]>();
|
2
|
2014 |
map.put(refType, bytes);
|
|
2015 |
try {
|
|
2016 |
Env.vm().redefineClasses(map);
|
|
2017 |
} catch (Throwable exc) {
|
|
2018 |
MessageOutput.println("Error redefining class to file",
|
|
2019 |
new Object [] {className,
|
|
2020 |
fileName,
|
|
2021 |
exc});
|
|
2022 |
}
|
|
2023 |
}
|
|
2024 |
}
|
|
2025 |
|
|
2026 |
void commandPopFrames(StringTokenizer t, boolean reenter) {
|
|
2027 |
ThreadInfo threadInfo;
|
|
2028 |
|
|
2029 |
if (t.hasMoreTokens()) {
|
|
2030 |
String token = t.nextToken();
|
|
2031 |
threadInfo = doGetThread(token);
|
|
2032 |
if (threadInfo == null) {
|
|
2033 |
return;
|
|
2034 |
}
|
|
2035 |
} else {
|
|
2036 |
threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
2037 |
if (threadInfo == null) {
|
|
2038 |
MessageOutput.println("No thread specified.");
|
|
2039 |
return;
|
|
2040 |
}
|
|
2041 |
}
|
|
2042 |
|
|
2043 |
try {
|
|
2044 |
StackFrame frame = threadInfo.getCurrentFrame();
|
|
2045 |
threadInfo.getThread().popFrames(frame);
|
|
2046 |
threadInfo = ThreadInfo.getCurrentThreadInfo();
|
|
2047 |
ThreadInfo.setCurrentThreadInfo(threadInfo);
|
|
2048 |
if (reenter) {
|
|
2049 |
commandStepi();
|
|
2050 |
}
|
|
2051 |
} catch (Throwable exc) {
|
|
2052 |
MessageOutput.println("Error popping frame", exc.toString());
|
|
2053 |
}
|
|
2054 |
}
|
|
2055 |
|
|
2056 |
void commandExtension(StringTokenizer t) {
|
|
2057 |
if (!t.hasMoreTokens()) {
|
|
2058 |
MessageOutput.println("No class specified.");
|
|
2059 |
return;
|
|
2060 |
}
|
|
2061 |
|
|
2062 |
String idClass = t.nextToken();
|
|
2063 |
ReferenceType cls = Env.getReferenceTypeFromToken(idClass);
|
|
2064 |
String extension = null;
|
|
2065 |
if (cls != null) {
|
|
2066 |
try {
|
|
2067 |
extension = cls.sourceDebugExtension();
|
|
2068 |
MessageOutput.println("sourcedebugextension", extension);
|
|
2069 |
} catch (AbsentInformationException e) {
|
|
2070 |
MessageOutput.println("No sourcedebugextension specified");
|
|
2071 |
}
|
|
2072 |
} else {
|
|
2073 |
MessageOutput.println("is not a valid id or class name", idClass);
|
|
2074 |
}
|
|
2075 |
}
|
|
2076 |
|
|
2077 |
void commandVersion(String debuggerName,
|
|
2078 |
VirtualMachineManager vmm) {
|
|
2079 |
MessageOutput.println("minus version",
|
|
2080 |
new Object [] { debuggerName,
|
|
2081 |
new Integer(vmm.majorInterfaceVersion()),
|
|
2082 |
new Integer(vmm.minorInterfaceVersion()),
|
|
2083 |
System.getProperty("java.version")});
|
|
2084 |
if (Env.connection() != null) {
|
|
2085 |
try {
|
|
2086 |
MessageOutput.printDirectln(Env.vm().description());// Special case: use printDirectln()
|
|
2087 |
} catch (VMNotConnectedException e) {
|
|
2088 |
MessageOutput.println("No VM connected");
|
|
2089 |
}
|
|
2090 |
}
|
|
2091 |
}
|
|
2092 |
}
|