15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with GNU Classpath; see the file COPYING. If not, write to the |
along with GNU Classpath; see the file COPYING. If not, write to the |
18 |
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 |
02111-1307 USA. |
02110-1301 USA. |
20 |
|
|
21 |
Linking this library statically or dynamically with other modules is |
Linking this library statically or dynamically with other modules is |
22 |
making a combined work based on this library. Thus, the terms and |
making a combined work based on this library. Thus, the terms and |
39 |
|
|
40 |
package gnu.classpath.jdwp.processor; |
package gnu.classpath.jdwp.processor; |
41 |
|
|
|
import gnu.classpath.jdwp.VMFrame; |
|
|
import gnu.classpath.jdwp.IVirtualMachine; |
|
|
import gnu.classpath.jdwp.Jdwp; |
|
42 |
import gnu.classpath.jdwp.JdwpConstants; |
import gnu.classpath.jdwp.JdwpConstants; |
43 |
|
import gnu.classpath.jdwp.VMFrame; |
44 |
|
import gnu.classpath.jdwp.VMVirtualMachine; |
45 |
import gnu.classpath.jdwp.exception.InvalidObjectException; |
import gnu.classpath.jdwp.exception.InvalidObjectException; |
46 |
import gnu.classpath.jdwp.exception.JdwpException; |
import gnu.classpath.jdwp.exception.JdwpException; |
47 |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
48 |
import gnu.classpath.jdwp.exception.NotImplementedException; |
import gnu.classpath.jdwp.exception.NotImplementedException; |
|
import gnu.classpath.jdwp.id.IdManager; |
|
49 |
import gnu.classpath.jdwp.id.ObjectId; |
import gnu.classpath.jdwp.id.ObjectId; |
50 |
import gnu.classpath.jdwp.id.ThreadId; |
import gnu.classpath.jdwp.id.ThreadId; |
51 |
import gnu.classpath.jdwp.util.JdwpString; |
import gnu.classpath.jdwp.util.JdwpString; |
61 |
* |
* |
62 |
* @author Aaron Luchko <aluchko@redhat.com> |
* @author Aaron Luchko <aluchko@redhat.com> |
63 |
*/ |
*/ |
64 |
public class ThreadReferenceCommandSet implements CommandSet |
public class ThreadReferenceCommandSet |
65 |
|
extends CommandSet |
66 |
{ |
{ |
|
// Our hook into the jvm |
|
|
private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); |
|
|
|
|
|
// Manages all the different ids that are assigned by jdwp |
|
|
private final IdManager idMan = Jdwp.getIdManager(); |
|
|
|
|
67 |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
68 |
throws JdwpException |
throws JdwpException |
69 |
{ |
{ |
124 |
private void executeName(ByteBuffer bb, DataOutputStream os) |
private void executeName(ByteBuffer bb, DataOutputStream os) |
125 |
throws JdwpException, IOException |
throws JdwpException, IOException |
126 |
{ |
{ |
127 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
128 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
129 |
JdwpString.writeString(os, thread.getName()); |
JdwpString.writeString(os, thread.getName()); |
130 |
} |
} |
131 |
|
|
132 |
private void executeSuspend(ByteBuffer bb, DataOutputStream os) |
private void executeSuspend(ByteBuffer bb, DataOutputStream os) |
133 |
throws JdwpException, IOException |
throws JdwpException, IOException |
134 |
{ |
{ |
135 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
136 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
137 |
vm.suspendThread(thread); |
VMVirtualMachine.suspendThread(thread); |
138 |
} |
} |
139 |
|
|
140 |
private void executeResume(ByteBuffer bb, DataOutputStream os) |
private void executeResume(ByteBuffer bb, DataOutputStream os) |
141 |
throws JdwpException, IOException |
throws JdwpException, IOException |
142 |
{ |
{ |
143 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
144 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
145 |
vm.suspendThread(thread); |
VMVirtualMachine.suspendThread(thread); |
146 |
} |
} |
147 |
|
|
148 |
private void executeStatus(ByteBuffer bb, DataOutputStream os) |
private void executeStatus(ByteBuffer bb, DataOutputStream os) |
149 |
throws InvalidObjectException, IOException |
throws JdwpException, IOException |
150 |
{ |
{ |
151 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
152 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
153 |
int threadStatus = vm.getThreadStatus(thread); |
int threadStatus = VMVirtualMachine.getThreadStatus(thread); |
154 |
// There's only one possible SuspendStatus... |
// There's only one possible SuspendStatus... |
155 |
int suspendStatus = JdwpConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED; |
int suspendStatus = JdwpConstants.SuspendStatus.SUSPENDED; |
156 |
|
|
157 |
os.writeInt(threadStatus); |
os.writeInt(threadStatus); |
158 |
os.writeInt(suspendStatus); |
os.writeInt(suspendStatus); |
159 |
} |
} |
160 |
|
|
161 |
private void executeThreadGroup(ByteBuffer bb, DataOutputStream os) |
private void executeThreadGroup(ByteBuffer bb, DataOutputStream os) |
162 |
throws InvalidObjectException, IOException |
throws JdwpException, IOException |
163 |
{ |
{ |
164 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
165 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
166 |
ThreadGroup group = thread.getThreadGroup(); |
ThreadGroup group = thread.getThreadGroup(); |
167 |
ObjectId groupId = idMan.getId(group); |
ObjectId groupId = idMan.getObjectId(group); |
168 |
groupId.write(os); |
groupId.write(os); |
169 |
} |
} |
170 |
|
|
171 |
private void executeFrames(ByteBuffer bb, DataOutputStream os) |
private void executeFrames(ByteBuffer bb, DataOutputStream os) |
172 |
throws JdwpException, IOException |
throws JdwpException, IOException |
173 |
{ |
{ |
174 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
175 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
176 |
int startFrame = bb.getInt(); |
int startFrame = bb.getInt(); |
177 |
int length = bb.getInt(); |
int length = bb.getInt(); |
178 |
|
|
179 |
ArrayList frames = vm.getVMFrames(thread, startFrame, length); |
ArrayList frames = VMVirtualMachine.getFrames(thread, startFrame, length); |
180 |
os.writeInt(frames.size()); |
os.writeInt(frames.size()); |
181 |
for (int i = 0; i < frames.size(); i++) |
for (int i = 0; i < frames.size(); i++) |
182 |
{ |
{ |
190 |
private void executeFrameCount(ByteBuffer bb, DataOutputStream os) |
private void executeFrameCount(ByteBuffer bb, DataOutputStream os) |
191 |
throws JdwpException, IOException |
throws JdwpException, IOException |
192 |
{ |
{ |
193 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
194 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
195 |
|
|
196 |
int frameCount = vm.getFrameCount(thread); |
int frameCount = VMVirtualMachine.getFrameCount(thread); |
197 |
os.writeInt(frameCount); |
os.writeInt(frameCount); |
198 |
} |
} |
199 |
|
|
219 |
private void executeStop(ByteBuffer bb, DataOutputStream os) |
private void executeStop(ByteBuffer bb, DataOutputStream os) |
220 |
throws JdwpException, IOException |
throws JdwpException, IOException |
221 |
{ |
{ |
222 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
223 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
224 |
ObjectId exception = idMan.readId(bb); |
ObjectId exception = idMan.readObjectId(bb); |
225 |
vm.stopThread(thread, (Exception) exception.getObject()); |
Throwable throwable = (Throwable) exception.getObject(); |
226 |
|
thread.stop (throwable); |
227 |
} |
} |
228 |
|
|
229 |
private void executeInterrupt(ByteBuffer bb, DataOutputStream os) |
private void executeInterrupt(ByteBuffer bb, DataOutputStream os) |
230 |
throws JdwpException, IOException |
throws JdwpException, IOException |
231 |
{ |
{ |
232 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
233 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
234 |
thread.interrupt(); |
thread.interrupt(); |
235 |
} |
} |
236 |
|
|
237 |
private void executeSuspendCount(ByteBuffer bb, DataOutputStream os) |
private void executeSuspendCount(ByteBuffer bb, DataOutputStream os) |
238 |
throws JdwpException, IOException |
throws JdwpException, IOException |
239 |
{ |
{ |
240 |
ThreadId tid = (ThreadId) idMan.readId(bb); |
ThreadId tid = (ThreadId) idMan.readObjectId(bb); |
241 |
Thread thread = (Thread) tid.getObject(); |
Thread thread = tid.getThread(); |
242 |
int suspendCount = vm.getSuspendCount(thread); |
int suspendCount = VMVirtualMachine.getSuspendCount(thread); |
243 |
os.writeInt(suspendCount); |
os.writeInt(suspendCount); |
244 |
} |
} |
245 |
} |
} |