From 820aa607a715296ef00193e5511d5a0eb7c8c559 Mon Sep 17 00:00:00 2001 From: Kyle Galloway Date: Fri, 9 Mar 2007 21:23:10 +0000 Subject: 2007-03-09 Kyle Galloway * gnu/classpath/jdwp/exception/InvalidTagException.java: New file. * gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java (executeGetValues): Use Value type. (exectureSetValues): Ditto. * gnu/classpath/jdwp/processor/ClassTypeCommandSet.java (executeGetValues): Use Value type. (executeSetValues): Ditto. (invokeMethod): Record method return type. * gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java (executeGetValues): Use Value type. (executeSetValues): Ditto. * gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java (executeGetValues): Use Value type. * gnu/classpath/jdwp/processor/StackFrameCommandSet.java (executeGetValues): Use Value type. (executeSetValues): Ditto. * gnu/classpath/jdwp/util/MethodResult.java: Add resType to store return type. (getResultType): New Method. (setResultType): Ditto. * gnu/classpath/jdwp/util/Value.java: Remove. * gnu/classpath/jdwp/value: New Package. * gnu/classpath/jdwp/value/Value.java: New file. * gnu/classpath/jdwp/value/BooleanValue.java: New file. * gnu/classpath/jdwp/value/ByteValue.java: New file. * gnu/classpath/jdwp/value/CharValue.java: New file. * gnu/classpath/jdwp/value/DoubleValue.java: New file. * gnu/classpath/jdwp/value/FloatValue.java: New file. * gnu/classpath/jdwp/value/IntValue.java: New file. * gnu/classpath/jdwp/value/LongValue.java: New file. * gnu/classpath/jdwp/value/ObjectValue.java: New file. * gnu/classpath/jdwp/value/ShortValue.java: New file. * gnu/classpath/jdwp/value/StringValue.java: New file. * gnu/classpath/jdwp/value/ValueFactory.java: New file. * gnu/classpath/jdwp/value/VoidValue.java: New file. --- ChangeLog | 38 +++ .../jdwp/exception/InvalidTagException.java | 57 ++++ .../jdwp/processor/ArrayReferenceCommandSet.java | 11 +- .../jdwp/processor/ClassTypeCommandSet.java | 12 +- .../jdwp/processor/ObjectReferenceCommandSet.java | 16 +- .../jdwp/processor/ReferenceTypeCommandSet.java | 7 +- .../jdwp/processor/StackFrameCommandSet.java | 14 +- gnu/classpath/jdwp/util/MethodResult.java | 13 + gnu/classpath/jdwp/util/Value.java | 301 --------------------- gnu/classpath/jdwp/value/BooleanValue.java | 100 +++++++ gnu/classpath/jdwp/value/ByteValue.java | 99 +++++++ gnu/classpath/jdwp/value/CharValue.java | 100 +++++++ gnu/classpath/jdwp/value/DoubleValue.java | 100 +++++++ gnu/classpath/jdwp/value/FloatValue.java | 100 +++++++ gnu/classpath/jdwp/value/IntValue.java | 100 +++++++ gnu/classpath/jdwp/value/LongValue.java | 100 +++++++ gnu/classpath/jdwp/value/ObjectValue.java | 92 +++++++ gnu/classpath/jdwp/value/ShortValue.java | 100 +++++++ gnu/classpath/jdwp/value/StringValue.java | 100 +++++++ gnu/classpath/jdwp/value/Value.java | 155 +++++++++++ gnu/classpath/jdwp/value/ValueFactory.java | 247 +++++++++++++++++ gnu/classpath/jdwp/value/VoidValue.java | 82 ++++++ vm/reference/gnu/classpath/jdwp/VMFrame.java | 5 +- 23 files changed, 1624 insertions(+), 325 deletions(-) create mode 100644 gnu/classpath/jdwp/exception/InvalidTagException.java delete mode 100644 gnu/classpath/jdwp/util/Value.java create mode 100644 gnu/classpath/jdwp/value/BooleanValue.java create mode 100644 gnu/classpath/jdwp/value/ByteValue.java create mode 100644 gnu/classpath/jdwp/value/CharValue.java create mode 100644 gnu/classpath/jdwp/value/DoubleValue.java create mode 100644 gnu/classpath/jdwp/value/FloatValue.java create mode 100644 gnu/classpath/jdwp/value/IntValue.java create mode 100644 gnu/classpath/jdwp/value/LongValue.java create mode 100644 gnu/classpath/jdwp/value/ObjectValue.java create mode 100644 gnu/classpath/jdwp/value/ShortValue.java create mode 100644 gnu/classpath/jdwp/value/StringValue.java create mode 100644 gnu/classpath/jdwp/value/Value.java create mode 100644 gnu/classpath/jdwp/value/ValueFactory.java create mode 100644 gnu/classpath/jdwp/value/VoidValue.java diff --git a/ChangeLog b/ChangeLog index ea14949f2..3b56b9481 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,41 @@ +2007-03-09 Kyle Galloway + + * gnu/classpath/jdwp/exception/InvalidTagException.java: New file. + * gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java + (executeGetValues): Use Value type. + (exectureSetValues): Ditto. + * gnu/classpath/jdwp/processor/ClassTypeCommandSet.java + (executeGetValues): Use Value type. + (executeSetValues): Ditto. + (invokeMethod): Record method return type. + * gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java + (executeGetValues): Use Value type. + (executeSetValues): Ditto. + * gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java + (executeGetValues): Use Value type. + * gnu/classpath/jdwp/processor/StackFrameCommandSet.java + (executeGetValues): Use Value type. + (executeSetValues): Ditto. + * gnu/classpath/jdwp/util/MethodResult.java: Add resType to store return + type. + (getResultType): New Method. + (setResultType): Ditto. + * gnu/classpath/jdwp/util/Value.java: Remove. + * gnu/classpath/jdwp/value: New Package. + * gnu/classpath/jdwp/value/Value.java: New file. + * gnu/classpath/jdwp/value/BooleanValue.java: New file. + * gnu/classpath/jdwp/value/ByteValue.java: New file. + * gnu/classpath/jdwp/value/CharValue.java: New file. + * gnu/classpath/jdwp/value/DoubleValue.java: New file. + * gnu/classpath/jdwp/value/FloatValue.java: New file. + * gnu/classpath/jdwp/value/IntValue.java: New file. + * gnu/classpath/jdwp/value/LongValue.java: New file. + * gnu/classpath/jdwp/value/ObjectValue.java: New file. + * gnu/classpath/jdwp/value/ShortValue.java: New file. + * gnu/classpath/jdwp/value/StringValue.java: New file. + * gnu/classpath/jdwp/value/ValueFactory.java: New file. + * gnu/classpath/jdwp/value/VoidValue.java: New file. + 2007-03-09 Roman Kennke * java/awt/image/SinglePixelPackageSampleModel.java diff --git a/gnu/classpath/jdwp/exception/InvalidTagException.java b/gnu/classpath/jdwp/exception/InvalidTagException.java new file mode 100644 index 000000000..738b5e734 --- /dev/null +++ b/gnu/classpath/jdwp/exception/InvalidTagException.java @@ -0,0 +1,57 @@ +/* InvalidTagException.java -- an invalid type tag exception + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid tag is used by + * the debugger + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class InvalidTagException + extends JdwpException +{ + public InvalidTagException (byte tag) + { + super (JdwpConstants.Error.INVALID_TAG, + "invalid tag (" + tag + ")"); + } +} diff --git a/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java index a9dc6cc81..5f579050a 100644 --- a/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java @@ -46,7 +46,8 @@ import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpInternalErrorException; import gnu.classpath.jdwp.exception.NotImplementedException; import gnu.classpath.jdwp.id.ObjectId; -import gnu.classpath.jdwp.util.Value; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; import java.io.DataOutputStream; import java.io.IOException; @@ -150,11 +151,11 @@ public class ArrayReferenceCommandSet // tagged for (int i = first; i < first + length; i++) { - Object value = Array.get(array, i); + Value val = ValueFactory.createFromObject(Array.get(array, i), clazz); if (clazz.isPrimitive()) - Value.writeUntaggedValue(os, value); + val.writeUntagged(os); else - Value.writeTaggedValue(os, value); + val.writeTagged(os); } } @@ -168,7 +169,7 @@ public class ArrayReferenceCommandSet Class type = array.getClass().getComponentType(); for (int i = first; i < first + length; i++) { - Object value = Value.getUntaggedObj(bb, type); + Object value = Value.getUntaggedObject(bb, type); Array.set(array, i, value); } } diff --git a/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java index a3a7ca05e..278cade81 100644 --- a/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java +++ b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java @@ -49,7 +49,8 @@ import gnu.classpath.jdwp.exception.NotImplementedException; import gnu.classpath.jdwp.id.ObjectId; import gnu.classpath.jdwp.id.ReferenceTypeId; import gnu.classpath.jdwp.util.MethodResult; -import gnu.classpath.jdwp.util.Value; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; import java.io.DataOutputStream; import java.io.IOException; @@ -128,7 +129,7 @@ public class ClassTypeCommandSet { ObjectId fieldId = idMan.readObjectId(bb); Field field = (Field) (fieldId.getObject()); - Object value = Value.getUntaggedObj(bb, field.getType()); + Object value = Value.getUntaggedObject(bb, field.getType()); try { field.setAccessible(true); // Might be a private field @@ -154,7 +155,8 @@ public class ClassTypeCommandSet Exception exception = mr.getThrownException(); ObjectId eId = idMan.getObjectId(exception); - Value.writeTaggedValue(os, value); + Value val = ValueFactory.createFromObject(value, mr.getResultType()); + val.writeTagged(os); eId.writeTagged(os); } @@ -192,7 +194,7 @@ public class ClassTypeCommandSet for (int i = 0; i < args; i++) { - values[i] = Value.getObj(bb); + values[i] = Value.getTaggedObject(bb); } int invokeOpts = bb.getInt(); @@ -207,6 +209,8 @@ public class ClassTypeCommandSet MethodResult mr = VMVirtualMachine.executeMethod(null, thread, clazz, method, values, false); + mr.setResultType(method.getReturnType()); + if (suspend) VMVirtualMachine.resumeAllThreads (); diff --git a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java index 6bcd11e89..ed83fd2f9 100644 --- a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java @@ -49,7 +49,8 @@ import gnu.classpath.jdwp.id.ObjectId; import gnu.classpath.jdwp.id.ReferenceTypeId; import gnu.classpath.jdwp.util.MethodResult; import gnu.classpath.jdwp.util.MonitorInfo; -import gnu.classpath.jdwp.util.Value; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; import java.io.DataOutputStream; import java.io.IOException; @@ -138,7 +139,9 @@ public class ObjectReferenceCommandSet { field.setAccessible(true); // Might be a private field Object value = field.get(obj); - Value.writeTaggedValue(os, value); + Value val = ValueFactory.createFromObject(value, + field.getType()); + val.writeTagged(os); } catch (IllegalArgumentException ex) { @@ -164,7 +167,7 @@ public class ObjectReferenceCommandSet for (int i = 0; i < numFields; i++) { Field field = (Field) idMan.readObjectId(bb).getObject(); - Object value = Value.getUntaggedObj(bb, field.getType()); + Object value = Value.getUntaggedObject(bb, field.getType()); try { field.setAccessible(true); // Might be a private field @@ -218,7 +221,7 @@ public class ObjectReferenceCommandSet for (int i = 0; i < args; i++) { - values[i] = Value.getObj(bb); + values[i] = Value.getTaggedObject(bb); } int invokeOptions = bb.getInt(); @@ -238,11 +241,14 @@ public class ObjectReferenceCommandSet MethodResult mr = VMVirtualMachine.executeMethod(obj, thread, clazz, method, values, nonVirtual); + mr.setResultType (method.getReturnType()); + Object value = mr.getReturnedValue(); Exception exception = mr.getThrownException(); ObjectId eId = idMan.getObjectId(exception); - Value.writeTaggedValue(os, value); + Value val = ValueFactory.createFromObject(value, mr.getResultType()); + val.writeTagged(os); eId.writeTagged(os); } diff --git a/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java b/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java index cfee7194d..8e8b74b9d 100644 --- a/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java +++ b/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java @@ -51,7 +51,8 @@ import gnu.classpath.jdwp.id.ObjectId; import gnu.classpath.jdwp.id.ReferenceTypeId; import gnu.classpath.jdwp.util.JdwpString; import gnu.classpath.jdwp.util.Signature; -import gnu.classpath.jdwp.util.Value; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; import java.io.DataOutputStream; import java.io.IOException; @@ -220,7 +221,9 @@ public class ReferenceTypeCommandSet { field.setAccessible(true); // Might be a private field Object value = field.get(null); - Value.writeTaggedValue(os, value); + Value val = ValueFactory.createFromObject(value, + field.getType()); + val.writeTagged(os); } catch (IllegalArgumentException ex) { diff --git a/gnu/classpath/jdwp/processor/StackFrameCommandSet.java b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java index 4cfb25183..2d90e8064 100644 --- a/gnu/classpath/jdwp/processor/StackFrameCommandSet.java +++ b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java @@ -46,7 +46,9 @@ import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpInternalErrorException; import gnu.classpath.jdwp.exception.NotImplementedException; import gnu.classpath.jdwp.id.ThreadId; -import gnu.classpath.jdwp.util.Value; +import gnu.classpath.jdwp.value.ObjectValue; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; import java.io.DataOutputStream; import java.io.IOException; @@ -115,8 +117,8 @@ public class StackFrameCommandSet { int slot = bb.getInt(); byte sig = bb.get(); - Object val = frame.getValue(slot, sig); - Value.writeTaggedValue(os, val); + Value val = frame.getValue(slot, sig); + val.writeTagged(os); } } @@ -133,7 +135,7 @@ public class StackFrameCommandSet for (int i = 0; i < slots; i++) { int slot = bb.getInt(); - Object value = Value.getObj(bb); + Value value = ValueFactory.createFromTagged(bb); frame.setValue(slot, value); } } @@ -147,8 +149,8 @@ public class StackFrameCommandSet long frameID = bb.getLong(); VMFrame frame = VMVirtualMachine.getFrame(thread, frameID); - Object thisObject = frame.getObject(); - Value.writeTaggedValue(os, thisObject); + ObjectValue objVal = new ObjectValue(frame.getObject()); + objVal.writeTagged(os); } private void executePopFrames(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/util/MethodResult.java b/gnu/classpath/jdwp/util/MethodResult.java index a9c1b3305..190511de8 100644 --- a/gnu/classpath/jdwp/util/MethodResult.java +++ b/gnu/classpath/jdwp/util/MethodResult.java @@ -52,6 +52,9 @@ public class MethodResult // Any Exception that was thrown by the executing method private Exception thrownException; + + // The type of this result + private Class resType; public Object getReturnedValue() { @@ -73,4 +76,14 @@ public class MethodResult this.thrownException = thrownException; } + public Class getResultType() + { + return resType; + } + + public void setResultType(Class type) + { + resType = type; + } + } diff --git a/gnu/classpath/jdwp/util/Value.java b/gnu/classpath/jdwp/util/Value.java deleted file mode 100644 index 414c4a33b..000000000 --- a/gnu/classpath/jdwp/util/Value.java +++ /dev/null @@ -1,301 +0,0 @@ -/* Value.java -- class to read/write JDWP tagged and untagged values - Copyright (C) 2005, 2006, Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.util; - -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.VMIdManager; -import gnu.classpath.jdwp.exception.InvalidFieldException; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; -import gnu.classpath.jdwp.exception.NotImplementedException; -import gnu.classpath.jdwp.id.ObjectId; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * A class to read/write JDWP tagged and untagged values. - * - * @author Aaron Luchko - */ -public class Value -{ - /** - * Will write the given object as an untagged value to the DataOutputStream. - * - * @param os write the value here - * @param obj the Object to write - * @throws IOException - * @throws InvalidFieldException - */ - public static void writeUntaggedValue(DataOutputStream os, Object obj) - throws JdwpException, IOException - { - writeValue(os, obj, false); - } - - /** - * Will write the given object as a tagged value to the DataOutputStream. - * - * @param os write the value here - * @param obj the Object to write - * @throws IOException - * @throws InvalidFieldException - */ - public static void writeTaggedValue(DataOutputStream os, Object obj) - throws JdwpException, IOException - { - writeValue(os, obj, true); - } - - /** - * Will write the given object as either a value or an untagged value to the - * DataOutputStream. - * - * @param os write the value here - * @param obj the Object to write - * @param tagged true if the value is tagged, false otherwise - * @throws IOException - * @throws InvalidFieldException - */ - private static void writeValue(DataOutputStream os, Object obj, - boolean tagged) - throws IOException, JdwpException - { - Class clazz = obj.getClass(); - if (clazz.isPrimitive()) - { - if (clazz == byte.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.BYTE); - os.writeByte(((Byte) obj).byteValue()); - } - else if (clazz == char.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.CHAR); - os.writeChar(((Character) obj).charValue()); - } - else if (clazz == float.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.FLOAT); - os.writeFloat(((Float) obj).floatValue()); - } - else if (clazz == double.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.DOUBLE); - os.writeDouble(((Double) obj).doubleValue()); - } - else if (clazz == int.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.BYTE); - os.writeInt(((Integer) obj).intValue()); - } - else if (clazz == long.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.LONG); - os.writeLong(((Long) obj).longValue()); - } - else if (clazz == short.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.SHORT); - os.writeInt(((Short) obj).shortValue()); - } - else if (clazz == void.class) - { // A 'void' has no data - if (tagged) - os.writeByte(JdwpConstants.Tag.VOID); - } - else if (clazz == boolean.class) - { - if (tagged) - os.writeByte(JdwpConstants.Tag.BOOLEAN); - os.writeBoolean(((Boolean) obj).booleanValue()); - } - else - { // This shouldn't be possible - throw new JdwpInternalErrorException( - "Field has invalid primitive!"); - } - } - else - { - // Object is an Object, not a primitive type wrapped in an object - // Write the appropriate tag - if (tagged) - { - if (clazz.isArray()) - os.writeByte(JdwpConstants.Tag.ARRAY); - else if (obj instanceof String) - os.writeByte(JdwpConstants.Tag.STRING); - else if (obj instanceof Thread) - os.writeByte(JdwpConstants.Tag.THREAD); - else if (obj instanceof ThreadGroup) - os.writeByte(JdwpConstants.Tag.THREAD_GROUP); - else if (obj instanceof ClassLoader) - os.writeByte(JdwpConstants.Tag.CLASS_LOADER); - else if (obj instanceof Class) - os.writeByte(JdwpConstants.Tag.CLASS_OBJECT); - else - os.writeByte(JdwpConstants.Tag.OBJECT); - } - ObjectId oid = VMIdManager.getDefault().getObjectId(obj); - oid.write(os); - } - } - - /** - * Reads the appropriate object for the tagged value contained in the - * ByteBuffer. - * - * @param bb contains the Object - * @return The Object referenced by the value - * @throws JdwpException - * @throws IOException - */ - public static Object getObj(ByteBuffer bb) - throws JdwpException, IOException - { - return getUntaggedObj(bb, bb.get()); - } - - /** - * Reads an object of the given Class from the untagged value contained - * in the ByteBuffer. - * - * @param bb contains the Object - * @param type corresponds to the TAG of value to be read - * @return the resultant object - * @throws JdwpException - * @throws IOException - */ - public static Object getUntaggedObj(ByteBuffer bb, Class type) - throws JdwpException, IOException - { - if (type.isPrimitive()) - { - if (type == byte.class) - return new Byte(bb.get()); - else if (type == char.class) - return new Character(bb.getChar()); - else if (type == float.class) - return new Float(bb.getFloat()); - else if (type == double.class) - return new Double(bb.getDouble()); - else if (type == int.class) - return new Integer(bb.getInt()); - else if (type == long.class) - return new Long(bb.getLong()); - else if (type == short.class) - return new Short(bb.getShort()); - else if (type == boolean.class) - return Boolean.valueOf(bb.get() != 0); - else if (type == void.class) - return new byte[0]; - else - { // This shouldn't be possible - throw new JdwpInternalErrorException( - "Field has invalid primitive!"); - } - } - else - { - // Field is an object - ObjectId oid = VMIdManager.getDefault().readObjectId(bb); - return oid.getObject(); - } - } - - /** - * Reads the an object of the given Class from the untagged value contained - * in the ByteBuffer. - * - * @param bb contains the Object - * @param tag TAG of the Value to be read - * @return the object - * @throws JdwpException - * @throws IOException - */ - public static Object getUntaggedObj(ByteBuffer bb, byte tag) - throws JdwpException, IOException - { - switch (tag) - { - case JdwpConstants.Tag.BYTE: - return new Byte(bb.get()); - case JdwpConstants.Tag.CHAR: - return new Character(bb.getChar()); - case JdwpConstants.Tag.FLOAT: - return new Float(bb.getFloat()); - case JdwpConstants.Tag.DOUBLE: - return new Double(bb.getDouble()); - case JdwpConstants.Tag.INT: - return new Integer(bb.getInt()); - case JdwpConstants.Tag.LONG: - return new Long(bb.getLong()); - case JdwpConstants.Tag.SHORT: - return new Short(bb.getShort()); - case JdwpConstants.Tag.VOID: - return new byte[0]; - case JdwpConstants.Tag.BOOLEAN: - return (bb.get() == 0) ? new Boolean(false) : new Boolean(true); - case JdwpConstants.Tag.STRING: - return JdwpString.readString(bb); - case JdwpConstants.Tag.ARRAY: - case JdwpConstants.Tag.THREAD: - case JdwpConstants.Tag.OBJECT: - case JdwpConstants.Tag.THREAD_GROUP: - case JdwpConstants.Tag.CLASS_LOADER: - case JdwpConstants.Tag.CLASS_OBJECT: - // All these cases are ObjectIds - ObjectId oid = VMIdManager.getDefault().readObjectId(bb); - return oid.getObject(); - default: - throw new NotImplementedException("Tag " + tag - + " is not implemented."); - } - } -} diff --git a/gnu/classpath/jdwp/value/BooleanValue.java b/gnu/classpath/jdwp/value/BooleanValue.java new file mode 100644 index 000000000..42bb806fa --- /dev/null +++ b/gnu/classpath/jdwp/value/BooleanValue.java @@ -0,0 +1,100 @@ +/* BooleanValue.java -- JDWP wrapper class for a boolean value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an boolean value. + * + * @author Kyle Galloway + */ +public final class BooleanValue + extends Value +{ + // The boolean wrapped by this class + boolean _value; + + /** + * Create a new BooleanValue from an boolean + * + * @param value the boolean to wrap + */ + public BooleanValue(boolean value) + { + super(JdwpConstants.Tag.BOOLEAN); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public boolean getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Boolean(_value); + } + + /** + * Write the wrapped boolean to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeBoolean(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/ByteValue.java b/gnu/classpath/jdwp/value/ByteValue.java new file mode 100644 index 000000000..204fe86b0 --- /dev/null +++ b/gnu/classpath/jdwp/value/ByteValue.java @@ -0,0 +1,99 @@ +/* ByteValue.java -- JDWP wrapper class for a byte value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an byte value. + * + * @author Kyle Galloway + */ +public final class ByteValue + extends Value +{ + // The byte wrapped by this class + byte _value; + + /** + * Create a new ByteValue from an byte + * + * @param value the byte to wrap + */ + public ByteValue(byte value) + { + super(JdwpConstants.Tag.BYTE); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public byte getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Byte(_value); + } + + /** + * Write the wrapped byte to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeByte(_value); + } +} diff --git a/gnu/classpath/jdwp/value/CharValue.java b/gnu/classpath/jdwp/value/CharValue.java new file mode 100644 index 000000000..f68fc88d1 --- /dev/null +++ b/gnu/classpath/jdwp/value/CharValue.java @@ -0,0 +1,100 @@ +/* CharValue.java -- JDWP wrapper class for a char value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an char value. + * + * @author Kyle Galloway + */ +public final class CharValue + extends Value +{ + // The char wrapped by this class + char _value; + + /** + * Create a new CharValue from an char + * + * @param value the char to wrap + */ + public CharValue(char value) + { + super(JdwpConstants.Tag.CHAR); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public char getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Character(_value); + } + + /** + * Write the wrapped char to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeChar(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/DoubleValue.java b/gnu/classpath/jdwp/value/DoubleValue.java new file mode 100644 index 000000000..45923c4da --- /dev/null +++ b/gnu/classpath/jdwp/value/DoubleValue.java @@ -0,0 +1,100 @@ +/* DoubleValue.java -- JDWP wrapper class for a double value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an double value. + * + * @author Kyle Galloway + */ +public final class DoubleValue + extends Value +{ + // The double wrapped by this class + double _value; + + /** + * Create a new DoubleValue from an double + * + * @param value the double to wrap + */ + public DoubleValue(double value) + { + super(JdwpConstants.Tag.DOUBLE); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public double getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Double(_value); + } + + /** + * Write the wrapped double to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeDouble(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/FloatValue.java b/gnu/classpath/jdwp/value/FloatValue.java new file mode 100644 index 000000000..970f77c07 --- /dev/null +++ b/gnu/classpath/jdwp/value/FloatValue.java @@ -0,0 +1,100 @@ +/* FloatValue.java -- JDWP wrapper class for a float value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +afloat with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an float value. + * + * @author Kyle Galloway + */ +public final class FloatValue + extends Value +{ + // The float wrapped by this class + float _value; + + /** + * Create a new FloatValue from an float + * + * @param value the float to wrap + */ + public FloatValue(float value) + { + super(JdwpConstants.Tag.FLOAT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public float getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Float(_value); + } + + /** + * Write the wrapped float to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeFloat(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/IntValue.java b/gnu/classpath/jdwp/value/IntValue.java new file mode 100644 index 000000000..27868754f --- /dev/null +++ b/gnu/classpath/jdwp/value/IntValue.java @@ -0,0 +1,100 @@ +/* IntValue.java -- JDWP wrapper class for an int value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an int value. + * + * @author Kyle Galloway + */ +public final class IntValue + extends Value +{ + // The int wrapped by this class + int _value; + + /** + * Create a new IntValue from an int + * + * @param value the int to wrap + */ + public IntValue(int value) + { + super(JdwpConstants.Tag.INT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public int getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Integer(_value); + } + + /** + * Write the wrapped int to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeInt(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/LongValue.java b/gnu/classpath/jdwp/value/LongValue.java new file mode 100644 index 000000000..0ebe0e9f9 --- /dev/null +++ b/gnu/classpath/jdwp/value/LongValue.java @@ -0,0 +1,100 @@ +/* LongValue.java -- JDWP wrapper class for a long value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an long value. + * + * @author Kyle Galloway + */ +public final class LongValue + extends Value +{ + // The long wrapped by this class + long _value; + + /** + * Create a new LongValue from an long + * + * @param value the long to wrap + */ + public LongValue(long value) + { + super(JdwpConstants.Tag.LONG); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public long getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Long(_value); + } + + /** + * Write the wrapped long to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeLong(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/ObjectValue.java b/gnu/classpath/jdwp/value/ObjectValue.java new file mode 100644 index 000000000..7ec9beb5f --- /dev/null +++ b/gnu/classpath/jdwp/value/ObjectValue.java @@ -0,0 +1,92 @@ +/* ObjectValue.java -- JDWP wrapper class for an Object value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an Object value. + * + * @author Kyle Galloway + */ +public final class ObjectValue + extends Value +{ + // The Object wrapped by this class + Object _value; + + /** + * Create a new ObjectValue from an Object + * + * @param value the Object to wrap + */ + public ObjectValue(Object value) + { + super(JdwpConstants.Tag.OBJECT); + _value = value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return _value; + } + + /** + * Write the wrapped object to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + ObjectId oid = VMIdManager.getDefault().getObjectId(_value); + oid.write(os); + } +} diff --git a/gnu/classpath/jdwp/value/ShortValue.java b/gnu/classpath/jdwp/value/ShortValue.java new file mode 100644 index 000000000..cbde2269e --- /dev/null +++ b/gnu/classpath/jdwp/value/ShortValue.java @@ -0,0 +1,100 @@ +/* ShortValue.java -- JDWP wrapper class for a short value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an short value. + * + * @author Kyle Galloway + */ +public final class ShortValue + extends Value +{ + // The short wrapped by this class + short _value; + + /** + * Create a new ShortValue from a short + * + * @param value the short to wrap + */ + public ShortValue(short value) + { + super(JdwpConstants.Tag.SHORT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public short getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Short(_value); + } + + /** + * Write the wrapped short to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeShort(_value); + } +} + diff --git a/gnu/classpath/jdwp/value/StringValue.java b/gnu/classpath/jdwp/value/StringValue.java new file mode 100644 index 000000000..2371547ef --- /dev/null +++ b/gnu/classpath/jdwp/value/StringValue.java @@ -0,0 +1,100 @@ +/* StringValue.java -- JDWP wrapper class for an String value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.util.JdwpString; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an String value. + * + * @author Kyle Galloway + */ +public final class StringValue + extends Value +{ + // The String wrapped by this class + String _value; + + /** + * Create a new StringValue from an String + * + * @param value the String to wrap + */ + public StringValue(String value) + { + super(JdwpConstants.Tag.OBJECT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public String getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return _value; + } + + /** + * Write the wrapped object to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + JdwpString.writeString(os, _value); + } +} diff --git a/gnu/classpath/jdwp/value/Value.java b/gnu/classpath/jdwp/value/Value.java new file mode 100644 index 000000000..4ad8bec07 --- /dev/null +++ b/gnu/classpath/jdwp/value/Value.java @@ -0,0 +1,155 @@ +/* Value.java -- base class of JDWP values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.InvalidTagException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * Superclass for all JDWP Values. + * + * @author Kyle Galloway + */ +public abstract class Value +{ + // A Tag representing the type of this value + private byte _tag; + + /** + * Create a new value of type tag. + * + * @param tag the type of the value + */ + protected Value(byte tag) + { + _tag = tag; + } + + /** + * Get the tag for this Value + * + * @return the byte tag of this Value + */ + public byte getTag() + { + return _tag; + } + + /** + * Calls the dervied classes writeValue method to write its value to the + * DataOutputStream. + * + * @param os write the value here + * @throws IOException + */ + public void writeUntagged(DataOutputStream os) + throws IOException + { + write(os); + } + + /** + * Will write the given object as a tagged value to the DataOutputStream. + * + * @param os write the value here + * @param obj the Object to write + * @throws IOException + */ + public void writeTagged(DataOutputStream os) + throws IOException + { + os.write (_tag); + write(os); + } + + /** + * This method must write the value to the DataOutputStream in a manner + * appropriate for the type of the value. + * + * @param os DataOutputStream to write to + * @throws IOException + */ + protected abstract void write(DataOutputStream os) + throws IOException; + + /** + * Returns an object representing this type + * + * @return an Object represntation of this value + */ + protected abstract Object getObject(); + + /** + * Get an untagged object from the ByteBuffer + * + * @param bb the ByteBuffer to extract the value from + * @param type a Class representing the type + * @return an Object from the ByteBuffer of the type of the Class parameter + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Object getUntaggedObject(ByteBuffer bb, Class type) + throws JdwpInternalErrorException, InvalidObjectException, InvalidClassException + { + Value val = ValueFactory.createFromUntagged(bb, type); + return val.getObject(); + } + + /** + * Get an untagged object from the ByteBuffer + * + * @param bb the ByteBuffer to extract the value from + * @param tag a byte tag representing the type + * @return an Object from the ByteBuffer of the type of the Class parameter + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Object getTaggedObject(ByteBuffer bb) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + Value val = ValueFactory.createFromTagged(bb); + return val.getObject(); + } +} diff --git a/gnu/classpath/jdwp/value/ValueFactory.java b/gnu/classpath/jdwp/value/ValueFactory.java new file mode 100644 index 000000000..8f1a8780e --- /dev/null +++ b/gnu/classpath/jdwp/value/ValueFactory.java @@ -0,0 +1,247 @@ +/* ValueFactory.java -- factory to create JDWP Values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.InvalidTagException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.util.JdwpString; + +import java.nio.ByteBuffer; + +/** + * A factory to create JDWP Values. + * + * @author Kyle Galloway + */ +public class ValueFactory +{ + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer + * by reading the tag byte from the front of the buffer. + * + * @param bb contains the Object + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Value createFromTagged(ByteBuffer bb) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + return create(bb, bb.get()); + } + + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer + * by checking the type of the Class passed in. + * + * @param bb contains the Object + * @param type a Class representing the type of the value in the ByteBuffer + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Value createFromUntagged(ByteBuffer bb, Class type) + throws JdwpInternalErrorException, InvalidObjectException, InvalidClassException + { + byte tag = getTagForClass(type); + + try + { + return create(bb, tag); + } + catch (InvalidTagException ite) + { + throw new InvalidClassException(ite); + } + } + + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer. + * + * @param bb contains the Object + * @param tag a byte representing the type of the object + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + private static Value create(ByteBuffer bb, byte tag) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + Value val = null; + switch(tag) + { + case JdwpConstants.Tag.BYTE: + val = new ByteValue(bb.get()); + break; + case JdwpConstants.Tag.BOOLEAN: + val = new BooleanValue((bb.get() != 0)); + break; + case JdwpConstants.Tag.CHAR: + val = new CharValue(bb.getChar()); + break; + case JdwpConstants.Tag.SHORT: + val = new ShortValue(bb.getShort()); + break; + case JdwpConstants.Tag.INT: + val = new IntValue(bb.getInt()); + break; + case JdwpConstants.Tag.FLOAT: + val = new FloatValue(bb.getFloat()); + break; + case JdwpConstants.Tag.LONG: + val = new LongValue(bb.getLong()); + break; + case JdwpConstants.Tag.DOUBLE: + val = new DoubleValue(bb.getDouble()); + break; + case JdwpConstants.Tag.VOID: + val = new VoidValue(); + break; + case JdwpConstants.Tag.ARRAY: + case JdwpConstants.Tag.THREAD: + case JdwpConstants.Tag.OBJECT: + case JdwpConstants.Tag.THREAD_GROUP: + case JdwpConstants.Tag.CLASS_LOADER: + case JdwpConstants.Tag.CLASS_OBJECT: + ObjectId oid = VMIdManager.getDefault().readObjectId(bb); + val = new ObjectValue(oid.getObject()); + break; + case JdwpConstants.Tag.STRING: + val = new StringValue(JdwpString.readString(bb)); + break; + default: + throw new InvalidTagException(tag); + } + + return val; + } + + /** + * Creates a tag for the type of the class. + * + * @param klass the type to get a tag for + * @return a byte tag representing the class + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + private static byte getTagForClass(Class klass) + throws JdwpInternalErrorException + { + byte tag; + + if (klass.isPrimitive()) + { + if (klass == byte.class) + tag = JdwpConstants.Tag.BYTE; + else if (klass == boolean.class) + tag = JdwpConstants.Tag.BOOLEAN; + else if (klass == char.class) + tag = JdwpConstants.Tag.CHAR; + else if (klass == short.class) + tag = JdwpConstants.Tag.SHORT; + else if (klass == int.class) + tag = JdwpConstants.Tag.INT; + else if (klass == float.class) + tag = JdwpConstants.Tag.FLOAT; + else if (klass == long.class) + tag = JdwpConstants.Tag.LONG; + else if (klass == double.class) + tag = JdwpConstants.Tag.DOUBLE; + else if (klass == void.class) + tag = JdwpConstants.Tag.VOID; + else + throw new JdwpInternalErrorException("Invalid primitive class"); + } + else + { + tag = JdwpConstants.Tag.OBJECT; + } + + return tag; + } + + /** + * Create a value type for an Object of type determined by a Class. This is + * a special case where a value needs to be created, but the value to create + * it for is already in an object, not in a buffer. + * + * @param value the Object to convert to a Value + * @param type the Class type of the object + * @return a new Value representing this object + */ + public static Value createFromObject(Object value, Class type) + { + Value val = null; + + if (type.isPrimitive()) + { + if (type == byte.class) + val = new ByteValue(((Byte) value).byteValue()); + else if (type == boolean.class) + val = new BooleanValue(((Boolean) value).booleanValue()); + else if (type == char.class) + val = new CharValue(((Character) value).charValue()); + else if (type == short.class) + val = new ShortValue(((Short) value).shortValue()); + else if (type == int.class) + val = new IntValue(((Integer) value).intValue()); + else if (type == float.class) + val = new FloatValue(((Float) value).floatValue()); + else if (type == long.class) + val = new LongValue(((Long) value).longValue()); + else if (type == double.class) + val = new DoubleValue(((Double) value).doubleValue()); + else if (type == void.class) + val = new VoidValue(); + } + else + { + if (type.isAssignableFrom(String.class)) + val = new StringValue ((String) value); + else + val = new ObjectValue(value); + } + + return val; + } +} diff --git a/gnu/classpath/jdwp/value/VoidValue.java b/gnu/classpath/jdwp/value/VoidValue.java new file mode 100644 index 000000000..82cded929 --- /dev/null +++ b/gnu/classpath/jdwp/value/VoidValue.java @@ -0,0 +1,82 @@ +/* VoidValue.java -- JDWP wrapper class for a void value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an void value. + * + * @author Kyle Galloway + */ +public class VoidValue + extends Value +{ + /** + * Create a new VoidValue. + */ + public VoidValue () + { + super(JdwpConstants.Tag.VOID); + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return null; + } + + /** + * Write the wrapped void to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + } +} diff --git a/vm/reference/gnu/classpath/jdwp/VMFrame.java b/vm/reference/gnu/classpath/jdwp/VMFrame.java index 3b0b031c2..eec7b63d6 100644 --- a/vm/reference/gnu/classpath/jdwp/VMFrame.java +++ b/vm/reference/gnu/classpath/jdwp/VMFrame.java @@ -40,6 +40,7 @@ exception statement from your version. */ package gnu.classpath.jdwp; import gnu.classpath.jdwp.util.Location; +import gnu.classpath.jdwp.value.Value; /** * Reference implementation of VM hooks for JDWP Frame access. @@ -93,14 +94,14 @@ public class VMFrame * * @param slot the slot containing the variable */ - public native Object getValue(int slot, byte sig); + public native Value getValue(int slot, byte sig); /** * Assigns the given variable to the given value. * @param slot The slot which contains the variable * @param value The value to assign the variable to */ - public native void setValue(int slot, Object value); + public native void setValue(int slot, Value value); /** * Get the thread this frame is in. -- cgit v1.2.1