diff options
author | Keith Seitz <keiths@redhat.com> | 2005-06-14 00:40:55 +0000 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2005-06-14 00:40:55 +0000 |
commit | dc8ae091e38fa3477c2682ca788305d3268831d1 (patch) | |
tree | 88ecebe2eb1af2eb3127c8f2d359c8958c98bbe4 /gnu/classpath/jdwp | |
parent | 06de4a118eb80d5b9441b2027c014f4d59851611 (diff) | |
download | classpath-dc8ae091e38fa3477c2682ca788305d3268831d1.tar.gz |
* gnu/classpath/jdwp/id/ArrayId.java: New file.
* gnu/classpath/jdwp/id/ArrayReferenceTypeId.java: New file.
* gnu/classpath/jdwp/id/ClassLoaderId.java: New file.
* gnu/classpath/jdwp/id/ClassObjectId.java: New file.
* gnu/classpath/jdwp/id/ClassReferenceTypeId.java: New file.
* gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java: New file.
* gnu/classpath/jdwp/id/JdwpId.java: New file.
* gnu/classpath/jdwp/id/ObjectId.java: New file.
* gnu/classpath/jdwp/id/ReferenceTypeId.java: New file.
* gnu/classpath/jdwp/id/StringId.java: New file.
* gnu/classpath/jdwp/id/ThreadGroupId.java: New file.
* gnu/classpath/jdwp/id/ThreadId.java: New file.
* gnu/classpath/jdwp/util/Signature.java: New file.
* gnu/classpath/jdwp/transport/JdwpConnection.java: New file.
* gnu/classpath/jdwp/transport/ITransport.java: New file.
* gnu/classpath/jdwp/transport/SocketTransport.java: New file.
* gnu/classpath/jdwp/transport/TransportFactory.java: New file.
* gnu/classpath/jdwp/transport/TransportException.java: New file.
* gnu/classpath/jdwp/transport/JdwpPacket.java: New file.
* gnu/classpath/jdwp/transport/JdwpCommandPacket.java: New file.
* gnu/classpath/jdwp/transport/JdwpReplyPacket.java: New file.
Diffstat (limited to 'gnu/classpath/jdwp')
21 files changed, 2273 insertions, 0 deletions
diff --git a/gnu/classpath/jdwp/id/ArrayId.java b/gnu/classpath/jdwp/id/ArrayId.java new file mode 100644 index 000000000..bd95b84e5 --- /dev/null +++ b/gnu/classpath/jdwp/id/ArrayId.java @@ -0,0 +1,62 @@ +/* ArrayId.java -- array object IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP array id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ArrayId + extends ObjectId +{ + // Arrays are handled a little differently than other IDs + //public static final Class typeClass = UNDEFINED + + /** + * Constructs a new <code>ArrayId</code> + */ + public ArrayId () + { + super (JdwpConstants.Tag.ARRAY); + } +} diff --git a/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java b/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java new file mode 100644 index 000000000..23cf4e80f --- /dev/null +++ b/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java @@ -0,0 +1,59 @@ +/* ArrayReferenceTypeId.java -- array reference type ids + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A reference type ID representing java arrays + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ArrayReferenceTypeId + extends ReferenceTypeId +{ + /** + * Constructs a new <code>ArrayReferenceTypeId</code> + */ + public ArrayReferenceTypeId () + { + super (JdwpConstants.TypeTag.ARRAY); + } +} diff --git a/gnu/classpath/jdwp/id/ClassLoaderId.java b/gnu/classpath/jdwp/id/ClassLoaderId.java new file mode 100644 index 000000000..1f2b1e468 --- /dev/null +++ b/gnu/classpath/jdwp/id/ClassLoaderId.java @@ -0,0 +1,64 @@ +/* ClassLoaderId.java -- class loader IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP thread id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ClassLoaderId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = ClassLoader.class; + + /** + * Constructs a new <code>ClassLoaderId</code> + */ + public ClassLoaderId () + { + super (JdwpConstants.Tag.CLASS_LOADER); + } +} diff --git a/gnu/classpath/jdwp/id/ClassObjectId.java b/gnu/classpath/jdwp/id/ClassObjectId.java new file mode 100644 index 000000000..cb756fdf1 --- /dev/null +++ b/gnu/classpath/jdwp/id/ClassObjectId.java @@ -0,0 +1,64 @@ +/* ClassObjectId.java -- class object IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP class object id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ClassObjectId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = Class.class; + + /** + * Constructs a new <code>ClassObjectId</code> + */ + public ClassObjectId () + { + super (JdwpConstants.Tag.CLASS_OBJECT); + } +} diff --git a/gnu/classpath/jdwp/id/ClassReferenceTypeId.java b/gnu/classpath/jdwp/id/ClassReferenceTypeId.java new file mode 100644 index 000000000..4f96802a4 --- /dev/null +++ b/gnu/classpath/jdwp/id/ClassReferenceTypeId.java @@ -0,0 +1,59 @@ +/* ClassReferenceTypeId.java -- class reference type ids + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A reference type ID representing java classes + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ClassReferenceTypeId + extends ReferenceTypeId +{ + /** + * Constructs a new <code>ClassReferenceTypeId</code> + */ + public ClassReferenceTypeId () + { + super (JdwpConstants.TypeTag.CLASS); + } +} diff --git a/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java b/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java new file mode 100644 index 000000000..95d5a4896 --- /dev/null +++ b/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java @@ -0,0 +1,59 @@ +/* InterfaceReferenceTypeId.java -- interface reference type ids + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A reference type ID representing java interfaces + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class InterfaceReferenceTypeId + extends ReferenceTypeId +{ + /** + * Constructs a new <code>InterfaceReferenceTypeId</code> + */ + public InterfaceReferenceTypeId () + { + super (JdwpConstants.TypeTag.INTERFACE); + } +} diff --git a/gnu/classpath/jdwp/id/JdwpId.java b/gnu/classpath/jdwp/id/JdwpId.java new file mode 100644 index 000000000..81b6d2659 --- /dev/null +++ b/gnu/classpath/jdwp/id/JdwpId.java @@ -0,0 +1,127 @@ +/* JdwpId.java -- base class for all object ID types + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A baseclass for all object types reported to the debugger + * + * @author Keith Seitz <keiths@redhat.com> + */ +public abstract class JdwpId +{ + /** + * ID assigned to this object + */ + protected long _id; + + /** + * Tag of ID's type (see {@link gnu.classpath.jdwp.JdwpConstants.Tag}) + * for object-like IDs or the type tag (see {@link + * gnu.classpath.JdwpConstants.TypeTag}) for reference type IDs. + */ + private byte _tag; + + /** + * Constructs an empty <code>JdwpId</code> + */ + public JdwpId (byte tag) + { + _tag = tag; + } + + /** + * Sets the id for this object reference + */ + void setId (long id) + { + _id = id; + } + + /** + * Returns the id for this object reference + */ + public long getId () + { + return _id; + } + + /** + * Compares two object ids for equality. Two object ids + * are equal if they point to the same type and contain to + * the same id number. (NOTE: This is a much stricter check + * than is necessary: all <code>JdwpId</code>s have unique + * ids.) + */ + public boolean equals (JdwpId id) + { + return ((id.getClass () == getClass ()) && (id.getId () == getId ())); + } + + /** + * Returns size of this type (used by IDSizes) + */ + public abstract int size (); + + /** + * Writes the contents of this type to the <code>DataOutputStream</code> + * @param outStream the <code>DataOutputStream</code> to use + * @throws IOException when an error occurs on the <code>OutputStream</code> + */ + public abstract void write (DataOutputStream outStream) + throws IOException; + + /** + * Writes the contents of this type to the output stream, preceded + * by a one-byte tag for tagged object IDs or type tag for + * reference type IDs. + * + * @param outStream the <code>DataOutputStream</code> to use + * @throws IOException when an error occurs on the <code>OutputStream</code> + */ + public void writeTagged (DataOutputStream outStream) + throws IOException + { + outStream.writeByte (_tag); + write (outStream); + } +} diff --git a/gnu/classpath/jdwp/id/ObjectId.java b/gnu/classpath/jdwp/id/ObjectId.java new file mode 100644 index 000000000..6bd399fe2 --- /dev/null +++ b/gnu/classpath/jdwp/id/ObjectId.java @@ -0,0 +1,99 @@ +/* ObjectId.java -- object IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A class which represents a JDWP object id for an object + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ObjectId + extends JdwpId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = Object.class; + + /** + * Constructs a new <code>ObjectId</code> + */ + public ObjectId () + { + super (JdwpConstants.Tag.OBJECT); + } + + /** + * Constructs a new <code>ObjectId</code> of the + * given type. + * + * @param tag the tag of this type of object ID + */ + public ObjectId (byte tag) + { + super (tag); + } + + /** + * Returns the size of this id type + */ + public int size () + { + return 8; + } + + /** + * Writes the id to the stream + * + * @param outStream the stream to which to write + * @throws IOException when an error occurs on the <code>OutputStream</code> + */ + public void write (DataOutputStream outStream) + throws IOException + { + // All we need to do is write out our id as an 8-byte integer + outStream.writeLong (_id); + } +} diff --git a/gnu/classpath/jdwp/id/ReferenceTypeId.java b/gnu/classpath/jdwp/id/ReferenceTypeId.java new file mode 100644 index 000000000..63f38af04 --- /dev/null +++ b/gnu/classpath/jdwp/id/ReferenceTypeId.java @@ -0,0 +1,81 @@ +/* ReferenceTypeId.java -- a base class for all reference type IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Base class for reference type IDs. This class usurps + * <code>JdwpId</code>'s tag member for its own use (type tag). + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ReferenceTypeId + extends JdwpId +{ + /** + * Constructor used by {Array,Interface,Class}ReferenceTypeId + */ + public ReferenceTypeId (byte tag) + { + super (tag); + } + + /** + * Returns the size of this ID type + */ + public int size () + { + return 8; + } + + /** + * Outputs the reference type ID to the given output stream + * + * @param outStream the stream to which to write the data + * @throws IOException for errors writing to the stream + */ + public void write (DataOutputStream outStream) + throws IOException + { + outStream.writeLong (_id); + } +} diff --git a/gnu/classpath/jdwp/id/StringId.java b/gnu/classpath/jdwp/id/StringId.java new file mode 100644 index 000000000..9e5b7ce8b --- /dev/null +++ b/gnu/classpath/jdwp/id/StringId.java @@ -0,0 +1,64 @@ +/* StringId.java -- string IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP string id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class StringId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = String.class; + + /** + * Constructs a new <code>StringId</code> + */ + public StringId () + { + super (JdwpConstants.Tag.STRING); + } +} diff --git a/gnu/classpath/jdwp/id/ThreadGroupId.java b/gnu/classpath/jdwp/id/ThreadGroupId.java new file mode 100644 index 000000000..80e8ac500 --- /dev/null +++ b/gnu/classpath/jdwp/id/ThreadGroupId.java @@ -0,0 +1,64 @@ +/* ThreadGroupId.java -- thread group IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP thread group id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ThreadGroupId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = ThreadGroup.class; + + /** + * Constructs a new <code>ThreadGroupId</code> + */ + public ThreadGroupId () + { + super (JdwpConstants.Tag.THREAD_GROUP); + } +} diff --git a/gnu/classpath/jdwp/id/ThreadId.java b/gnu/classpath/jdwp/id/ThreadId.java new file mode 100644 index 000000000..9a719bec9 --- /dev/null +++ b/gnu/classpath/jdwp/id/ThreadId.java @@ -0,0 +1,64 @@ +/* ThreadId.java -- thread IDs + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.id; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * A class which represents a JDWP thread id + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class ThreadId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = Thread.class; + + /** + * Constructs a new <code>ThreadId</code> + */ + public ThreadId () + { + super (JdwpConstants.Tag.THREAD); + } +} diff --git a/gnu/classpath/jdwp/transport/ITransport.java b/gnu/classpath/jdwp/transport/ITransport.java new file mode 100644 index 000000000..16706076f --- /dev/null +++ b/gnu/classpath/jdwp/transport/ITransport.java @@ -0,0 +1,84 @@ +/* ITransport.java -- An interface defining JDWP transports + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.IllegalArgumentException; +import java.util.HashMap; + +/** + * A class representing a transport layer. This class serves as a generic + * interface for all transport types used in the JDWP back-end. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public interface ITransport +{ + /** + * Configure the transport with the given properties + * + * @param properties properties of the transport configuration + * @throws TransportException on configury error + */ + public void configure (HashMap properties) + throws TransportException; + + /** + * Initialize the transport + * + * @throws TransportException on initialization error + */ + public void initialize () + throws TransportException; + + /** + * Get the input stream for the transport + */ + public InputStream getInputStream () + throws IOException; + + /** + * Get the output stream for the transport + */ + public OutputStream getOutputStream () + throws IOException; +} diff --git a/gnu/classpath/jdwp/transport/JdwpCommandPacket.java b/gnu/classpath/jdwp/transport/JdwpCommandPacket.java new file mode 100644 index 000000000..cf193a2ed --- /dev/null +++ b/gnu/classpath/jdwp/transport/JdwpCommandPacket.java @@ -0,0 +1,149 @@ +/* JdwpCommandPacket.java -- JDWP command packet + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +/** + * A class representing a JDWP command packet. + * This class adds command set and command to the packet header + * information in {@link gnu.classpath.jdwp.transport.JdwpPacket} + * and adds additional command packet-specific processing. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class JdwpCommandPacket extends JdwpPacket +{ + /** + * Command set + */ + protected byte _commandSet; + + /** + * Command + */ + protected byte _command; + + // Minimum packet size [excluding super class] + // ( commandSet (1) + command (1) ) + private static final int MINIMUM_LENGTH = 2; + + /** + * Constructs a new <code>JdwpCommandPacket</code> + */ + public JdwpCommandPacket () + { + // Don't assign an id. This constructor is called by + // JdwpPacket.fromBytes, and that will assign a packet id. + } + + /** + * Constructs a new <code>JdwpCommandPacket</code> + * with the given command set and command + * + * @param set the command set + * @param command the command + */ + public JdwpCommandPacket (byte set, byte command) + { + _id = ++_last_id; + _commandSet = set; + _command = command; + } + + /** + * Retuns the length of this packet + */ + public int getLength () + { + return MINIMUM_LENGTH + super.getLength (); + } + + /** + * Returns the command set + */ + public byte getCommandSet () + { + return _commandSet; + } + + /** + * Sets the command set + */ + public void setCommandSet (byte cs) + { + _commandSet = cs; + } + + /** + * Returns the command + */ + public byte getCommand () + { + return _command; + } + + /** + * Sets the command + */ + public void setCommand (byte cmd) + { + _command = cmd; + } + + // Reads command packet data from the given buffer, starting + // at the given offset + protected int myFromBytes (byte[] bytes, int index) + { + int i = 0; + setCommandSet (bytes[index + i++]); + setCommand (bytes[index + i++]); + return i; + } + + // Writes the command packet data into the given buffer + protected int myToBytes (byte[] bytes, int index) + { + // Need to add command set & command + int i = 0; + bytes[index + i++] = getCommandSet (); + bytes[index + i++] = getCommand (); + + return i; + } +} diff --git a/gnu/classpath/jdwp/transport/JdwpConnection.java b/gnu/classpath/jdwp/transport/JdwpConnection.java new file mode 100644 index 000000000..a22bbb9f2 --- /dev/null +++ b/gnu/classpath/jdwp/transport/JdwpConnection.java @@ -0,0 +1,265 @@ +/* JdwpConnection.java -- A JDWP-speaking connection + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +import gnu.classpath.jdwp.Jdwp; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + +/** + * A connection via some transport to some JDWP-speaking entity. + * This is also a thread which handles all communications to/from + * the debugger. While access to the transport layer may be accessed by + * several threads, start-up and initialization should not be allowed + * to occur more than once. + * + * <p>This class is also a thread that is responsible for pulling + * packets off the wire and sticking them in a queue for packet + * processing threads. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class JdwpConnection + extends Thread +{ + // The JDWP handshake + private static final byte[] _HANDSHAKE = {'J', 'D', 'W', 'P', '-', 'H', 'a', 'n', 'd', 's', 'h', 'a', 'k', 'e'}; + + // Transport method + private ITransport _transport; + + // Command queue + private ArrayList _commandQueue; + + // Shutdown flag + private boolean _shutdown; + + // Input stream from transport + private DataInputStream _inStream; + + // Output stream from transprot + private DataOutputStream _outStream; + + /** + * Creates a new <code>JdwpConnection</code> instance + * + * @param transport the transport to use for communications + */ + public JdwpConnection (ITransport transport) + { + _transport = transport; + _commandQueue = new ArrayList (); + _shutdown = false; + } + + /** + * Initializes the connection, including connecting + * to socket or shared memory endpoint + * + * @throws TransportException if initialization fails + */ + public void initialize () + throws TransportException + { + // Initialize transport (connect socket, e.g.) + _transport.initialize (); + + // Do handshake + try + { + _inStream = new DataInputStream (_transport.getInputStream ()); + _outStream = new DataOutputStream (_transport.getOutputStream ()); + _doHandshake (); + } + catch (IOException ioe) + { + throw new TransportException (ioe); + } + } + + /* Does the JDWP handshake -- this should not need synchronization + because this is called by VM startup code, i.e., no packet + processing threads have started yet. */ + private void _doHandshake () + throws IOException + { + // According to the spec, the handshake is always initiated by + // the debugger, regardless of whether the JVM is in client mode or + // server mode. + + // Wait for handshake from debugger + byte[] hshake = new byte[_HANDSHAKE.length]; + _inStream.readFully (hshake, 0, _HANDSHAKE.length); + + if (Arrays.equals (hshake, _HANDSHAKE)) + { + // Send reply handshake + _outStream.write (_HANDSHAKE, 0, _HANDSHAKE.length); + return; + } + else + { + throw new IOException ("invalid JDWP handshake (\"" + hshake + "\")"); + } + } + + /** + * Main run method for the thread. This thread loops waiting for + * packets to be read via the connection. When a packet is complete + * and ready for processing, it places the packet in a queue that can + * be accessed via <code>getPacket</code> + */ + public void run () + { + while (!_shutdown) + { + try + { + _readOnePacket (); + } + catch (IOException ioe) + { + /* IOException can occur for two reasons: + 1. Lost connection with the other side + 2. Transport was shutdown + In either case, we make sure that all of the + back-end gets shutdown. */ + Jdwp.getInstance().shutdown (); + } + catch (Throwable t) + { + System.out.println ("JdwpConnection.run: caught an exception: " + + t); + // Just keep going + } + } + } + + // Reads a single packet from the connection, adding it to the packet + // queue when a complete packet is ready. + private void _readOnePacket () + throws IOException + { + byte[] data = null; + + // Read in the packet + int length = _inStream.readInt (); + if (length < 11) + { + throw new IOException ("JDWP packet length < 11 (" + + length + ")"); + } + + data = new byte[length]; + data[0] = (byte) (length >>> 24); + data[1] = (byte) (length >>> 16); + data[2] = (byte) (length >>> 8); + data[3] = (byte) length; + _inStream.readFully (data, 4, length - 4); + + JdwpPacket packet = JdwpPacket.fromBytes (data); + if (packet != null) + { + synchronized (_commandQueue) + { + _commandQueue.add (packet); + _commandQueue.notifyAll (); + } + } + } + + /** + * Returns a packet from the queue of ready packets + * + * @returns a <code>JdwpPacket</code> ready for processing + * <code>null</code> when shutting down + */ + public JdwpPacket getPacket () + { + synchronized (_commandQueue) + { + while (_commandQueue.isEmpty ()) + { + try + { + _commandQueue.wait (); + } + catch (InterruptedException ie) + { + /* PacketProcessor is interrupted + when shutting down */ + return null; + } + } + + return (JdwpPacket) _commandQueue.remove (0); + } + } + + /** + * Send a packet to the debugger + * + * @param pkt a <code>JdwpPacket</code> to send + * @throws TransportException + */ + public void sendPacket (JdwpPacket pkt) + throws IOException + { + byte[] data = pkt.toBytes (); + _outStream.write (data, 0, data.length); + } + + /** + * Shutdown the connection + */ + public void shutdown () + { + if (!_shutdown) + { + _transport.shutdown (); + _shutdown = true; + interrupt (); + } + } +} diff --git a/gnu/classpath/jdwp/transport/JdwpPacket.java b/gnu/classpath/jdwp/transport/JdwpPacket.java new file mode 100644 index 000000000..1a6a96254 --- /dev/null +++ b/gnu/classpath/jdwp/transport/JdwpPacket.java @@ -0,0 +1,286 @@ +/* JdwpPacket.java -- Base class for JDWP command and reply packets + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +/** + * All command and reply packets in JDWP share + * common header type information: + * + * length (4 bytes) : size of entire packet, including length + * id (4 bytes) : unique packet id + * flags (1 byte) : flag byte + * [command packet stuff | reply packet stuff] + * data (variable) : unique command-/reply-specific data + * + * This class deal with everything except the command- and reply-specific + * data, which get handled in {@link + * gnu.classpath.jdwp.transport.JdwpCommandPacket} and {@link + * gnu.classpath.jdwp.transprot.JdwpReplyPacket}. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public abstract class JdwpPacket +{ + // Last id of packet constructed + protected static int _last_id = 0; + + // JDWP reply packet flag + protected static final int JDWP_FLAG_REPLY = 0x80; + + /** + * Minimum packet size excluding sub-class data + * ( length (4) + id (4) + flags (1) ) + */ + protected static final int MINIMUM_SIZE = 9; + + /** + * Id of command/reply + */ + protected int _id; + + /** + * Packet flags + */ + protected byte _flags; + + /** + * Packet-specific data + */ + protected byte[] _data; + + /** + * Constructor + */ + public JdwpPacket () + { + // By default, DON'T assign an id. This way when a packet + // is constructed from fromBytes, _last_id won't increment (i.e., + // it won't leave holes in the outgoing packet ids). + } + + /** + * Constructs a <code>JdwpPacket</code> with the id + * from the given packet. + * + * @param pkt a packet whose id will be used in this new packet + */ + public JdwpPacket (JdwpPacket pkt) + { + _id = pkt.getId (); + } + + /** + * Returns the packet id + */ + public int getId () + { + return _id; + } + + /** + * Sets the packet id + */ + public void setId (int id) + { + _id = id; + } + + /** + * Returns the packet flags + */ + public byte getFlags () + { + return _flags; + } + + /** + * Sets the packet flags + */ + public void setFlags (byte flags) + { + _flags = flags; + } + + /** + * Gets the command/reply-specific data in this packet + */ + public byte[] getData () + { + return _data; + } + + /** + * Sets the command/reply-specific data in this packet + */ + public void setData (byte[] data) + { + _data = data; + } + + /** + * Returns the length of this entire packet + */ + public int getLength () + { + return MINIMUM_SIZE + (_data == null ? 0 : _data.length); + } + + /** + * Allow subclasses to initialize from data + * + * @param bytes packet data from the wire + * @param index index into <code>bytes</code> to start processing + * @return number of bytes in <code>bytes</code> processed + */ + protected abstract int myFromBytes (byte[] bytes, int index); + + /** + * Convert the given bytes into a <code>JdwpPacket</code>. Uses the + * abstract method <code>myFromBytes</code> to allow subclasses to + * process data. + * + * If the given data does not represent a valid JDWP packet, it returns + * <code>null</code>. + * + * @param bytes packet data from the wire + * @param index index into <code>bytes</code> to start processing + * @return number of bytes in <code>bytes</code> processed + */ + public static JdwpPacket fromBytes (byte[] bytes) + { + int i = 0; + int length = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16 + | (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff)); + int id = 0; + byte flags = 0; + + if (bytes.length == length) + { + id = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16 + | (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff)); + flags = bytes[i++]; + + Class clazz = null; + if (flags == 0) + clazz = JdwpCommandPacket.class; + else if ((flags & JDWP_FLAG_REPLY) != 0) + clazz = JdwpReplyPacket.class; + else + { + // Malformed packet. Discard it. + return null; + } + + JdwpPacket pkt = null; + try + { + pkt = (JdwpPacket) clazz.newInstance (); + } + catch (InstantiationException ie) + { + // Discard packet + return null; + } + catch (IllegalAccessException iae) + { + // Discard packet + return null; + } + + pkt.setId (id); + pkt.setFlags (flags); + + i += pkt.myFromBytes (bytes, i); + byte[] data = new byte[length - i]; + System.arraycopy (bytes, i, data, 0, data.length); + pkt.setData (data); + + return pkt; + } + + return null; + } + + // Put subclass information into bytes + protected abstract int myToBytes (byte[] bytes, int index); + + // Convert this packet to it byte representation (ready to send on the wire) + // NOTE: All integers should be big-endian. + public byte[] toBytes () + { + // Allocate a new array to hold contents of packet + int length = getLength (); + byte[] bytes = new byte[length]; + + int i = 0; + + // + // Packet layout: length, id, flags, packet-specific, data (optional) + // + + // length + bytes[i++] = (byte) (length >>> 24); + bytes[i++] = (byte) (length >>> 16); + bytes[i++] = (byte) (length >>> 8); + bytes[i++] = (byte) length; + + // id + bytes[i++] = (byte) (getId () >>> 24); + bytes[i++] = (byte) (getId () >>> 16); + bytes[i++] = (byte) (getId () >>> 8); + bytes[i++] = (byte) getId (); + + // flag + bytes[i++] = getFlags (); + + // packet-specific stuff + i += myToBytes (bytes, i); + + // data (if any) + byte[] data = getData (); + if (data.length > 0 && i < length) + { + // Would it pay to be over cautious? + System.arraycopy (data, 0, bytes, i, data.length); + } + + return bytes; + } +} diff --git a/gnu/classpath/jdwp/transport/JdwpReplyPacket.java b/gnu/classpath/jdwp/transport/JdwpReplyPacket.java new file mode 100644 index 000000000..1aa2dd344 --- /dev/null +++ b/gnu/classpath/jdwp/transport/JdwpReplyPacket.java @@ -0,0 +1,127 @@ +/* JdwpReplyPacket.java -- JDWP reply packet + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +/** + * A class represents a JDWP reply packet. + * This class adds an error code to the packet header information + * in {@link gnu.classpath.transport.JdwpPacket} and adds additional + * reply packet-specific processing. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class JdwpReplyPacket extends JdwpPacket +{ + /** + * Error code + */ + protected short _errorCode; + + // Minimum packet size [excluding super class] ( errorCode (2) ) + private static final int MINIMUM_LENGTH = 2; + + /** + * Constructs a <code>JdwpReplyPacket</code>. + */ + public JdwpReplyPacket () + { + // Don't assign a packet id. This is called by JdwpPacket.fromBytes + // which assigns a packet id. (Not that a VM would do that...) + } + + /** + * Constructs a <code>JdwpReplyPacket</code> with the + * id from the given packet and error code + * + * @param pkt the packet whose id this packet will use + * @param errorCode the error code + */ + public JdwpReplyPacket (JdwpPacket pkt, short errorCode) + { + super (pkt); + _flags = (byte) JDWP_FLAG_REPLY; + _errorCode = errorCode; + } + + /** + * Returns the length of this packet + */ + public int getLength () + { + return MINIMUM_LENGTH + super.getLength (); + } + + /** + * Returns the error code + */ + public short getErrorCode () + { + return _errorCode; + } + + /** + * Sets the error code + */ + public void setErrorCode (short ec) + { + _errorCode = ec; + } + + // Reads command packet data from the given buffer, starting + // at the given offset + protected int myFromBytes (byte[] bytes, int index) + { + int i = 0; + setErrorCode ((short) ((bytes[index + i++] & 0xff) << 8 + | (bytes[index + i++] & 0xff))); + return i; + } + + // Writes the command packet data into the given buffer + protected int myToBytes (byte[] bytes, int index) + { + // Need to add error code + int i = 0; + bytes[index + i++] = (byte) (getErrorCode () >>> 8); + bytes[index + i++] = (byte) getErrorCode (); + + return i; + } +} diff --git a/gnu/classpath/jdwp/transport/SocketTransport.java b/gnu/classpath/jdwp/transport/SocketTransport.java new file mode 100644 index 000000000..3be193a05 --- /dev/null +++ b/gnu/classpath/jdwp/transport/SocketTransport.java @@ -0,0 +1,171 @@ +/* SocketTransport.java -- a socket transport + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +import gnu.classpath.jdwp.transport.ITransport; +import gnu.classpath.jdwp.transport.TransportException; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.HashMap; + +import javax.net.ServerSocketFactory; +import javax.net.SocketFactory; + +/** + * A socket-based transport. This transport uses + * configury string that looks like "name=dt_socket, + * address=localhost:1234,server=y". + * + * @author Keith Seitz <keiths@redhat.com> + */ +class SocketTransport + implements ITransport +{ + /** + * Name of this transport + */ + public static final String NAME = "dt_socket"; + + // Configure properties + private static final String _PROPERTY_ADDRESS = "address"; + private static final String _PROPERTY_SERVER = "server"; + + // Port number + private int _port; + + // Host name + private String _host; + + // Are we acting as a server? + private boolean _server = false; + + // Socket + private Socket _socket; + + /** + * Setup the connection configuration from the given properties + * + * @param properties the properties of the JDWP session + * @throws TransportException for any configury errors + */ + public void configure (HashMap properties) + throws TransportException + { + // Get address [form: "hostname:port"] + String p = (String) properties.get (_PROPERTY_ADDRESS); + if (p != null) + { + String[] s = p.split (":"); + if (s.length == 2) + { + _host = s[0]; + _port = Integer.parseInt (s[1]); + } + } + + // Get server [form: "y" or "n"] + p = (String) properties.get (_PROPERTY_SERVER); + if (p != null) + { + if (p.toLowerCase().equals ("y")) + _server = true; + } + } + + /** + * Initialize this socket connection. This includes + * connecting to the host (or listening for it). + * + * @throws TransportException if a transport-related error occurs + */ + public void initialize () + throws TransportException + { + try + { + if (_server) + { + // Get a server socket + ServerSocketFactory ssf = ServerSocketFactory.getDefault (); + ServerSocket ss = ssf.createServerSocket (_port, 1); + _socket = ss.accept (); + } + else + { + // Get a client socket (the factory will connect it) + SocketFactory sf = SocketFactory.getDefault (); + _socket = sf.createSocket (_host, _port); + } + } + catch (IOException ioe) + { + // This will grab UnknownHostException, too. + throw new TransportException (ioe); + } + } + + /** + * Returns an <code>InputStream</code> for the transport + * + * @throws IOException if an I/O error occurs creating the stream + * or the socket is not connected + */ + public InputStream getInputStream () + throws IOException + { + return _socket.getInputStream (); + } + + /** + * Returns an <code>OutputStream</code> for the transport + * + * @throws IOException if an I/O error occurs creating the stream + * or the socket is not connected + */ + public OutputStream getOutputStream () + throws IOException + { + return _socket.getOutputStream (); + } +} diff --git a/gnu/classpath/jdwp/transport/TransportException.java b/gnu/classpath/jdwp/transport/TransportException.java new file mode 100644 index 000000000..7a7afe35a --- /dev/null +++ b/gnu/classpath/jdwp/transport/TransportException.java @@ -0,0 +1,75 @@ +/* TransportException.java -- Exception for transport configury errors + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +/** + * A transport configury or initialization exception thrown by + * JDWP transports. This class is a generic exception class + * that the different transport layers use to report transport-specific + * exceptions that may occur (which could be very different from + * one transport to the next.). + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class TransportException + extends Exception +{ + /** + * Constructs a <code>TransportException</code> with the + * given message + * + * @param message a message describing the exception + */ + public TransportException (String message) + { + super (message); + } + + /** + * Constructs a <code>TransportException</code> with the + * given <code>Throwable</code> root cause + * + * @param t the cause of the exception + */ + public TransportException (Throwable t) + { + super (t); + } +} diff --git a/gnu/classpath/jdwp/transport/TransportFactory.java b/gnu/classpath/jdwp/transport/TransportFactory.java new file mode 100644 index 000000000..7f617863e --- /dev/null +++ b/gnu/classpath/jdwp/transport/TransportFactory.java @@ -0,0 +1,115 @@ +/* TransportFactory.java -- Factory for transports + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.transport; + +import java.util.HashMap; + +/** + * A factory class that constructs transports for use by + * the JDWP back-end. + * + * @author Keith Seitz <keiths@redhat.com> + */ +public class TransportFactory +{ + // Keyword in configspec that specifies transport method + private static final String _TRANSPORT_PROPERTY = "transport"; + + // A single transport method mapping + private static class TransportMethod + { + String name; + Class clazz; + public TransportMethod (String name, Class clazz) + { + this.name = name; + this.clazz = clazz; + } + } + + // List of all supported transport methods + private static TransportMethod[] _transportMethods = new TransportMethod[] + { + new TransportMethod (SocketTransport.NAME, SocketTransport.class) + //new TransportMethod (ShmemTransport.NAME, ShmemTransport.class) + }; + + /** + * Get a transport configured as specified in the properties + * + * @param properties a <code>HashMap</code> specifying the JDWP + * configuration properties + * @returns the created and configured transport + * @throws TransportException for invalid configurations + */ + public static ITransport newInstance (HashMap properties) + throws TransportException + { + String name = null; + if (properties != null) + name = (String) properties.get (_TRANSPORT_PROPERTY); + if (name == null) + throw new TransportException ("no transport specified"); + + for (int i = 0; i < _transportMethods.length; ++i) + { + if (_transportMethods[i].name.equals (name)) + { + try + { + ITransport t; + t = (ITransport) _transportMethods[i].clazz.newInstance (); + t.configure (properties); + return t; + } + catch (TransportException te) + { + throw te; + } + catch (Exception e) + { + throw new TransportException (e); + } + } + } + + throw new TransportException ("transport \"" + name + "\" not found"); + } +} diff --git a/gnu/classpath/jdwp/util/Signature.java b/gnu/classpath/jdwp/util/Signature.java new file mode 100644 index 000000000..648a8404d --- /dev/null +++ b/gnu/classpath/jdwp/util/Signature.java @@ -0,0 +1,135 @@ +/* Signature.java -- utility class to compute class and method signatures + Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.util; + +import java.lang.reflect.Method; + +/** + * A class to compute class and method signatures. + * + * @author Tom Tromey (tromey@redhat.com) + * @author Keith Seitz (keiths@redhat.com) + */ +public class Signature +{ + /** + * Computes the class signature, i.e., java.lang.String.class + * returns "Ljava/lang/String;". + * + * @param theClass the class for which to compute the signature + * @return the class's type signature + */ + public static String computeClassSignature (Class theClass) + { + StringBuffer sb = new StringBuffer (); + _addToSignature (sb, theClass); + return sb.toString (); + } + + /** + * Computes the method signature, i.e., java.lang.String.split (String, int) + * returns "(Ljava/lang/String;I)[Ljava/lang/String;" + * + * @param method the method for which to compute the signature + * @return the method's type signature + */ + public static String computeMethodSignature (Method method) + { + return _computeSignature (method.getReturnType (), + method.getParameterTypes ()); + } + + private static String _computeSignature (Class returnType, + Class[] paramTypes) + { + StringBuffer sb = new StringBuffer ("("); + if (paramTypes != null) + { + for (int i = 0; i < paramTypes.length; ++i) + _addToSignature (sb, paramTypes[i]); + } + sb.append (")"); + _addToSignature (sb, returnType); + return sb.toString(); + } + + private static void _addToSignature (StringBuffer sb, Class k) + { + // For some reason there's no easy way to get the signature of a + // class. + if (k.isPrimitive ()) + { + if (k == void.class) + sb.append('V'); + else if (k == boolean.class) + sb.append('Z'); + else if (k == byte.class) + sb.append('B'); + else if (k == char.class) + sb.append('C'); + else if (k == short.class) + sb.append('S'); + else if (k == int.class) + sb.append('I'); + else if (k == float.class) + sb.append('F'); + else if (k == double.class) + sb.append('D'); + else if (k == long.class) + sb.append('J'); + return; + } + + String name = k.getName (); + int len = name.length (); + sb.ensureCapacity (len); + if (! k.isArray ()) + sb.append('L'); + for (int i = 0; i < len; ++i) + { + char c = name.charAt (i); + if (c == '.') + c = '/'; + sb.append (c); + } + if (! k.isArray ()) + sb.append(';'); + } +} |