/* * Copyright (c) 2000, 2001 Paul Kinnucan * * $Revision: 1.1 $ */ package jde.debugger.command; import jde.debugger.JDEException; import java.util.List; import java.util.ArrayList; import java.util.StringTokenizer; import jde.debugger.spec.EventRequestSpec; import jde.debugger.Etc; import jde.debugger.spec.EventRequestSpecList; /** * 'break' command. *

* * Syntax: *

 * break {@link #doBreakInMethod in_method} class method [(args)] 
 *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
 *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
 *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
 *     
 * break {@link #doBreakOnLine on_line}   class line
 *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
 *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
 *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
 *
 * break {@link #doBreakAbsolute absolute}  file line
 *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
 *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
 *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
 * 
* * Returns: *
 * (jde-dbo-command-result cmdID specID)
 * 
* * Comments: * * *

* @see EventHandler#breakpointEvent(BreakpointEvent) * * @author Paul Kinnucan * @version $Revision: 1.1 $ * */ public class Break extends DebugProcessCommand { /** * * @exception jde.debugger.JDEException */ public void doCommand() throws JDEException { try { // whatever function is called, should do a signalCommandResult // during the execution. String type = args.remove(0).toString().toLowerCase(); if (type.equals("in_method")) { doBreakInMethod(args); } else if (type.equals("on_line")) { doBreakOnLine(args); } else if (type.equals("absolute")) { doBreakAbsolute(args); } else throw new JDEException("Syntax error: expecting one of 'in_method', 'on_line', or 'absolute'; '"+type+"' is not supported"); } catch (UnsupportedOperationException ex) { throw new JDEException("Unspecified Error occured"); } catch (IndexOutOfBoundsException ex) { throw new JDEException("Syntax error: argument missing"); } } /** * A break in a particular method. *

* * Syntax: *

     * break in_method class method [(arg1,arg2,...)] 
     *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
     *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
     *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
     * 
* * Comments: * */ public void doBreakInMethod(List args) throws JDEException { if (args.size() < 2) throw new JDEException("Insufficient arguments"); String classPattern = args.remove(0).toString(); String method = args.remove(0).toString(); // the argument list List argumentList = null; // see if more arguments are present if (args.size() > 0) { String arg = args.remove(0).toString(); // see if any arglist was provided at all if (arg.startsWith("(")) { // apparently it was. double check. if (!arg.endsWith(")")) { throw new JDEException("The argument list seems to be corrupt"); } // trim the parens arg = arg.substring(1, arg.length() - 1); argumentList = new ArrayList(); StringTokenizer t = new StringTokenizer(arg, ","); while (t.hasMoreTokens()) { argumentList.add(t.nextToken()); } } } EventRequestSpecList eventRequests = proc.getEventRequestSpecs(); EventRequestSpec er = eventRequests.createMethodBreakpoint(classPattern, method, argumentList); er.setThread(Etc.getThreadFromArgs(args)); er.setExpression(Etc.getExprFromArgs(args)); er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args)); eventRequests.install(er); jde.signalCommandResult(procID, cmdID, er.getID()); } /** A break on a particular line of a class */ public void doBreakOnLine(List args) throws JDEException { if (args.size() < 2) throw new JDEException("Insufficient arguments"); String classPattern = args.remove(0).toString(); int line = Etc.safeGetint(args.remove(0), "line number"); EventRequestSpecList eventRequests = proc.getEventRequestSpecs(); EventRequestSpec er = eventRequests.createClassLineBreakpoint(classPattern, line); er.setThread(Etc.getThreadFromArgs(args)); er.setExpression(Etc.getExprFromArgs(args)); er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args)); eventRequests.install(er); jde.signalCommandResult(procID, cmdID, er.getID()); } /** A break on a line of a given source file */ public void doBreakAbsolute(List args) throws JDEException { if (args.size() < 2) throw new JDEException("Insufficient arguments"); String file = args.remove(0).toString(); int line = Etc.safeGetint(args.remove(0), "line number"); EventRequestSpecList eventRequests = proc.getEventRequestSpecs(); EventRequestSpec er = eventRequests.createSourceLineBreakpoint(file, line); er.setThread(Etc.getThreadFromArgs(args)); er.setExpression(Etc.getExprFromArgs(args)); er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(args)); eventRequests.install(er); jde.signalCommandResult(procID, cmdID, er.getID()); } public Object clone() {return new Break();} } // Break /* * $Log: Break.java,v $ * Revision 1.1 2001/03/24 05:48:39 paulk * Initial version. * * */ // End of Break.java