📄 tty.java
字号:
return "\"" + idToken +
"\" is not a valid decimal number.";
} catch (ArrayIndexOutOfBoundsException e) {
return idToken + " is out of bounds for " +
obj.description();
}
if (rv != null && rv.isObject()) {
obj = rv;
rv = noValue;
}
if (pieces.hasMoreTokens() == false ||
(idToken = pieces.nextToken()).equals("]") == false) {
return "\"" + expr +
"\" is not a valid expression.";
}
idToken = pieces.hasMoreTokens() ?
pieces.nextToken(printDelimiters) : null;
} else if (idToken.equals("(")) {
return "print <method> not supported yet.";
} else {
/* Should never get here. */
return "invalid expression";
}
}
out.print(expr + " = ");
if (rv != noValue) {
out.println((rv == null) ? "null" : rv.description());
} else if (dumpObject && obj instanceof RemoteObject) {
out.println(obj.description() + " {");
if (obj instanceof RemoteClass) {
RemoteClass cls = (RemoteClass)obj;
out.print(" superclass = ");
RemoteClass superClass = cls.getSuperclass();
out.println((superClass == null) ?
"null" : superClass.description());
out.print(" loader = ");
RemoteObject loader = cls.getClassLoader();
out.println((loader == null) ?
"null" : loader.description());
RemoteClass interfaces[] = cls.getInterfaces();
if (interfaces != null && interfaces.length > 0) {
out.println(" interfaces:");
for (int i = 0; i < interfaces.length; i++) {
out.println(" " + interfaces[i]);
}
}
}
RemoteField fields[] = ((RemoteObject)obj).getFields();
if (obj instanceof RemoteClass && fields.length > 0) {
out.println();
}
for (int i = 0; i < fields.length; i++) {
String name = fields[i].getTypedName();
String modifiers = fields[i].getModifiers();
out.print(" " + modifiers + name + " = ");
RemoteValue v = ((RemoteObject)obj).getFieldValue(i);
out.println((v == null) ? "null" : v.description());
}
out.println("}");
} else {
out.println(obj.toString());
}
return null;
}
void help() {
out.println("** command list **");
out.println("threads [threadgroup] -- list threads");
out.println("thread <thread id> -- set default thread");
out.println("suspend [thread id(s)] -- suspend threads (default: all)");
out.println("resume [thread id(s)] -- resume threads (default: all)");
out.println("where [thread id] | all -- dump a thread's stack");
out.println("wherei [thread id] | all -- dump a thread's stack, with pc info");
out.println("threadgroups -- list threadgroups");
out.println("threadgroup <name> -- set current threadgroup\n");
out.println("print <id> [id(s)] -- print object or field");
out.println("dump <id> [id(s)] -- print all object information\n");
out.println("locals -- print all local variables in current stack frame\n");
out.println("classes -- list currently known classes");
out.println("methods <class id> -- list a class's methods\n");
out.println("stop in <class id>.<method> -- set a breakpoint in a method");
out.println("stop at <class id>:<line> -- set a breakpoint at a line");
out.println("up [n frames] -- move up a thread's stack");
out.println("down [n frames] -- move down a thread's stack");
out.println("clear <class id>:<line> -- clear a breakpoint");
out.println("step -- execute current line");
out.println("step up -- execute until the current method returns to its caller"); // SAS GVH step out
out.println("stepi -- execute current instruction");
out.println("next -- step one line (step OVER calls)");
out.println("cont -- continue execution from breakpoint\n");
out.println("catch <class id> -- break for the specified exception");
out.println("ignore <class id> -- ignore when the specified exception\n");
out.println("list [line number|method] -- print source code");
out.println("use [source file path] -- display or change the source path\n");
out.println("memory -- report memory usage");
out.println("gc -- free unused objects\n");
out.println("load classname -- load Java class to be debugged");
out.println("run <class> [args] -- start execution of a loaded Java class");
// out.println("kill <thread(group)> -- kill a thread or threadgroup\n");
out.println("!! -- repeat last command");
out.println("help (or ?) -- list commands");
out.println("exit (or quit) -- exit debugger");
}
void executeCommand(StringTokenizer t) {
String cmd = t.nextToken().toLowerCase();
try {
if (cmd.equals("print")) {
print(t, false);
} else if (cmd.equals("dump")) {
print(t, true);
} else if (cmd.equals("locals")) {
locals();
} else if (cmd.equals("classes")) {
classes();
} else if (cmd.equals("methods")) {
methods(t);
} else if (cmd.equals("threads")) {
threads(t);
} else if (cmd.equals("thread")) {
thread(t);
} else if (cmd.equals("suspend")) {
suspend(t);
} else if (cmd.equals("resume")) {
resume(t);
} else if (cmd.equals("threadgroups")) {
threadGroups();
} else if (cmd.equals("threadgroup")) {
threadGroup(t);
} else if (cmd.equals("catch")) {
catchException(t);
} else if (cmd.equals("ignore")) {
ignoreException(t);
} else if (cmd.equals("cont")) {
cont();
} else if (cmd.equals("step")) {
step(t);
} else if (cmd.equals("stepi")) {
stepi();
} else if (cmd.equals("next")) {
next();
} else if (cmd.equals("kill")) {
kill(t);
} else if (cmd.equals("where")) {
where(t, false);
} else if (cmd.equals("wherei")) {
where(t, true);
} else if (cmd.equals("up")) {
up(t);
} else if (cmd.equals("down")) {
down(t);
} else if (cmd.equals("load")) {
load(t);
} else if (cmd.equals("run")) {
run(t);
} else if (cmd.equals("memory")) {
memory();
} else if (cmd.equals("gc")) {
gc();
// This cannot reasonably work
// } else if (cmd.equals("trace") || cmd.equals("itrace")) {
// trace(cmd, t);
} else if (cmd.equals("stop")) {
stop(t);
} else if (cmd.equals("clear")) {
clear(t);
} else if (cmd.equals("list")) {
list(t);
} else if (cmd.equals("use")) {
use(t);
} else if (cmd.equals("help") || cmd.equals("?")) {
help();
} else if (cmd.equals("quit") || cmd.equals("exit")) {
resume(t); // ibm.6281
debugger.close();
System.exit(0);
} else {
out.println("huh? Try help...");
}
} catch (Exception e) {
out.println("Internal exception:");
out.flush();
e.printStackTrace();
}
}
void readCommandFile(File f) {
try {
if (f.canRead()) {
// Process initial commands.
DataInputStream inFile =
new DataInputStream(new FileInputStream(f));
String ln;
while ((ln = inFile.readLine()) != null) {
StringTokenizer t = new StringTokenizer(ln);
if (t.hasMoreTokens()) {
executeCommand(t);
}
}
}
} catch (IOException e) {}
}
public TTY(String host, String password, String javaArgs, String args,
PrintStream outStream, PrintStream consoleStream,
boolean verbose) throws Exception {
System.out.println("Initializing " + progname + "...");
out = outStream;
console = consoleStream;
if (password == null) {
debugger = new RemoteDebugger(javaArgs, this, verbose);
} else {
debugger = new RemoteDebugger(host, password, this, verbose);
}
DataInputStream in = new DataInputStream(System.in);
String lastLine = null;
if (args != null && args.length() > 0) {
StringTokenizer t = new StringTokenizer(args);
load(t);
lastArgs = args;
}
Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
// Try reading user's startup file.
File f = new File(System.getProperty("user.home") +
System.getProperty("file.separator") + "jdb.ini");
if (!f.canRead()) {
// Try opening $HOME/jdb.ini
f = new File(System.getProperty("user.home") +
System.getProperty("file.separator") + ".jdbrc");
}
readCommandFile(f);
// Try opening local jdb.ini
f = new File(System.getProperty("user.dir") +
System.getProperty("file.separator") + "startup.jdb");
readCommandFile(f);
// Process interactive commands.
while (true) {
printPrompt();
String ln = in.readLine();
if (ln == null) {
out.println("Input stream closed.");
return;
}
if (ln.startsWith("!!") && lastLine != null) {
ln = lastLine + ln.substring(2);
out.println(ln);
}
StringTokenizer t = new StringTokenizer(ln);
if (t.hasMoreTokens()) {
lastLine = ln;
executeCommand(t);
}
}
}
private static void usage() {
System.out.println("Usage: " + progname + " <options> <classes>");
System.out.println();
System.out.println("where options include:");
System.out.println(" -help print out this message and exit");
System.out.println(" -version print out the build version and exit");
System.out.println(" -host <hostname> host machine of interpreter to attach to");
System.out.println(" -password <psswd> password of interpreter to attach to (from -debug)");
System.out.println("options forwarded to debuggee process:");
System.out.println(" -v -verbose turn on verbose mode");
System.out.println(" -debug enable remote JAVA debugging");
System.out.println(" -noasyncgc don't allow asynchronous garbage collection");
System.out.println(" -verbosegc print a message when garbage collection occurs");
System.out.println(" -noclassgc disable class garbage collection");
System.out.println(" -cs -checksource check if source is newer when loading classes");
System.out.println(" -ss<number> set the maximum native stack size for any thread");
System.out.println(" -oss<number> set the maximum Java stack size for any thread");
System.out.println(" -ms<number> set the initial Java heap size");
System.out.println(" -mx<number> set the maximum Java heap size");
System.out.println(" -D<name>=<value> set a system property");
System.out.println(" -classpath <directories separated by colons>");
System.out.println(" list directories in which to look for classes");
System.out.println(" -prof[:<file>] output profiling data to ./java.prof or ./<file>");
System.out.println(" -verify verify all classes when read in");
System.out.println(" -verifyremote verify classes read in over the network [default]");
System.out.println(" -noverify do not verify any class");
System.out.println(" -dbgtrace print info for debugging " + progname);
System.out.println();
System.out.println("For command help type 'help' at " + progname + " prompt");
}
public static void main(String argv[]) {
// Get host attribute, if any.
String localhost;
try {
localhost = InetAddress.getLocalHost().getHostName();
} catch (Exception ex) {
localhost = null;
}
if (localhost == null) {
localhost = "localhost";
}
String host = null;
String password = null;
String cmdLine = "";
String javaArgs = "";
boolean verbose = false;
for (int i = 0; i < argv.length; i++) {
String token = argv[i];
if (token.equals("-dbgtrace")) {
verbose = true;
} else if (token.equals("-cs") || token.equals("-checksource") ||
token.equals("-noasyncgc") || token.equals("-prof") ||
token.equals("-v") || token.equals("-verbose") ||
token.equals("-verify") || token.equals("-noverify") ||
token.equals("-verifyremote") ||
token.equals("-verbosegc") ||
token.startsWith("-ms") || token.startsWith("-mx") ||
token.startsWith("-ss") || token.startsWith("-oss") ||
token.startsWith("-D")) {
javaArgs += token + " ";
} else if (token.equals("-classpath")) {
if (i == (argv.length - 1)) {
System.out.println("No classpath specified.");
usage();
System.exit(1);
}
javaArgs += token + " " + argv[++i] + " ";
} else if (token.equals("-host")) {
if (i == (argv.length - 1)) {
System.out.println("No host specified.");
usage();
System.exit(1);
}
host = argv[++i];
} else if (token.equals("-password")) {
if (i == (argv.length - 1)) {
System.out.println("No password specified.");
usage();
System.exit(1);
}
password = argv[++i];
} else if (token.equals("-help")) {
usage();
System.exit(0);
} else if (token.equals("-version")) {
System.out.println(progname + " version " + version);
System.exit(0);
} else if (token.startsWith("-")) {
System.out.println("invalid option: " + token);
usage();
System.exit(1);
} else {
// Everything from here is part of the command line
cmdLine = token + " ";
for (i++; i < argv.length; i++) {
cmdLine += argv[i] + " ";
}
break;
}
}
if (host != null && password == null) {
System.out.println("A debug password must be specified for " +
"remote debugging.");
System.exit(1);
}
if (host == null) {
host = localhost;
}
try {
if (!host.equals(localhost) && password.length() == 0) {
System.out.println(
"No password supplied for accessing remote " +
"Java interpreter.");
System.out.println(
"The password is reported by the remote interpreter" +
"when it is started.");
System.exit(1);
}
new TTY(host, password, javaArgs, cmdLine,
System.out, System.out, verbose);
} catch(SocketException se) {
System.out.println("Failed accessing debugging session on " +
host + ": invalid password.");
} catch(NumberFormatException ne) {
System.out.println("Failed accessing debugging session on " +
host + ": invalid password.");
} catch(Exception e) {
System.out.print("Internal exception: ");
System.out.flush();
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -