16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
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 |
19 |
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
20 |
02111-1307 USA. |
02110-1301 USA. |
21 |
|
|
22 |
Linking this library statically or dynamically with other modules is |
Linking this library statically or dynamically with other modules is |
23 |
making a combined work based on this library. Thus, the terms and |
making a combined work based on this library. Thus, the terms and |
40 |
|
|
41 |
package gnu.classpath.jdwp.processor; |
package gnu.classpath.jdwp.processor; |
42 |
|
|
|
import gnu.classpath.jdwp.IVirtualMachine; |
|
|
import gnu.classpath.jdwp.Jdwp; |
|
43 |
import gnu.classpath.jdwp.JdwpConstants; |
import gnu.classpath.jdwp.JdwpConstants; |
44 |
|
import gnu.classpath.jdwp.VMVirtualMachine; |
45 |
import gnu.classpath.jdwp.exception.InvalidFieldException; |
import gnu.classpath.jdwp.exception.InvalidFieldException; |
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.ReferenceTypeId; |
import gnu.classpath.jdwp.id.ReferenceTypeId; |
51 |
import gnu.classpath.jdwp.util.MethodResult; |
import gnu.classpath.jdwp.util.MethodResult; |
62 |
* |
* |
63 |
* @author Aaron Luchko <aluchko@redhat.com> |
* @author Aaron Luchko <aluchko@redhat.com> |
64 |
*/ |
*/ |
65 |
public class ClassTypeCommandSet implements CommandSet |
public class ClassTypeCommandSet |
66 |
|
extends CommandSet |
67 |
{ |
{ |
|
// 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(); |
|
|
|
|
68 |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
69 |
throws JdwpException |
throws JdwpException |
70 |
{ |
{ |
121 |
|
|
122 |
for (int i = 0; i < numValues; i++) |
for (int i = 0; i < numValues; i++) |
123 |
{ |
{ |
124 |
ObjectId fieldId = idMan.readId(bb); |
ObjectId fieldId = idMan.readObjectId(bb); |
125 |
Field field = (Field) (fieldId.getObject()); |
Field field = (Field) (fieldId.getObject()); |
126 |
Object value = Value.getUntaggedObj(bb, field.getType()); |
Object value = Value.getUntaggedObj(bb, field.getType()); |
127 |
try |
try |
147 |
|
|
148 |
Object value = mr.getReturnedValue(); |
Object value = mr.getReturnedValue(); |
149 |
Exception exception = mr.getThrownException(); |
Exception exception = mr.getThrownException(); |
150 |
ObjectId eId = idMan.getId(exception); |
ObjectId eId = idMan.getObjectId(exception); |
151 |
|
|
152 |
Value.writeTaggedValue(os, value); |
Value.writeTaggedValue(os, value); |
153 |
eId.writeTagged(os); |
eId.writeTagged(os); |
159 |
MethodResult mr = invokeMethod(bb); |
MethodResult mr = invokeMethod(bb); |
160 |
|
|
161 |
Object obj = mr.getReturnedValue(); |
Object obj = mr.getReturnedValue(); |
162 |
ObjectId oId = idMan.getId(obj); |
ObjectId oId = idMan.getObjectId(obj); |
163 |
Exception exception = mr.getThrownException(); |
Exception exception = mr.getThrownException(); |
164 |
ObjectId eId = idMan.getId(exception); |
ObjectId eId = idMan.getObjectId(exception); |
165 |
|
|
166 |
oId.writeTagged(os); |
oId.writeTagged(os); |
167 |
eId.writeTagged(os); |
eId.writeTagged(os); |
176 |
ReferenceTypeId refId = idMan.readReferenceTypeId(bb); |
ReferenceTypeId refId = idMan.readReferenceTypeId(bb); |
177 |
Class clazz = refId.getType(); |
Class clazz = refId.getType(); |
178 |
|
|
179 |
ObjectId tId = idMan.readId(bb); |
ObjectId tId = idMan.readObjectId(bb); |
180 |
Thread thread = (Thread) tId.getObject(); |
Thread thread = (Thread) tId.getObject(); |
181 |
|
|
182 |
ObjectId mId = idMan.readId(bb); |
ObjectId mId = idMan.readObjectId(bb); |
183 |
Method method = (Method) mId.getObject(); |
Method method = (Method) mId.getObject(); |
184 |
|
|
185 |
int args = bb.getInt(); |
int args = bb.getInt(); |
189 |
{ |
{ |
190 |
values[i] = Value.getObj(bb); |
values[i] = Value.getObj(bb); |
191 |
} |
} |
192 |
boolean suspendSuccess = false; |
|
193 |
int invokeOpts = bb.getInt(); |
int invokeOpts = bb.getInt(); |
194 |
|
boolean suspend = ((invokeOpts |
195 |
|
& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) |
196 |
|
!= 0); |
197 |
try |
try |
198 |
{ |
{ |
199 |
if ((invokeOpts & JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) |
if (suspend) |
200 |
!= 0) |
VMVirtualMachine.suspendAllThreads (); |
201 |
{ |
|
202 |
// We must suspend all running threads first |
MethodResult mr = VMVirtualMachine.executeMethod(null, thread, |
203 |
suspendSuccess = vm.suspendAllThreadsExcept(Thread.currentThread(). |
clazz, method, |
204 |
getThreadGroup()); |
values, false); |
205 |
} |
if (suspend) |
206 |
MethodResult mr = vm.executeMethod(null, thread, clazz, method, values, |
VMVirtualMachine.resumeAllThreads (); |
207 |
false); |
|
|
if (suspendSuccess) |
|
|
{ // We must call resume if we suspended threads |
|
|
suspendSuccess = false; |
|
|
vm.resumeAllThreadsExcept(Thread.currentThread().getThreadGroup()); |
|
|
} |
|
208 |
return mr; |
return mr; |
209 |
} |
} |
210 |
catch (Exception ex) |
catch (Exception ex) |
211 |
{ |
{ |
212 |
if (suspendSuccess) |
if (suspend) |
213 |
{ // We must call resume if we suspended threads |
VMVirtualMachine.resumeAllThreads (); |
214 |
vm.resumeAllThreadsExcept(Thread.currentThread().getThreadGroup()); |
|
|
} |
|
215 |
throw new JdwpInternalErrorException(ex); |
throw new JdwpInternalErrorException(ex); |
216 |
} |
} |
217 |
} |
} |