1 package jde.debugger.command;
2 import java.util.ArrayList;
4 import java.util.StringTokenizer;
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;
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}]
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}]
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}]
37 * (jde-dbo-command-result cmdID specID)
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.
50 * Copyright (c) 2000, 2001, 2003 Paul Kinnucan
52 * @see jde.debugger.EventHandler#breakpointEvent(BreakpointEvent)
54 * @author Paul Kinnucan
55 * @version $Revision: 1.2 $
58 public class Break extends DebugProcessCommand {
62 * @exception jde.debugger.JDEException <description>
64 public void doCommand() throws JDEException {
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);
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");
86 * A break in a particular method.
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}]
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.
106 public void doBreakInMethod(List args)
107 throws JDEException {
110 throw new JDEException("Insufficient arguments");
112 String classPattern = args.remove(0).toString();
113 String method = args.remove(0).toString();
116 List argumentList = null;
118 // see if more arguments are present
119 if (args.size() > 0) {
121 String arg = args.remove(0).toString();
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");
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());
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);
145 m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
148 /** A break on a particular line of a class */
149 public void doBreakOnLine(List args)
150 throws JDEException {
153 throw new JDEException("Insufficient arguments");
155 String classPattern = args.remove(0).toString();
156 int line = Etc.safeGetint(args.remove(0), "line number");
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);
166 m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
169 /** A break on a line of a given source file */
170 public void doBreakAbsolute(List args)
171 throws JDEException {
174 throw new JDEException("Insufficient arguments");
176 String file = args.remove(0).toString();
177 int line = Etc.safeGetint(args.remove(0), "line number");
179 JDE.debug(EVENTS, "Doing an absolute break on file <" + file + ">, line: " + line);
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);
189 m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
192 public Object clone() {return new Break();}
198 * $Log: Break.java,v $
199 * Revision 1.2 2003/01/15 05:56:26 paulk
200 * Add Petter Mahlen's changes.
202 * Revision 1.1 2001/03/24 05:48:39 paulk