📄 tty.java
字号:
/* * @(#)TTY.java 1.54 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */package com.sun.tools.example.debug.tty;import com.sun.jdi.*;import com.sun.jdi.event.*;import com.sun.jdi.connect.*;import java.util.*;import java.io.*;public class TTY implements EventNotifier { EventHandler handler = null; /** * List of Strings to execute at each stop. */ private List monitorCommands = new ArrayList(); private int monitorCount = 0; /** * The name of this tool. */ private static final String progname = "jdb"; /** * The version date of this tool. Formats to: * April 19, 2002 7:42:13 PM PDT (when locale=en_US.ISO8859-1) */ private static final long version = 1019270533724L; public void vmStartEvent(VMStartEvent se) { Thread.yield(); // fetch output MessageOutput.lnprint("VM Started:"); } public void vmDeathEvent(VMDeathEvent e) { } public void vmDisconnectEvent(VMDisconnectEvent e) { } public void threadStartEvent(ThreadStartEvent e) { } public void threadDeathEvent(ThreadDeathEvent e) { } public void classPrepareEvent(ClassPrepareEvent e) { } public void classUnloadEvent(ClassUnloadEvent e) { } public void breakpointEvent(BreakpointEvent be) { Thread.yield(); // fetch output MessageOutput.lnprint("Breakpoint hit:"); } public void fieldWatchEvent(WatchpointEvent fwe) { Field field = fwe.field(); ObjectReference obj = fwe.object(); Thread.yield(); // fetch output if (fwe instanceof ModificationWatchpointEvent) { MessageOutput.lnprint("Field access encountered before after", new Object [] {field, fwe.valueCurrent(), ((ModificationWatchpointEvent)fwe).valueToBe()}); } else { MessageOutput.lnprint("Field access encountered", field.toString()); } } public void stepEvent(StepEvent se) { Thread.yield(); // fetch output MessageOutput.lnprint("Step completed:"); } public void exceptionEvent(ExceptionEvent ee) { Thread.yield(); // fetch output Location catchLocation = ee.catchLocation(); if (catchLocation == null) { MessageOutput.lnprint("Exception occurred uncaught", ee.exception().referenceType().name()); } else { MessageOutput.lnprint("Exception occurred caught", new Object [] {ee.exception().referenceType().name(), Commands.locationString(catchLocation)}); } } public void methodEntryEvent(MethodEntryEvent me) { Thread.yield(); // fetch output /* * These can be very numerous, so be as efficient as possible. */ MessageOutput.lnprint("Method entered:", new Object [] {me.method().declaringType().name(), me.method().name()}); } public void methodExitEvent(MethodExitEvent me) { Thread.yield(); // fetch output /* * These can be very numerous, so be as efficient as possible. */ MessageOutput.lnprint("Method exited:", new Object [] {me.method().declaringType().name(), me.method().name()}); } public void vmInterrupted() { Thread.yield(); // fetch output printCurrentLocation(); Iterator it = monitorCommands.iterator(); while (it.hasNext()) { StringTokenizer t = new StringTokenizer((String)it.next()); t.nextToken(); // get rid of monitor number executeCommand(t); } MessageOutput.printPrompt(); } public void receivedEvent(Event event) { } private void printCurrentLocation() { ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); StackFrame frame; try { frame = threadInfo.getCurrentFrame(); } catch (IncompatibleThreadStateException exc) { MessageOutput.println("<location unavailable>"); return; } if (frame == null) { MessageOutput.println("No frames on the current call stack"); } else { Location loc = frame.location(); MessageOutput.println("location", new Object [] {threadInfo.getThread().name(), Commands.locationString(loc)}); // Output the current source line, if possible if (loc.lineNumber() != -1) { String line; try { line = Env.sourceLine(loc, loc.lineNumber()); } catch (java.io.IOException e) { line = null; } if (line != null) { MessageOutput.println("source line number and line", new Object [] {new Integer(loc.lineNumber()), line}); } } } MessageOutput.println(); } void help() { MessageOutput.println("zz help text"); } /* * These commands do not require a connected VM */ private String[] disconnectCmds = { "run", "catch", "ignore", "stop", "clear", "watch", "unwatch", "use", "sourcepath", "quit", "exit", "help", "?", "read", "version", "exclude" }; private boolean isDisconnectCmd(String cmd) { for (int i = 0; i < disconnectCmds.length; i++) { if (disconnectCmds[i].equals(cmd)) { return true; } } return false; } void executeCommand(StringTokenizer t) { String cmd = t.nextToken().toLowerCase(); Commands evaluator = new Commands(); // Normally, prompt for the next command after this one is done boolean showPrompt = true; /* * Do this check ahead of time so that it precedes any syntax * checking in the command itself. If the command is not * properly classified by isDisconnectCmd, the exception catch * below will still protect us. */ if (!Env.connection().isOpen() && !isDisconnectCmd(cmd)) { MessageOutput.println("Command not valid until the VM is started with the run command", cmd); } else { try { if (cmd.equals("print")) { evaluator.commandPrint(t, false); showPrompt = false; // asynchronous command } else if (cmd.equals("eval")) { evaluator.commandPrint(t, false); showPrompt = false; // asynchronous command } else if (cmd.equals("set")) { evaluator.commandSet(t); showPrompt = false; // asynchronous command } else if (cmd.equals("dump")) { evaluator.commandPrint(t, true); showPrompt = false; // asynchronous command } else if (cmd.equals("locals")) { evaluator.commandLocals(); } else if (cmd.equals("classes")) { evaluator.commandClasses(); } else if (cmd.equals("class")) { evaluator.commandClass(t); } else if (cmd.equals("methods")) { evaluator.commandMethods(t); } else if (cmd.equals("fields")) { evaluator.commandFields(t); } else if (cmd.equals("threads")) { evaluator.commandThreads(t); } else if (cmd.equals("thread")) { evaluator.commandThread(t); } else if (cmd.equals("suspend")) { evaluator.commandSuspend(t); } else if (cmd.equals("resume")) { evaluator.commandResume(t); } else if (cmd.equals("cont")) { evaluator.commandCont(); } else if (cmd.equals("threadgroups")) { evaluator.commandThreadGroups(); } else if (cmd.equals("threadgroup")) { evaluator.commandThreadGroup(t); } else if (cmd.equals("catch")) { evaluator.commandCatchException(t); } else if (cmd.equals("ignore")) { evaluator.commandIgnoreException(t); } else if (cmd.equals("step")) { evaluator.commandStep(t); } else if (cmd.equals("stepi")) { evaluator.commandStepi(); } else if (cmd.equals("next")) { evaluator.commandNext(); } else if (cmd.equals("kill")) { evaluator.commandKill(t); } else if (cmd.equals("interrupt")) { evaluator.commandInterrupt(t); } else if (cmd.equals("trace")) { evaluator.commandTrace(t); } else if (cmd.equals("untrace")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -