CommandInterpreter.java revision 0
0N/A * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * The numbering of threads is relative to the current set of threads, 0N/A * and may be affected by the creation and termination of new threads. 0N/A * Commands issued using such thread ids will only give reliable behavior 0N/A * relative to what was shown earlier in 'list' commands if the VM is interrupted. 0N/A * We need a better scheme. 0N/A //env.failure("No thread for id \"" + idToken + "\""); 0N/A //### Why not use runtime.allThreads().iterator() ? 0N/A //out.println("** classes list **"); 0N/A //### Should validate class name syntax. 0N/A //### Should handle multiple results sensibly. 0N/A //### Issue: Uniqueness of thread group names is not enforced. 0N/A for (
int j =
0; j <
79; j++) {
0N/A // Right-justify the thread number at start of output string 0N/A // Command: threadgroups 0N/A //### Should notify user. 0N/A // Command: threadgroup 0N/A //### Should notify user. 0N/A // Run from prevously-set class name. 0N/A env.
failure(
"No main class specifed and no current default defined.");
0N/A // Allow VM arguments to be specified here? 0N/A //context.setVmArguments(vmArgs); 0N/A // Command: interrupt 0N/A // Suspend all threads in the current thread group. 0N/A //### Issue: help message says default is all threads. 0N/A //### Behavior here agrees with 'jdb', however. 0N/A // TODO - don't suspend debugger threads 0N/A // Suspend all threads in the current thread group. 0N/A //### Issue: help message says default is all threads. 0N/A //### Behavior here agrees with 'jdb', however. 0N/A // TODO - don't suspend debugger threads 0N/A "Try \"stepi\" to step by instructions.");
0N/A "Try \"nexti\" to step by instructions.");
0N/A // Command: nexti (NEW) 0N/A //### Should change the way in which thread ids and threadgroup names 0N/A //### are distinguished. 0N/A env.
error(
"Usage: kill <threadgroup name> or <thread id>");
0N/A /* Check for threadgroup name, NOT skipping "system". */ 0N/A //### Should skip "system"? Classic 'jdb' does this. 0N/A //### Should deal with possible non-uniqueness of threadgroup names. 0N/A "\" is not a valid threadgroup or id.");
0N/A private void commandCatchException(StringTokenizer t) throws NoSessionException {} 0N/A private void commandIgnoreException(StringTokenizer t) throws NoSessionException {} 0N/A //### Print current frame after command? 0N/A //### Should we insist that VM be interrupted here? 0N/A //### There is an inconsistency between the 'where' command 0N/A //### and 'up' and 'down' in this respect. 0N/A //### Do we want to set current thread here? 0N/A //### Should notify user of change. 0N/A //### Check for these. 0N/A //env.failure("Thread no longer exists."); 0N/A //env.failure("Target VM must be in interrupted state."); 0N/A //env.failure("Current thread isn't suspended."); 0N/A //### Should handle extremely long stack traces sensibly for user. 0N/A //### Previously mishandled cases where thread was not current. 0N/A //### Now, prints all of the stack regardless of current frame. 0N/A //int frameIndex = context.getCurrentFrameIndex(); 0N/A // Print set breakpoints 0N/A // We can't use hasMoreTokens here because it will cause any leading 0N/A // paren to be lost. 0N/A // Try stripping method from class.method token. 0N/A if ( (
idot <=
0) ||
/* No dot or dot in first char */ 0N/A //### Should throw exception with error message 0N/A //out.println("Invalid method specification: " 0N/A // + methodName + rest); 0N/A //### What about spaces in arglist? 0N/A// } catch (Exception e) { 0N/A// env.error("Exception attempting to create breakpoint: " + e); 0N/A // Ignore optional "at" or "in" token. 0N/A // Allowed for backward compatibility. 0N/A //### Add sanity-checks for deferred breakpoint. 0N/A // Print set breakpoints 0N/A //### need 'clear all' 0N/A // The request used for matching should be found 0N/A // See if token is a line number. 0N/A // It isn't -- see if it's a method name. 0N/A " is not a valid line number or " +
0N/A "method name for class " +
0N/A " is an ambiguous method name in" +
0N/A " is an invalid line number for " +
0N/A // Get or set the source file path list. 0N/A //### Should throw exception for invalid path. 0N/A //### E.g., vetoable property change. 0N/A // Command: sourcepath 0N/A // Get or set the source file path list. (Alternate to 'use'.) 0N/A //### Should throw exception for invalid path. 0N/A //### E.g., vetoable property change. 0N/A // Command: classpath 0N/A // Get or set the class file path list. 0N/A //### Should throw exception for invalid path. 0N/A //### E.g., vetoable property change. 0N/A // Display source for source file or class. 0N/A //### JDI crashes taking line number for class. 0N/A ReferenceType cls = findClass(name); 0N/A env.viewLocation(cls.location()); 0N/A env.failure("No such class"); 0N/A // Print all local variables in current stack frame. 0N/A "use the \"thread\" command first.");
0N/A " Compile with -g to generate variable information");
0N/A * Monitor an expression 0N/A * Command: unmonitor 0N/A * Unmonitor an expression 0N/A // Print a stack variable. 0N/A // Evaluate an expression. 0N/A //### Probably confused if expresion contains whitespace. 0N/A "use the \"thread\" command first.");
0N/A return;
// Error message already printed 0N/A * Display help message. 0N/A out.
println(
"suspend [thread id(s)] -- suspend threads (default: all)");
0N/A out.
println(
"resume [thread id(s)] -- resume threads (default: all)");
0N/A out.
println(
"wherei [thread id] | all -- dump a thread's stack, with pc info");
0N/A// out.println("print <expression> -- print value of expression"); 0N/A out.
println(
"dump <expression> -- print all object information\n");
0N/A// out.println("eval <expression> -- evaluate expression (same as print)"); 0N/A out.
println(
"locals -- print all local variables in current stack frame\n");
0N/A out.
println(
"stop [in] <class id>.<method>[(argument_type,...)] -- set a breakpoint in a method");
0N/A out.
println(
"stop [at] <class id>:<line> -- set a breakpoint at a line");
0N/A out.
println(
"clear <class id>.<method>[(argument_type,...)] -- clear a breakpoint in a method");
0N/A out.
println(
"clear <class id>:<line> -- clear a breakpoint at a line");
0N/A out.
println(
"step up -- execute until the current method returns to its caller");
0N/A// out.println("catch <class id> -- break for the specified exception"); 0N/A// out.println("ignore <class id> -- ignore when the specified exception\n"); 0N/A out.
println(
"list [line number|method] -- print source code context at line or method");
0N/A out.
println(
"use <source file path> -- display or change the source path\n");
0N/A out.
println(
"sourcepath <source file path> -- display or change the source path\n");
0N/A out.
println(
"classpath <class file path> -- display or change the class path\n");
0N/A out.
println(
"monitor <expression> -- evaluate an expression each time the program stops\n");
0N/A out.
println(
"read <filename> -- read and execute a command file\n");
0N/A// out.println("memory -- report memory usage"); 0N/A// out.println("gc -- free unused objects\n"); 0N/A out.
println(
"run <class> [args] -- start execution of a Java class");
0N/A out.
println(
"load <class> [args] -- start execution of a Java class, initially suspended");
0N/A out.
println(
"load -- re-execute last class run, initially suspended");
0N/A out.
println(
"kill <thread(group)> -- kill a thread or threadgroup\n");
0N/A * Execute a command. 0N/A //### Treatment of 'out' here is dirty... 0N/A//### Not implemented. 0N/A// } else if (cmd.equals("catch")) { 0N/A// commandCatchException(t); 0N/A//### Not implemented. 0N/A// } else if (cmd.equals("ignore")) { 0N/A// commandIgnoreException(t); 0N/A// } else if (cmd.equals("read")) { 0N/A //### Dubious repeat-count feature inherited from 'jdb'