Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / JDEbug.java
1 package jde.debugger;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.util.List;
7
8 import jde.debugger.command.CommandHandler;
9 import jde.debugger.command.DebugCommand;
10 import jde.debugger.command.DebugCommandFactory;
11
12 /**
13  * Class of JDEbug debuggers.
14  * <p>
15  * This class defines methods for communicating with the JDE. It
16  * maintains a list of active applications. It passes application
17  * commands to the apps specified by the commands.
18  * <p>
19  * See {@link Protocol Protocol class} for command/response formats and
20  * {@link EventHandler EventHandler} for event set formats.
21  * <p>
22  * JDEbug responds to every command with either a result or error
23  * message.
24  * <p>
25  *
26  * @author Amit Kumar
27  * @since 0.1
28  * @author Paul Kinnucan
29  * @since 1.3
30  * @version $Revision: 1.13 $
31  */
32 public class JDEbug extends Thread implements Protocol {
33
34   /**
35    * The ID of jdebug. This is used by jde when issuing commands that
36    * are not specific to any particular vm, for instance, 'quit', or
37    * the command used to launch new application/vms.<br>
38    * It is the Integer -1.
39    */
40   public static final Integer debuggerID = new Integer(-1);
41
42   public static JDEbug theDebugger = new JDEbug();
43
44   private boolean       m_shutdown = false;
45   private CommandStream m_commandStream;
46
47   /**
48    * Protected constructor, since this is a singleton class.
49    */
50   protected JDEbug() {
51   }
52
53   public void init() throws IOException {
54     // The debugger uses standard in to read commands from Emacs.
55     m_commandStream = new CommandStream(new BufferedReader(new InputStreamReader(System.in)));
56   }
57
58
59   /**
60    * Runs the debugger thread. This method reads and executes commands
61    * from the JDE.
62    */
63   public void run() {
64
65     JDE.debug(FRAMEWORK, "Starting JDEbug main loop");
66
67     while (!m_shutdown) {
68       JDE.debug(FRAMEWORK, "JDEbug waiting for cmd");
69       List command = m_commandStream.nextCommand();
70       JDE.debug(FRAMEWORK, "JDEbug got cmd");
71
72       final Integer procID    = Integer.valueOf(command.get(0).toString());
73       final Integer cmdID     = Integer.valueOf(command.get(1).toString());
74       final String  cmdName   = command.get(2).toString().toLowerCase();
75       final List    arguments = command.subList(3, command.size());
76
77       try {
78         CommandHandler handler = SessionManager.getCommandHandler(procID);
79
80         if (handler == null) {
81           throw new JDEException("no command handler found for debugger process: " + procID);
82         }
83
84         JDE.debug(EVENTS, "JDEbug firing command event");
85         handler.fireCommandEvent(procID,
86                                  cmdID,
87                                  cmdName,
88                                  arguments);
89       }
90       catch (JDEException ex) {
91         JDE.commandResult(cmdID, "Error occurred while executing " + cmdName +
92                           ". Error: " + ex,
93                           CMD_NOK, QUOTE);
94       }
95     }
96
97     JDE.debug(FRAMEWORK, "jdebug main loop terminating");
98     SessionManager.shutdown(); // Just in case no Quit command was issued
99   }
100
101   /**
102    * Sets a flag that terminates the main loop (implemented in the
103    * {@link #run} method).
104    */
105   public void shutdown() {
106     m_shutdown = true;
107   }
108
109 } // JDEbug
110
111 /*
112  * $Log: JDEbug.java,v $
113  * Revision 1.13  2003/04/29 16:51:57  troy
114  * Initial version of GUI.  Includes display of local variables.
115  *
116  * Revision 1.12  2003/01/16 05:38:28  paulk
117  * Cosmetic change
118  *
119  * Revision 1.11  2003/01/08 06:53:37  paulk
120  * Integrate Petter Mahlen's updates.
121  *
122  * Revision 1.10  2001/08/14 05:15:01  paulk
123  * Miscellaneous updates.
124  *
125  * Revision 1.9  2001/03/24 05:36:48  paulk
126  * Updated to reflect reorganization of debuggee code.
127  *
128  * Revision 1.8  2000/10/20 04:18:29  paulk
129  * *** empty log message ***
130  *
131  * Revision 1.7  2000/07/28 06:26:31  paulk
132  * Committing all modified files.
133  *
134  * Revision 1.6  2000/02/14 06:25:34  paulk
135  * Implemented workaround for JPDA bug that prevented setting of
136  * breakpoints in inner classes.
137  *
138  * Revision 1.5  2000/01/31 12:41:39  paulk
139  * * Continue converting commands from functional to OO implementation.
140  *
141  * Revision 1.4  2000/01/30 12:47:40  paulk
142  * Changed to a singleton class. Implemented support for object-oriented
143  * commands created by DebugCommandFactory. Reimplemented launch and
144  * listen commands as object-oriented commands.
145  *
146  * Revision 1.3  2000/01/28 04:24:55  paulk
147  * Threaded listen commands. Moved launch, attach, and listen commands
148  * from Application to Jdebug class. Did general cleanup of Jdebug and
149  * Application class, including using more specific names for some
150  * variables, moving fields to the end of files, rewriting comments.
151  *
152  */
153
154
155 // End of JDEbug.java