001: /*
002: * JdbCommands.java
003: *
004: * Copyright (C) 2002-2003 Peter Graves
005: * $Id: JdbCommands.java,v 1.9 2003/05/19 02:04:28 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.jdb;
023:
024: import com.sun.jdi.Bootstrap;
025: import org.armedbear.j.Help;
026: import org.armedbear.j.JavaMode;
027: import org.armedbear.j.Log;
028: import org.armedbear.j.MessageDialog;
029:
030: public final class JdbCommands implements JdbConstants {
031: public static int findCommand(String cmd) {
032: // Single-letter abbreviations for the most common commands.
033: if (cmd.equals("b"))
034: return JDB_BREAK;
035: if (cmd.equals("c"))
036: return JDB_CONTINUE;
037: if (cmd.equals("f"))
038: return JDB_FINISH;
039: if (cmd.equals("n"))
040: return JDB_NEXT;
041: if (cmd.equals("q"))
042: return JDB_QUIT;
043: if (cmd.equals("s"))
044: return JDB_STEP;
045: if (cmd.equals("p"))
046: return JDB_PRINT;
047:
048: if ("break".startsWith(cmd))
049: return JDB_BREAK;
050: if (cmd.startsWith("ca"))
051: if ("catch".startsWith(cmd))
052: return JDB_CATCH;
053: if (cmd.startsWith("co"))
054: if ("continue".startsWith(cmd))
055: return JDB_CONTINUE;
056: if (cmd.startsWith("cl"))
057: if ("clear".startsWith(cmd))
058: return JDB_CLEAR;
059: if ("finish".startsWith(cmd))
060: return JDB_FINISH;
061: if ("go".startsWith(cmd))
062: return JDB_CONTINUE;
063: if ("locals".startsWith(cmd))
064: return JDB_LOCALS;
065: if ("next".startsWith(cmd))
066: return JDB_NEXT;
067: if ("print".startsWith(cmd))
068: return JDB_PRINT;
069: if ("quit".startsWith(cmd))
070: return JDB_QUIT;
071: if (cmd.startsWith("rest"))
072: if ("restart".startsWith(cmd))
073: return JDB_RESTART;
074: if (cmd.startsWith("resu"))
075: if ("resume".startsWith(cmd))
076: return JDB_CONTINUE;
077: if (cmd.startsWith("std"))
078: if ("stdin".startsWith(cmd))
079: return JDB_STDIN;
080: if (cmd.startsWith("ste"))
081: if ("step".startsWith(cmd))
082: return JDB_STEP;
083: if (cmd.startsWith("sto"))
084: if ("stop".startsWith(cmd))
085: return JDB_BREAK;
086: if (cmd.startsWith("su"))
087: if ("suspend".startsWith(cmd))
088: return JDB_SUSPEND;
089: if ("tbreak".startsWith(cmd))
090: return JDB_TBREAK;
091:
092: return -1;
093: }
094:
095: public static void jdb() {
096: if (JavaMode.getJdb() == null) {
097: try {
098: Bootstrap.virtualMachineManager();
099: } catch (NoClassDefFoundError e) {
100: Log.error("unable to load com.sun.jdi.Bootstrap");
101: String classpath = System
102: .getProperty("java.class.path");
103: Log.error("classpath = " + classpath);
104: Help.help("jdb.html");
105: MessageDialog
106: .showMessageDialog(
107: "Unable to find tools.jar. "
108: + "See doc/jdb.html for installation instructions.",
109: "Jdb");
110: return;
111: }
112: }
113: Jdb.jdb();
114: }
115:
116: public static void jdb(String s) {
117: if (JavaMode.getJdb() != null)
118: command(s);
119: else
120: MessageDialog.showMessageDialog(
121: "The debugger is not running.", "Error");
122: }
123:
124: public static void jdbContinue() {
125: command("continue");
126: }
127:
128: public static void jdbFinish() {
129: command("finish");
130: }
131:
132: public static void jdbLocals() {
133: command("locals");
134: }
135:
136: public static void jdbNext() {
137: command("next");
138: }
139:
140: public static void jdbQuit() {
141: command("quit");
142: }
143:
144: public static void jdbRestart() {
145: command("restart");
146: }
147:
148: public static void jdbStep() {
149: command("step");
150: }
151:
152: public static void jdbSuspend() {
153: command("suspend");
154: }
155:
156: public static void command(String s) {
157: Jdb jdb = Jdb.findJdb();
158: if (jdb != null)
159: jdb.doCommand(s);
160: }
161: }
|