Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / Break.java
1 package jde.debugger.command;
2 import java.util.ArrayList;
3 import java.util.List;
4 import java.util.StringTokenizer;
5
6 import jde.debugger.Etc;
7 import jde.debugger.JDE;
8 import jde.debugger.JDEException;
9 import jde.debugger.spec.EventRequestSpec;
10 import jde.debugger.spec.EventRequestSpecList;
11
12
13 /**
14  * 'break' command.
15  * <p>
16  *
17  * <b>Syntax:</b>
18  * <pre>
19  * break {@link #doBreakInMethod in_method} class method [(args)] 
20  *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
21  *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
22  *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
23  *     
24  * break {@link #doBreakOnLine on_line}   class line
25  *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
26  *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
27  *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
28  *
29  * break {@link #doBreakAbsolute absolute}  file line
30  *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
31  *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
32  *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
33  * </pre>
34  *
35  * <b>Returns:</b>
36  * <pre>
37  * (jde-dbo-command-result cmdID specID)
38  * </pre>
39  *
40  * <b>Comments:</b>
41  * <ul>
42  * <li> There are exactly three kinds of 'break' commands. One 
43  *      of in_method, on_line, or absolute need to be used.
44  * <li> 'class' can be a string pattern of the type *.Test
45  * <li> specID is a 'long', that can be used in 'clear' commands.
46  * </ul>
47  *
48  * <p>
49  * 
50  * Copyright (c) 2000, 2001, 2003    Paul Kinnucan
51  *
52  * @see jde.debugger.EventHandler#breakpointEvent(BreakpointEvent)
53  *
54  * @author Paul Kinnucan
55  * @version $Revision: 1.2 $
56  *
57  */
58 public class Break extends DebugProcessCommand {
59   
60   /**
61    *
62    * @exception jde.debugger.JDEException <description>
63    */
64   public void doCommand() throws JDEException {
65     try {
66       // whatever function is called, should do a signalCommandResult
67       // during the execution.
68       String type = m_args.remove(0).toString().toLowerCase();
69       if (type.equals("in_method")) {
70         doBreakInMethod(m_args);
71       } else if (type.equals("on_line")) {
72         doBreakOnLine(m_args);
73       } else if (type.equals("absolute")) {
74         doBreakAbsolute(m_args);
75       } else
76         throw new JDEException("Syntax error: expecting one of 'in_method', 'on_line', or 'absolute'; '"+type+"' is not supported");
77     } catch (UnsupportedOperationException ex) {
78       throw new JDEException("Unspecified Error occured");
79     } catch (IndexOutOfBoundsException ex) {
80       throw new JDEException("Syntax error: argument missing");
81     }
82   }
83     
84     
85   /**
86    * A break in a particular method.
87    * <p>
88    *
89    * <b>Syntax:</b>
90    * <pre>
91    * break in_method class method [(arg1,arg2,...)] 
92    *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
93    *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
94    *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
95    * </pre>
96    *
97    * <b>Comments:</b>
98    * <ul>
99    * <li> There should be <b>no spaces</b> before or after the ','; when 
100    *      the arguments are supplied.
101    * <li> A void method should be indicated by <code>()</code>
102    * <li> A unique method doesn't need to supply the arguments. The
103    * <b>entire</b> argument list should be absent in this case.
104    * </ul>
105    */
106   public void doBreakInMethod(List args)
107     throws JDEException {
108
109     if (args.size() < 2)
110       throw new JDEException("Insufficient arguments");
111         
112     String classPattern = args.remove(0).toString();
113     String method = args.remove(0).toString();
114
115     // the argument list
116     List argumentList = null;
117
118     // see if more arguments are present
119     if (args.size() > 0) {
120
121       String arg = args.remove(0).toString();
122
123       // see if any arglist was provided at all
124       if (arg.startsWith("(")) {
125         // apparently it was. double check.
126         if (!arg.endsWith(")")) {
127           throw new JDEException("The argument list seems to be corrupt");
128         }
129         // trim the parens
130         arg = arg.substring(1, arg.length() - 1);
131         argumentList = new ArrayList();
132         StringTokenizer t = new StringTokenizer(arg, ",");
133         while (t.hasMoreTokens()) {
134           argumentList.add(t.nextToken());
135         }
136       }
137     }
138     EventRequestSpecList eventRequests = m_debugger.getEventRequestSpecList();
139     EventRequestSpec er = eventRequests.createMethodBreakpoint(classPattern, method, argumentList);
140     er.setThread(Etc.getThreadFromArgs(args));
141     er.setExpression(Etc.getExprFromArgs(args));
142     er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args));
143     eventRequests.install(er);
144         
145     m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
146   }
147
148   /** A break on a particular line of a class */
149   public void doBreakOnLine(List args)
150     throws JDEException {
151
152     if (args.size() < 2)
153       throw new JDEException("Insufficient arguments");
154         
155     String classPattern = args.remove(0).toString();
156     int line = Etc.safeGetint(args.remove(0), "line number");
157
158     EventRequestSpecList eventRequests = m_debugger.getEventRequestSpecList();
159     EventRequestSpec er =
160       eventRequests.createClassLineBreakpoint(classPattern, line);
161     er.setThread(Etc.getThreadFromArgs(args));
162     er.setExpression(Etc.getExprFromArgs(args));
163     er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args));
164     eventRequests.install(er);
165         
166     m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
167   }
168
169   /** A break on a line of a given source file */
170   public void doBreakAbsolute(List args)
171     throws JDEException {
172
173     if (args.size() < 2)
174       throw new JDEException("Insufficient arguments");
175         
176     String file = args.remove(0).toString();
177     int line = Etc.safeGetint(args.remove(0), "line number");
178         
179     JDE.debug(EVENTS, "Doing an absolute break on file <" + file + ">, line: " + line);
180         
181     EventRequestSpecList eventRequests = m_debugger.getEventRequestSpecList();
182     EventRequestSpec er =
183       eventRequests.createSourceLineBreakpoint(file, line);
184     er.setThread(Etc.getThreadFromArgs(args));
185     er.setExpression(Etc.getExprFromArgs(args));
186     er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args));
187     eventRequests.install(er);
188             
189     m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
190   }
191
192   public Object clone() {return new Break();}
193   
194 } // Break
195
196
197 /*
198  * $Log: Break.java,v $
199  * Revision 1.2  2003/01/15 05:56:26  paulk
200  * Add Petter Mahlen's changes.
201  *
202  * Revision 1.1  2001/03/24 05:48:39  paulk
203  * Initial version.
204  *
205  *
206  */
207
208 // End of Break.java