Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / TraceThreads.java
1 package jde.debugger.command;
2
3 import java.util.List;
4
5 import com.sun.jdi.ObjectReference;
6 import com.sun.jdi.ThreadReference;
7 import com.sun.jdi.request.EventRequestManager;
8 import com.sun.jdi.request.ThreadDeathRequest;
9 import com.sun.jdi.request.ThreadStartRequest;
10 import jde.debugger.Etc;
11 import jde.debugger.JDEException;
12 import jde.debugger.ObjectStore;
13
14
15 /**
16  * 'trace_threads' command.
17  * <p>
18  *
19  * <b>Syntax:</b>
20  * <pre>
21  * trace_threads <u>type</u> [threadID]
22  *      [{@link Etc#getSuspendPolicyFromArgs(List) suspend-policy}]
23  * </pre>
24  *
25  * <b>Comments:</b>
26  * <ul>
27  * <li> <u>type</u> can be either "start" or "death"
28  * <li> If no threadID is specified, all the corresponding thread
29  * events are raised.
30  * </ul>
31  *
32  * <p>
33  * @see jde.debugger.EventHandler#threadStartEvent(ThreadStartEvent)
34  * @see jde.debugger.EventHandler#threadDeathEvent(ThreadDeathEvent)
35  *
36  * @author Paul Kinnucan
37  * @version $Revision: 1.2 $
38  *
39  * Copyright (c) 2000, 2001, 2003    Paul Kinnucan
40  * 
41  */
42 public class TraceThreads extends DebugProcessCommand {
43   
44   /**
45    *
46    * @exception jde.debugger.JDEException <description>
47    */
48   public void doCommand() throws JDEException {
49     if (m_args.size() < 2)
50       throw new JDEException("Insufficient arguments");
51         
52     String type = m_args.remove(0).toString().toLowerCase();
53         
54     if (!(type.equals("start") || type.equals("death")))
55       throw new JDEException("Invalid type");
56         
57     List classFilters   = Etc.getClassFiltersFromArgs(m_args);
58     List classExFilters = Etc.getClassExFiltersFromArgs(m_args);
59         
60     EventRequestManager em = m_debugger.getVM().eventRequestManager();
61         
62     Long        requestID = null;
63     ObjectStore store     = m_debugger.getStore();
64         
65     if (type.equals("start")) {
66       ThreadStartRequest ter = em.createThreadStartRequest();
67             
68       ter.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(m_args));
69             
70       if (m_args.size() > 0) {
71         Long            threadID = Etc.safeGetLong(m_args.remove(0), "thread ID");
72         ObjectReference tRef     = store.get(threadID);
73         if (tRef == null) {
74           throw new JDEException("No such thread exists");
75         } else if (!(tRef instanceof ThreadReference)) {
76           throw new JDEException("No such thread exists (anymore?)");
77         }
78         ter.addThreadFilter((ThreadReference)tRef);
79       }
80             
81       requestID = m_debugger.addIdentifiableRequest(ter);
82             
83     } else if (type.equals("death")) {
84             
85       ThreadDeathRequest ter = em.createThreadDeathRequest();
86             
87       ter.setSuspendPolicy(Etc.getSuspendPolicyFromArgs(m_args));
88             
89       if (m_args.size() > 0) {
90         Long            threadID = Etc.safeGetLong(m_args.remove(0), "thread ID");
91         ObjectReference tRef     = store.get(threadID);
92         if (tRef == null) {
93           throw new JDEException("No such thread exists");
94         } else if (!(tRef instanceof ThreadReference)) {
95           throw new JDEException("No such thread exists (anymore?)");
96         }
97         ter.addThreadFilter((ThreadReference)tRef);
98       }
99             
100       requestID = m_debugger.addIdentifiableRequest(ter);
101     }
102         
103
104     m_debugger.signalCommandResult(m_cmdID, requestID.toString(), CMD_OK);
105   }
106     
107     
108
109   public Object clone() {return new TraceThreads();}
110   
111 } // TraceThreads
112
113 /*
114  * $Log: TraceThreads.java,v $
115  * Revision 1.2  2003/01/15 05:56:26  paulk
116  * Add Petter Mahlen's changes.
117  *
118  * Revision 1.1  2001/03/24 13:35:26  paulk
119  * Initial revision.
120  *
121  *
122  */
123
124 // End of TraceThreads.java