Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / Watch.java
1 package jde.debugger.command;
2
3 import jde.debugger.Etc;
4 import jde.debugger.JDEException;
5 import jde.debugger.spec.EventRequestSpecList;
6 import jde.debugger.spec.WatchpointSpec;
7
8
9 /**
10  * 'watch' command.
11  * <p>
12  *
13  * <b>Syntax:</b>
14  * <pre>
15  * watch classPattern fieldName <u>type</u>
16  *      [{@link Etc#getThreadFromArgs(List) thread-restriction}]
17  *      [{@link Etc#getExprFromArgs(List) expression-restriction}]
18  *      [{@link Etc#getObjectIDFromArgs(List) object-id-restriction}]
19  *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
20  *      [{@link Etc#getClassFiltersFromArgs(List) class-filters}]
21  *      [{@link Etc#getClassExFiltersFromArgs(List) class-exclusion-filters}]
22  * </pre>
23  *
24  * <b>Returns:</b>
25  * <pre>
26  * (jde-dbo-command-result cmd_id specID)
27  * </pre>
28  *
29  * <b>Comments:</b>
30  * <ul>
31  * <li> <u>type</u> can be "for_access" or "for_modification"
32  * <li> 'classPattern' can be a string pattern of the type *.Test
33  * <li> objectID is used when, for example, when you already know the
34  *  object id of the object, the access/modification of which's field
35  *  you're interested in. 
36  * <li> specID is a 'long', that can be used in 'clear' commands.
37  * </ul>
38  *
39  * <p>
40  * @see jde.debugger.EventHandler#watchpointEvent(WatchpointEvent)
41  *
42  * @author Paul Kinnucan
43  * @version $Revision: 1.2 $
44  *
45  * Copyright (c) 2000, 2001, 2003    Paul Kinnucan
46  * 
47  */
48 public class Watch extends DebugProcessCommand {
49   
50   /**
51    *
52    * @exception jde.debugger.JDEException <description>
53    */
54   public void doCommand() throws JDEException {
55         
56     if (m_args.size() < 3)
57       throw new JDEException("Insufficient arguments");
58         
59     String classPattern = m_args.remove(0).toString();
60     String methodName   = m_args.remove(0).toString();
61     String typeString   = m_args.remove(0).toString().toLowerCase();
62
63     EventRequestSpecList eventRequests = m_debugger.getEventRequestSpecList();
64         
65     WatchpointSpec er = null;
66     if (typeString.equals("for_access")) {
67       if (!m_debugger.getVM().canWatchFieldAccess()) 
68         throw new JDEException("This VM implementation cannot watch field accesses");
69       er = eventRequests.createAccessWatchpoint(classPattern, methodName);
70     } else if (typeString.equals("for_modification")) {
71       if (!m_debugger.getVM().canWatchFieldModification()) 
72         throw new JDEException("This VM implementation cannot watch field modifications");
73       er = eventRequests.createModificationWatchpoint(classPattern, methodName);
74     } else {
75       throw new JDEException("'"+typeString+"' not understood: use either 'for_access' or 'for_modification'");
76     }
77     er.setThread(Etc.getThreadFromArgs(m_args));
78     er.setExpression(Etc.getExprFromArgs(m_args));
79     er.setObjectID(Etc.getObjectIDFromArgs(m_args));
80     er.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(m_args));
81     er.setClassFilters(Etc.getClassFiltersFromArgs(m_args));
82     er.setClassExFilters(Etc.getClassExFiltersFromArgs(m_args));
83     eventRequests.install(er);
84         
85     m_debugger.signalCommandResult(m_cmdID, er.getID().toString(), CMD_OK, NOQUOTE);
86   }
87     
88   public Object clone() {return new Watch();}
89     
90 } // Watch
91
92 /*
93  * $Log: Watch.java,v $
94  * Revision 1.2  2003/01/15 05:56:25  paulk
95  * Add Petter Mahlen's changes.
96  *
97  * Revision 1.1  2001/03/24 13:35:26  paulk
98  * Initial revision.
99  *
100  *
101  */
102
103 // End of Watch.java