Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / GetThreads.java
1 package jde.debugger.command;
2
3 import jde.debugger.JDEException;
4 import com.sun.jdi.ThreadGroupReference;
5 import jde.debugger.Rep;
6 import java.util.Iterator;
7 import java.util.List;
8
9
10 /**
11  * List all threads. 'get_threads' command.
12  * <p>
13  *
14  * <b>Syntax:</b>
15  * <pre>
16  * get_threads
17  * </pre>
18  *
19  * <b>Returns:</b>
20  * <pre>
21  * (jde-dbo-command-result cmd_id {@link #doCommand thread-info})
22  * </pre>
23  *
24  * <b>Comments:</b>
25  * <ul>
26  * <li> There are a couple of quirks regarding the reporting
27  * of thread state:
28  * <ul>
29  * <li> Quirk 1: Due to a bug in ThreadReference.isAtBreakpoint(),
30  *        a thread will report a breakpoint at a location
31  *            even if a threadFilter has been applied for the
32  *            thread. ie, if test.Test.java:41 is your
33  *            breakpoint, and you've applied a threadfilter
34  *            saying you DON'T want an event if the thread ==
35  *            Thread-A, and you somehow suspend Thread-A at
36  *            exactly that line, and do a 'get_threads';
37  *            Thread-A will report to be suspended on a
38  *            breakpoint, although ordinarily it would have
39  *            skipped it.
40  *
41  * <li> Quirk 2: There seems to be no way of reporting the
42  *        status if the user does a
43  *            Thread.suspend(). Well, it's deprecated
44  *            anyways... *shrug*.
45  * </ul>
46  * </ul>
47  *
48  * @author Paul Kinnucan
49  * @version $Revision: 1.2 $
50  * @copyright Copyright (c) 2000, 2001, 2003    Paul Kinnucan
51  *
52  */
53 public class GetThreads extends DebugProcessCommand {
54   
55   /**
56    * Returns a representation of all the threads and threadgroups
57    * in the VM. For example:
58    * <pre>
59    *              ThreadGroup-1
60    *                  +- ThreadGroup-2
61    *                  |        +- ThreadGroup-3
62    *                  |        |        \- Thread-1
63    *                  |        +- ThreadGroup-4
64    *                  |        |        +- Thread-2
65    *                  |        |        \- Thread-3
66    *                  |        \- Thread-4
67    *                  \- Thread-5
68    *              ThreadGroup-5
69    *                  +- Thread-6
70    *
71    *
72    *          (list
73    *            (list "ThreadGroup" <tgID> "ThreadGroup-1"
74    *              (list 
75    *                (list "Thread" <tID> "Thread-5" ...))
76    *              (list 
77    *                (list "ThreadGroup" <tgID> "ThreadGroup-2"
78    *                  (list 
79    *                    (list "Thread" <tID> "Thread-4"))
80    *                  (list 
81    *                    (list "ThreadGroup" <tgID> "ThreadGroup-3"
82    *                      (list)
83    *                      (list 
84    *                        (list "Thread" <tID> "Thread-1" ...)))
85    *                    (list "ThreadGroup" <tgID> "ThreadGroup-4"
86    *                      (list)
87    *                        (list
88    *                          (list "Thread" <tID> "Thread-2" ...)
89    *                          (list "Thread" <tID> "Thread-3" ...)))))))
90    *          (list "ThreadGroup" <tgID> "ThreadGroup-5"
91    *            (list)
92    *              (list
93    *                (list "Thread" <tID> "Thread-6" ...))))
94    * </pre>
95    * <b>Syntax:</b>
96    * <pre>
97    * (list [{@link Rep#getThreadGroupRep top-level thread group}]*)
98    * </pre>
99    *
100    * @exception jde.debugger.JDEException <description>
101    */
102   public void doCommand() throws JDEException {
103         
104     List         l      = m_debugger.getVM().topLevelThreadGroups();
105     Iterator     it     = l.iterator();
106     StringBuffer result = new StringBuffer("(list ");
107         
108     while (it.hasNext()) {
109       // XXX may have to populate the ObjectStore here. 
110             
111       result.append(BR);
112       result.append(Rep.getThreadGroupRep((ThreadGroupReference)it.next()));
113     }
114         
115     result.append(")");
116         
117     m_debugger.signalCommandResult(m_cmdID, result.toString(), CMD_OK, NOQUOTE);
118   }
119
120
121
122   public Object clone() {return new GetThreads();}
123   
124 } // GetThreads
125
126 /*
127  * $Log: GetThreads.java,v $
128  * Revision 1.2  2003/01/15 05:56:26  paulk
129  * Add Petter Mahlen's changes.
130  *
131  * Revision 1.1  2001/03/24 13:35:25  paulk
132  * Initial revision.
133  *
134  *
135  */
136
137 // End of GetThreads.java