diff options
Diffstat (limited to 'gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport')
8 files changed, 1344 insertions, 0 deletions
diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/ITransport.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/ITransport.java new file mode 100644 index 000000000..cf5542560 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/ITransport.java @@ -0,0 +1,88 @@ +/* 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., 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.transport; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +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; + + /** + * Shutdown the transport + */ + public void shutdown (); + + /** + * 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/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpCommandPacket.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpCommandPacket.java new file mode 100644 index 000000000..e99159aad --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/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., 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.transport; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * 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 void myWrite (DataOutputStream dos) + throws IOException + { + dos.writeByte (getCommandSet ()); + dos.writeByte (getCommand ()); + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpConnection.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpConnection.java new file mode 100644 index 000000000..44158aa26 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpConnection.java @@ -0,0 +1,307 @@ +/* JdwpConnection.java -- A JDWP-speaking connection + Copyright (C) 2005, 2006, 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.transport; + +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.event.EventRequest; + +import java.io.ByteArrayOutputStream; +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; + + // A buffer used to construct the packet data + private ByteArrayOutputStream _bytes; + + // A DataOutputStream for the byte buffer + private DataOutputStream _doStream; + + /** + * Creates a new <code>JdwpConnection</code> instance + * + * @param transport the transport to use for communications + */ + public JdwpConnection (ThreadGroup group, ITransport transport) + { + super (group, "JDWP connection thread"); + _transport = transport; + _commandQueue = new ArrayList (); + _shutdown = false; + _bytes = new ByteArrayOutputStream (); + _doStream = new DataOutputStream (_bytes); + } + + /** + * 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 () + { + // Notify initialization thread (gnu.classpath.jdwp.Jdwp) that + // the JdwpConnection thread is ready. + Jdwp.getDefault().subcomponentInitialized (); + + 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.getDefault().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 IOException + */ + public void sendPacket (JdwpPacket pkt) + throws IOException + { + pkt.write (_outStream); + } + + /** + * Send an event notification to the debugger. Note that this + * method will only send out one notification: all the events + * are passed in a single Event.COMPOSITE packet. + * + * @param requests debugger requests for events + * @param events the events to send + * @param suspendPolicy the suspend policy enforced by the VM + * @throws IOException + */ + public void sendEvents(EventRequest[] requests, Event[] events, + byte suspendPolicy) + throws IOException + { + JdwpPacket pkt; + + synchronized (_bytes) + { + _bytes.reset (); + pkt = Event.toPacket (_doStream, events, requests, suspendPolicy); + pkt.setData (_bytes.toByteArray ()); + } + + sendPacket (pkt); + } + + /** + * Shutdown the connection + */ + public void shutdown () + { + if (!_shutdown) + { + _transport.shutdown (); + _shutdown = true; + interrupt (); + } + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpPacket.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpPacket.java new file mode 100644 index 000000000..a3afe8421 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpPacket.java @@ -0,0 +1,277 @@ +/* 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., 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.transport; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * 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.transport.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 + * @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 onto the stream + * + * @param dos the output stream to which to write + */ + protected abstract void myWrite (DataOutputStream dos) + throws IOException; + + /** + * Writes the packet to the output stream + * + * @param dos the output stream to which to write the packet + */ + public void write (DataOutputStream dos) + throws IOException + { + // length + int length = getLength (); + dos.writeInt (length); + + // ID + dos.writeInt (getId ()); + + // flag + dos.writeByte (getFlags ()); + + // packet-specific stuff + myWrite (dos); + + // data (if any) + byte[] data = getData (); + if (data != null && data.length > 0) + dos.write (data, 0, data.length); + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpReplyPacket.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpReplyPacket.java new file mode 100644 index 000000000..d060dec99 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/JdwpReplyPacket.java @@ -0,0 +1,137 @@ +/* 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., 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.transport; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A class represents a JDWP reply packet. + * This class adds an error code to the packet header information + * in {@link gnu.classpath.jdwp.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) + { + this(pkt); + _errorCode = errorCode; + } + + /** + * Constructs a <code>JdwpReplyPacket</code> with the + * id from the given packet and an empty error code + * + * @param pkt the packet whose id this packet will use + */ + public JdwpReplyPacket (JdwpPacket pkt) + { + super (pkt); + _flags = (byte) JDWP_FLAG_REPLY; + } + + /** + * 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 void myWrite (DataOutputStream dos) + throws IOException + { + dos.writeShort (getErrorCode ()); + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/SocketTransport.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/SocketTransport.java new file mode 100644 index 000000000..3b0a8e7fe --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/SocketTransport.java @@ -0,0 +1,196 @@ +/* SocketTransport.java -- a socket transport + Copyright (C) 2005, 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.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 server [form: "y" or "n"] + String p = (String) properties.get(_PROPERTY_SERVER); + if (p != null) + { + if (p.toLowerCase().equals("y")) + _server = true; + } + + // Get address [form: "hostname:port"] + p = (String) properties.get(_PROPERTY_ADDRESS); + if (p != null) + { + String[] s = p.split(":"); + if (s.length == 1) + { + // Port number only. Assume "localhost" + _port = Integer.parseInt(s[0]); + _host = "localhost"; + } + else + { + if (s[0].length() == 0) + _host = "localhost"; + else + _host = s[0]; + _port = Integer.parseInt(s[1]); + } + } + } + + /** + * 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); + } + } + + /** + * Shutdown the socket. This could cause SocketExceptions + * for anyone blocked on socket i/o + */ + public void shutdown () + { + try + { + _socket.close (); + } + catch (Throwable t) + { + // We don't really care about errors at this point + } + } + + /** + * 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/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/TransportException.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/TransportException.java new file mode 100644 index 000000000..057422a87 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/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., 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.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/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/TransportFactory.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/jdwp/transport/TransportFactory.java new file mode 100644 index 000000000..480fb3629 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/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., 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.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"); + } +} |