diff options
Diffstat (limited to 'libjava/classpath/gnu/classpath/jdwp')
111 files changed, 14152 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/classpath/jdwp/Jdwp.java b/libjava/classpath/gnu/classpath/jdwp/Jdwp.java new file mode 100644 index 000000000..e90a2c762 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/Jdwp.java @@ -0,0 +1,416 @@ +/* Jdwp.java -- Virtual machine to JDWP back-end programming interface + 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; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.event.EventManager; +import gnu.classpath.jdwp.event.EventRequest; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.processor.PacketProcessor; +import gnu.classpath.jdwp.transport.ITransport; +import gnu.classpath.jdwp.transport.JdwpConnection; +import gnu.classpath.jdwp.transport.TransportException; +import gnu.classpath.jdwp.transport.TransportFactory; + +import java.io.IOException; +import java.security.AccessController; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Main interface from the virtual machine to the JDWP back-end. + * + * The thread created by this class is only used for initialization. + * Once it exits, the JDWP backend is fully initialized. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class Jdwp + extends Thread +{ + // The single instance of the back-end + private static Jdwp _instance = null; + + /** + * Are we debugging? Only true if debugging + * *and* initialized. + */ + public static boolean isDebugging = false; + + // Packet processor + private PacketProcessor _packetProcessor; + private Thread _ppThread; + + // JDWP configuration properties + private HashMap _properties; + + // The suspend property of the configure string + // (-Xrunjdwp:..suspend=<boolean>) + private static final String _PROPERTY_SUSPEND = "suspend"; + + // Connection to debugger + private JdwpConnection _connection; + + // Are we shutting down the current session? + private boolean _shutdown; + + // A thread group for the JDWP threads + private ThreadGroup _group; + + // Initialization synchronization + private Object _initLock = new Object (); + private int _initCount = 0; + + /** + * constructor + */ + public Jdwp () + { + _shutdown = false; + _instance = this; + } + + /** + * Returns the JDWP back-end, creating an instance of it + * if one does not already exist. + */ + public static Jdwp getDefault () + { + return _instance; + } + + /** + * Get the thread group used by JDWP threads + * + * @return the thread group + */ + public ThreadGroup getJdwpThreadGroup() + { + return _group; + } + + /** + * Should the virtual machine suspend on startup? + */ + public static boolean suspendOnStartup () + { + Jdwp jdwp = getDefault (); + if (jdwp != null) + { + String suspend = (String) jdwp._properties.get (_PROPERTY_SUSPEND); + if (suspend != null && suspend.equals ("y")) + return true; + } + + return false; + } + + /** + * Configures the back-end + * + * @param configArgs a string of configury options + */ + public void configure (String configArgs) + { + _processConfigury (configArgs); + } + + // A helper function to initialize the transport layer + private void _doInitialization () + throws TransportException + { + _group = new ThreadGroup ("JDWP threads"); + // initialize transport + ITransport transport = TransportFactory.newInstance (_properties); + _connection = new JdwpConnection (_group, transport); + _connection.initialize (); + _connection.start (); + + // Create processor + _packetProcessor = new PacketProcessor (_connection); + _ppThread = new Thread (_group, new Runnable () + { + public void run () + { + AccessController.doPrivileged (_packetProcessor); + } + }, "packet processor"); + _ppThread.start (); + } + + /** + * Shutdown the JDWP back-end + * + * NOTE: This does not quite work properly. See notes in + * run() on this subject (catch of InterruptedException). + */ + public void shutdown () + { + if (!_shutdown) + { + _packetProcessor.shutdown (); + _ppThread.interrupt (); + _connection.shutdown (); + _shutdown = true; + isDebugging = false; + + /* FIXME: probably need to check state of user's + program -- if it is suspended, we need to either + resume or kill them. */ + + interrupt (); + } + } + + /** + * Notify the debugger of an event. This method should not + * be called if debugging is not active (but it would not + * cause any harm). Places where event notifications occur + * should check isDebugging before doing anything. + * + * The event is filtered through the event manager before being + * sent. + * + * @param event the event to report + */ + public static void notify(Event event) + { + Jdwp jdwp = getDefault(); + if (jdwp != null) + { + EventManager em = EventManager.getDefault(); + EventRequest[] requests = em.getEventRequests(event); + for (int i = 0; i < requests.length; ++i) + { + try + { + sendEvent(requests[i], event); + jdwp._enforceSuspendPolicy(requests[i].getSuspendPolicy()); + } + catch (Exception e) + { + /* Really not much we can do. For now, just print out + a warning to the user. */ + System.out.println ("Jdwp.notify: caught exception: " + e); + } + } + } + } + + /** + * Notify the debugger of "co-located" events. This method should + * not be called if debugging is not active (but it would not + * cause any harm). Places where event notifications occur + * should check isDebugging before doing anything. + * + * The events are filtered through the event manager before being + * sent. + * + * @param events the events to report + */ + public static void notify(Event[] events) + { + Jdwp jdwp = getDefault(); + + if (jdwp != null) + { + byte suspendPolicy = JdwpConstants.SuspendPolicy.NONE; + EventManager em = EventManager.getDefault(); + ArrayList allEvents = new ArrayList (); + ArrayList allRequests = new ArrayList (); + for (int i = 0; i < events.length; ++i) + { + EventRequest[] r = em.getEventRequests(events[i]); + for (int j = 0; j < r.length; ++j) + { + /* This is hacky, but it's not clear whether this + can really happen, and if it does, what should + occur. */ + allEvents.add (events[i]); + allRequests.add (r[j]); + + // Perhaps this is overkill? + if (r[j].getSuspendPolicy() > suspendPolicy) + suspendPolicy = r[j].getSuspendPolicy(); + } + } + + try + { + Event[] e = new Event[allEvents.size()]; + allEvents.toArray(e); + EventRequest[] r = new EventRequest[allRequests.size()]; + allRequests.toArray(r); + sendEvents(r, e, suspendPolicy); + jdwp._enforceSuspendPolicy(suspendPolicy); + } + catch (Exception e) + { + /* Really not much we can do. For now, just print out + a warning to the user. */ + System.out.println ("Jdwp.notify: caught exception: " + e); + } + } + } + + /** + * Sends the event to the debugger. + * + * This method bypasses the event manager's filtering. + * + * @param request the debugger request for the event + * @param event the event to send + * @throws IOException if a communications failure occurs + */ + public static void sendEvent (EventRequest request, Event event) + throws IOException + { + sendEvents (new EventRequest[] { request }, new Event[] { event }, + request.getSuspendPolicy()); + } + + /** + * Sends the events to the debugger. + * + * This method bypasses the event manager's filtering. + * + * @param requests list of debugger requests for the events + * @param events the events to send + * @param suspendPolicy the suspendPolicy enforced by the VM + * @throws IOException if a communications failure occurs + */ + public static void sendEvents (EventRequest[] requests, Event[] events, + byte suspendPolicy) + throws IOException + { + Jdwp jdwp = getDefault(); + if (jdwp != null) + { + synchronized (jdwp._connection) + { + jdwp._connection.sendEvents (requests, events, suspendPolicy); + } + } + } + + // Helper function to enforce suspend policies on event notification + private void _enforceSuspendPolicy (byte suspendPolicy) + throws JdwpException + { + switch (suspendPolicy) + { + case EventRequest.SUSPEND_NONE: + // do nothing + break; + + case EventRequest.SUSPEND_THREAD: + VMVirtualMachine.suspendThread (Thread.currentThread ()); + break; + + case EventRequest.SUSPEND_ALL: + VMVirtualMachine.suspendAllThreads (); + break; + } + } + + /** + * Allows subcomponents to specify that they are + * initialized. + * + * Subcomponents include JdwpConnection and PacketProcessor. + */ + public void subcomponentInitialized () + { + synchronized (_initLock) + { + ++_initCount; + _initLock.notify (); + } + } + + public void run () + { + try + { + _doInitialization (); + + /* We need a little internal synchronization here, so that + when this thread dies, the back-end will be fully initialized, + ready to start servicing the VM and debugger. */ + synchronized (_initLock) + { + while (_initCount != 2) + _initLock.wait (); + } + _initLock = null; + } + catch (Throwable t) + { + System.out.println ("Exception in JDWP back-end: " + t); + System.exit (1); + } + + /* Force creation of the EventManager. If the event manager + has not been created when isDebugging is set, it is possible + that the VM will call Jdwp.notify (which uses EventManager) + while the EventManager is being created (or at least this is + a problem with gcj/gij). */ + EventManager.getDefault(); + + // Now we are finally ready and initialized + isDebugging = true; + } + + // A helper function to process the configure string "-Xrunjdwp:..." + private void _processConfigury (String configString) + { + // Loop through configuration arguments looking for a + // transport name + _properties = new HashMap (); + String[] options = configString.split (","); + for (int i = 0; i < options.length; ++i) + { + String[] property = options[i].split ("="); + if (property.length == 2) + _properties.put (property[0], property[1]); + // ignore malformed options + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/JdwpConstants.java b/libjava/classpath/gnu/classpath/jdwp/JdwpConstants.java new file mode 100644 index 000000000..80dd3f73a --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/JdwpConstants.java @@ -0,0 +1,901 @@ +/* JdwpConstants.java -- Constants defined by JDWP 1.4 specification + 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; + +/** + * Constants defined by JDWP specification. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class JdwpConstants +{ + public static final class Version + { + public static final int MAJOR = 1; + public static final int MINOR = 4; + } + + //////////////////////////////////////// + // Commands/Sets // + //////////////////////////////////////// + + public static final class CommandSet + { + public static final class VirtualMachine + { + public static final byte CS_VALUE = 1; + + // commands + public static final byte VERSION = 1; + public static final byte CLASSES_BY_SIGNATURE = 2; + public static final byte ALL_CLASSES = 3; + public static final byte ALL_THREADS = 4; + public static final byte TOP_LEVEL_THREAD_GROUPS = 5; + public static final byte DISPOSE = 6; + public static final byte IDSIZES = 7; + public static final byte SUSPEND = 8; + public static final byte RESUME = 9; + public static final byte EXIT = 10; + public static final byte CREATE_STRING = 11; + public static final byte CAPABILITIES = 12; + public static final byte CLASS_PATHS = 13; + public static final byte DISPOSE_OBJECTS = 14; + public static final byte HOLD_EVENTS = 15; + public static final byte RELEASE_EVENTS = 16; + public static final byte CAPABILITIES_NEW = 17; + public static final byte REDEFINE_CLASSES = 18; + public static final byte SET_DEFAULT_STRATUM = 19; + public static final byte ALL_CLASSES_WITH_GENERIC = 20; + } + + public static final class ReferenceType + { + public static final byte CS_VALUE = 2; + + // commands + public static final byte SIGNATURE= 1; + public static final byte CLASS_LOADER= 2; + public static final byte MODIFIERS = 3; + public static final byte FIELDS = 4; + public static final byte METHODS = 5; + public static final byte GET_VALUES = 6; + public static final byte SOURCE_FILE = 7; + public static final byte NESTED_TYPES = 8; + public static final byte STATUS = 9; + public static final byte INTERFACES= 10; + public static final byte CLASS_OBJECT = 11; + public static final byte SOURCE_DEBUG_EXTENSION = 12; + public static final byte SIGNATURE_WITH_GENERIC = 13; + public static final byte FIELDS_WITH_GENERIC = 14; + public static final byte METHODS_WITH_GENERIC = 15; + } + + public static final class ClassType + { + public static final byte CS_VALUE = 3; + + // commands + public static final byte SUPERCLASS = 1; + public static final byte SET_VALUES = 2; + public static final byte INVOKE_METHOD = 3; + public static final byte NEW_INSTANCE = 4; + } + + public static final class ArrayType + { + public static final byte CS_VALUE = 4; + + // commands + public static final byte NEW_INSTANCE = 1; + } + + public static final class InterfaceType + { + public static final byte CS_VALUE = 5; + + // commands + } + + public static final class Method + { + public static final byte CS_VALUE = 6; + + // commands + public static final byte LINE_TABLE = 1; + public static final byte VARIABLE_TABLE = 2; + public static final byte BYTE_CODES = 3; + public static final byte IS_OBSOLETE = 4; + public static final byte VARIABLE_TABLE_WITH_GENERIC = 5; + } + + public static final class Field + { + public static final byte CS_VALUE = 8; + + // commands + } + + public static final class ObjectReference + { + public static final byte CS_VALUE = 9; + + // commands + public static final byte REFERENCE_TYPE = 1; + public static final byte GET_VALUES = 2; + public static final byte SET_VALUES = 3; + public static final byte MONITOR_INFO = 5; + public static final byte INVOKE_METHOD = 6; + public static final byte DISABLE_COLLECTION = 7; + public static final byte ENABLE_COLLECTION = 8; + public static final byte IS_COLLECTED = 9; + } + + public static final class StringReference + { + public static final byte CS_VALUE = 10; + + // commands + public static final byte VALUE = 1; + } + + public static final class ThreadReference + { + public static final byte CS_VALUE = 11; + + // commands + public static final byte NAME = 1; + public static final byte SUSPEND = 2; + public static final byte RESUME = 3; + public static final byte STATUS = 4; + public static final byte THREAD_GROUP = 5; + public static final byte FRAMES = 6; + public static final byte FRAME_COUNT = 7; + public static final byte OWNED_MONITORS = 8; + public static final byte CURRENT_CONTENDED_MONITOR = 9; + public static final byte STOP = 10; + public static final byte INTERRUPT = 11; + public static final byte SUSPEND_COUNT = 12; + } + + public static final class ThreadGroupReference + { + public static final byte CS_VALUE = 12; + + // commands + public static final byte NAME = 1; + public static final byte PARENT = 2; + public static final byte CHILDREN = 3; + } + + public static final class ArrayReference + { + public static final byte CS_VALUE = 13; + + // commands + public static final byte LENGTH = 1; + public static final byte GET_VALUES = 2; + public static final byte SET_VALUES = 3; + } + + public static final class ClassLoaderReference + { + public static final byte CS_VALUE = 14; + + // commands + public static final byte VISIBLE_CLASSES = 1; + } + + public static final class EventRequest + { + public static final byte CS_VALUE = 15; + + // commands + public static final byte SET = 1; + public static final byte CLEAR = 2; + public static final byte CLEAR_ALL_BREAKPOINTS = 3; + } + + public static final class StackFrame + { + public static final byte CS_VALUE = 16; + + // commands + public static final byte GET_VALUES = 1; + public static final byte SET_VALUES = 2; + public static final byte THIS_OBJECT = 3; + public static final byte POP_FRAMES = 4; + } + + public static final class ClassObjectReference + { + public static final byte CS_VALUE = 17; + + // commands + public static final byte REFLECTED_TYPE = 1; + } + + public static final int MAXIMUM = ClassObjectReference.CS_VALUE; + + public static final class Event + { + public static final byte CS_VALUE = 64; + + // commands + public static final byte COMPOSITE = 100; + } + } + + //////////////////////////////////////// + // Constants // + //////////////////////////////////////// + + /* + * Error constants + */ + public static final class Error + { + /** + * No error has occurred + */ + public static final short NONE = 0; + + /** + * Passed thread is null, is not a valid thread or has exited + */ + public static final short INVALID_THREAD = 10; + + /** + * Thread group invalid + */ + public static final short INVALID_THREAD_GROUP = 11; + + /** + * Invalid priority + */ + public static final short INVALID_PRIORITY = 12; + + /** + * Specified thread has not been suspended by an event + */ + public static final short THREAD_NOT_SUSPENDED = 13; + + /** + * Thread already suspended + */ + public static final short THREAD_SUSPENDED = 14; + + /** + * Reference type has been unloaded and garbage collected + */ + public static final short INVALID_OBJECT = 20; + + /** + * Invalid class + */ + public static final short INVALID_CLASS = 21; + + /** + * Class has been loaded but not yet prepared + */ + public static final short CLASS_NOT_PREPARED = 22; + + /** + * Invalid method + */ + public static final short INVALID_METHODID = 23; + + /** + * Invalid location + */ + public static final short INVALID_LOCATION = 24; + + /** + * Invalid field + */ + public static final short INVALID_FIELDID = 25; + + /** + * Invaliid frame + */ + public static final short INVALID_FRAMEID = 30; + + /** + * There are no more Java or JNI frames on the call stack + */ + public static final short NO_MORE_FRAMES = 31; + + /** + * Information about the frame is not available + */ + public static final short OPAQUE_FRAME = 32; + + /** + * Operation can only be performed on current frame + */ + public static final short NOT_CURRENT_FRAME = 33; + + /** + * Variable is not an appropriate type for the function used + */ + public static final short TYPE_MISMATCH = 34; + + /** + * Invalid slot + */ + public static final short INVALID_SLOT = 35; + + /** + * Item already set + */ + public static final short DUPLICATE = 40; + + /** + * Desired element not found + */ + public static final short NOT_FOUND = 41; + + /** + * Invalid monitor + */ + public static final short INVALID_MONITOR = 50; + + /** + * Thread doesn't own the monitor + */ + public static final short NOT_MONITOR_OWNER = 51; + + /** + * Call has been interrupted before completion + */ + public static final short INTERRUPT = 52; + + /** + * Virtual machine attempted to read a class file and determined that + * the file is malformed or otherwise cannot be interpreted as a class + * file + */ + public static final short INVALID_CLASS_FORMAT = 60; + + /** + * Circularity has been detected while initializing a class + */ + public static final short CIRCULAR_CLASS_DEFINITION = 61; + + /** + * Verifier detected that a class file, though well formed, contained + * some sort of internal inconsistency or security problem + */ + public static final short FAILS_VERIFICATION = 62; + + /** + * Adding methods has not been implemented + */ + public static final short ADD_METHOD_NOT_IMPLEMENTED = 63; + + /** + * Schema change has not been implemented + */ + public static final short SCHEMA_CHANGE_NOT_IMPLEMENTED = 64; + + /** + * State of the thread has been modified and is now inconsistent + */ + public static final short INVALID_TYPESTATE = 65; + + /** + * A direct superclass is different for the new class version, or the set + * of directly implemented interfaces is different and + * <code>canUnrestrictedlyRedefineClasses</code> is false + */ + public static final short HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66; + + /** + * New class version does not declare a method declared in the old + * class version and <code>canUnrestrictedlyRedefineClasses</code> + * is false + */ + public static final short DELETE_METHOD_NOT_IMPLEMENTED = 67; + + /** + * Class file has a version number not supported by this VM + */ + public static final short UNSUPPORTED_VERSION = 68; + + /** + * Class name defined in the new class file is different from the name + * in the old class object + */ + public static final short NAMES_DONT_MATCH = 69; + + /** + * New class version has different modifiers and + * <code>canUnrestrictedlyRedefineClasses</code> is false + */ + public static final short CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70; + + /** + * A method in the new class version has different modifiers than its + * counterpart in the old class version and + * <code>canUnrestrictedlyRedefineClasses</code> is false. + */ + public static final short METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71; + + /** + * Functionality is not implemented in this virtual machine + */ + public static final short NOT_IMPLEMENTED = 99; + + /** + * Invalid pointer + */ + public static final short NULL_POINTER = 100; + + /** + * Desired information is not available + */ + public static final short ABSENT_INFORMATION = 101; + + /** + * Specified event type id is not recognized + */ + public static final short INVALID_EVENT_TYPE = 102; + + /** + * Illegal argument + */ + public static final short ILLEGAL_ARGUMENT = 103; + + /** + * The function needed to allocate memory and no more memory was + * available for allocation + */ + public static final short OUT_OF_MEMORY = 110; + + /** + * Debugging has not been enabled in this virtual machine. JVMDI cannot + * be used + */ + public static final short ACCESS_DENIED = 111; + + /** + * The virtual machine is not running + */ + public static final short VM_DEAD = 112; + + /** + * An unexpected internal error has occurred + */ + public static final short INTERNAL = 113; + + /** + * The thread being used to call this function is not attached to the + * virtual machine. Calls must be made from attached threads. + */ + public static final short UNATTACHED_THREAD = 115; + + /** + * Invalid object type id or class tag + */ + public static final short INVALID_TAG = 500; + + /** + * Previous invoke not complete + */ + public static final short ALREADY_INVOKING = 502; + + /** + * Invalid index + */ + public static final short INVALID_INDEX = 503; + + /** + * Invalid length + */ + public static final short INVALID_LENGTH = 504; + + /** + * Invalid string + */ + public static final short INVALID_STRING = 506; + + /** + * Invalid class loader + */ + public static final short INVALID_CLASS_LOADER = 507; + + /** + * Invalid array + */ + public static final short INVALID_ARRAY = 508; + + /** + * Unable to load the transport + */ + public static final short TRANSPORT_LOAD = 509; + + /** + * Unablie to initialize the transport + */ + public static final short TRANSPORT_INIT = 510; + + /** + * Method is native + */ + public static final short NATIVE_METHOD = 511; + + /** + * Invalid count + */ + public static final short INVALID_COUNT = 512; + } + + /* + * EventKind constants + */ + public static final class EventKind + { + public static final byte SINGLE_STEP = 1; + public static final byte BREAKPOINT = 2; + public static final byte FRAME_POP = 3; + public static final byte EXCEPTION = 4; + public static final byte USER_DEFINED = 5; + public static final byte THREAD_START = 6; + public static final byte THREAD_END = 7; + public static final byte CLASS_PREPARE = 8; + public static final byte CLASS_UNLOAD = 9; + public static final byte CLASS_LOAD = 10; + public static final byte FIELD_ACCESS = 20; + public static final byte FIELD_MODIFICATION = 21; + public static final byte EXCEPTION_CATCH = 30; + public static final byte METHOD_ENTRY = 40; + public static final byte METHOD_EXIT = 41; + public static final byte VM_INIT = 90; + public static final byte VM_DEATH = 99; + public static final byte VM_DISCONNECTED = 100; + + public static final byte VM_START = VM_INIT; + public static final byte THREAD_DEATH = THREAD_END; + } + + /* + * ModKind constants (event filters) + */ + public static final class ModKind + { + /** + * Limit the requested event to be reported at most once after a + * given number of occurrences. May be used with any event. + */ + public static final byte COUNT = 1; + + /** + * Conditional on expression + */ + public static final byte CONDITIONAL = 2; + + /** + * Restricts reported events to those in the given thread. + * May be used with any event except for class unload. + */ + public static final byte THREAD_ONLY = 3; + + /** + * For class prepare events, restricts generated events + * to be the preparation of the given reference type and any + * subtypes. + * + * For other events, restricts the generated events to those where + * location is in the given reference type or any of its subtypes. + * + * An event will be generated for any location in a reference type + * that can be safely cast to the given reference type. + * + * May be used with any event except class unload, thread start, + * and thread end. + */ + public static final byte CLASS_ONLY = 4; + + /** + * Restricts reported events to those for classes whose name matches + * the given restricted regular expression. + * + * For class prepare events, the prepared class name is matched. + * For class unload events, the unloaded class name is matched. + * For other events, the class name of the event's location is matched. + * + * May be used with any event except thread start and thread end. + */ + public static final byte CLASS_MATCH = 5; + + /** + * Restricts reported events to those for classes whose name does not + * match the given restricted regular expression. + * + * For class prepare events, the prepared class name is matched. + * For class unload events, the unloaded class name is matched. + * For other events, the class name of the event's location is matched. + * + * May be used with any event except thread start and thread end. + */ + public static final byte CLASS_EXCLUDE = 6; + + /** + * Restricts reported events to those that occur at the given location. + * + * May be used with breakpoint, field access, field modification, step, + * and exception event kinds. + */ + public static final byte LOCATION_ONLY = 7; + + /** + * Restricts reported exceptions by their class and whether they are + * caught or uncaught. + * + * May be used with exception event kinds only. + */ + public static final byte EXCEPTION_ONLY = 8; + + /** + * Restricts reported events to those that occur for a given field. + * + * May be used with field access and field modification event kinds only. + */ + public static final byte FIELD_ONLY = 9; + + /** + * Restricts reported step events to those which satisfy depth and + * size constraints. + * + * May be used with step event kinds only. + */ + public static final byte STEP = 10; + + /** + * Restricts reported events to those whose active 'this' object is + * the given object. Match value is the null object for static methods. + * + * May be used with any event except class prepare, class unload, + * thread start, and thread end. + */ + public static final byte INSTANCE_ONLY = 11; + } + + /* + * ThreadStatus constants + */ + public static final class ThreadStatus + { + public static final int ZOMBIE = 0; + public static final int RUNNING = 1; + public static final int SLEEPING = 2; + public static final int MONITOR = 3; + public static final int WAIT = 4; + } + + /* + * SuspendStatus constants + */ + public static final class SuspendStatus + { + public static final byte SUSPENDED = 1; + } + + /* + * ClassStatus constants + */ + public static final class ClassStatus + { + public static final int VERIFIED = 1; + public static final int PREPARED = 2; + public static final int INITIALIZED = 4; + public static final int ERROR = 8; + } + + /* + * TypeTag constants + */ + public static final class TypeTag + { + public static final byte CLASS = 1; + public static final byte INTERFACE = 2; + public static final byte ARRAY = 3; + } + + /* + * Tag constants + */ + public static final class Tag + { + /** + * Array object (objectID size) + */ + public static final byte ARRAY = '['; + + /** + * Byte value (1 byte) + */ + public static final byte BYTE = 'B'; + + /** + * Character value (2 bytes) + */ + public static final byte CHAR = 'C'; + + /** + * Object (objectID size) + */ + public static final byte OBJECT = 'L'; + + /** + * Float value (4 bytes) + */ + public static final byte FLOAT = 'F'; + + /** + * Double value (8 bytes) + */ + public static final byte DOUBLE = 'D'; + + /** + * Int value (4 bytes) + */ + public static final byte INT = 'I'; + + /** + * Long value (8 bytes) + */ + public static final byte LONG = 'J'; + + /** + * Short value (2 bytes) + */ + public static final byte SHORT = 'S'; + + /** + * Void value (no bytes) + */ + public static final byte VOID = 'V'; + + /** + * Boolean value (1 byte) + */ + public static final byte BOOLEAN = 'Z'; + + /** + * String object (objectID size) + */ + public static final byte STRING = 's'; + + /** + * Thread object (objectID size) + */ + public static final byte THREAD = 't'; + + /** + * ThreadGroup object (objectID size) + */ + public static final byte THREAD_GROUP = 'g'; + + /** + * ClassLoader object (objectID size) + */ + public static final byte CLASS_LOADER = 'l'; + + /** + * Class object object (objectID size) + */ + public static final byte CLASS_OBJECT = 'c'; + } + + /* + * StepDepth constants + */ + public static final class StepDepth + { + /** + * Step into any method calls that occur before the end of the step + */ + public static final int INTO = 0; + + /** + * Step over any method calls that occur before the end of the step + */ + public static final int OVER = 1; + + /** + * Step out of the current method + */ + public static final int OUT = 2; + } + + /* + * StepSize constants + */ + public static final class StepSize + { + /** + * Step by the minimum possible amount (often a bytecode instruction) + */ + public static final int MIN = 0; + + /** + * Step to the next source line unless there is no line number information, + * in which case MIN step is done instead + */ + public static final int LINE = 1; + } + + /* + * SuspendPolicy constants + */ + public static final class SuspendPolicy + { + /** + * Suspend no threads when this event is encountered + */ + public static final byte NONE = 0; + + /** + * Suspend the event thread when this event is encountered + */ + public static final byte EVENT_THREAD = 1; + + /** + * Suspend all threads when this event is encountered + */ + public static final byte ALL = 2; + } + + /* + * InvokeOptions flag constants + */ + public static final class InvokeOptions + { + /** + * otherwise, all threads started + */ + public static final int INVOKE_SINGLE_THREADED = 0x1; + + /** + * otherwise, normal virtual invoke (instance methods only) + */ + public static final int INVOKE_NONVIRTUAL = 0x2; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/BreakpointEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/BreakpointEvent.java new file mode 100644 index 000000000..46e50de16 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/BreakpointEvent.java @@ -0,0 +1,117 @@ +/* BreakpointEvent.java -- An event specifying that the interpreter + has hit a breakpoint + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of a breakpoint in the target VM. The breakpoint event is + * generated before the code at its location is executed." + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class BreakpointEvent + extends Event +{ + // The thread in which this event occurred + private Thread _thread; + + // Location where breakpoint occurred + private Location _location; + + //object instance + private Object _instance; + + /** + * Constructs a new BreakpointEvent + * + * @param thread thread in which event occurred + * @param loc location where breakpoint occurred + * @param instance object instance + */ + public BreakpointEvent(Thread thread, Location loc, Object instance) + { + super(JdwpConstants.EventKind.BREAKPOINT); + _thread = thread; + _location = loc; + _instance = instance; + } + + /** + * Returns a specific filtering parameter for this event. + * Valid types are thread and location. + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter(int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_LOCATION) + return _location; + else if (type == EVENT_INSTANCE) + return _instance; + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId(_thread); + + tid.write(outStream); + _location.write(outStream); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/ClassPrepareEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/ClassPrepareEvent.java new file mode 100644 index 000000000..f21f8e7c0 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/ClassPrepareEvent.java @@ -0,0 +1,147 @@ +/* ClassPrepareEvent.java -- An event specifying that a class has been + prepared by the virtual machine + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Signature; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of a class prepare in the target VM. See the JVM + * specification for a definition of class preparation. Class prepare + * events are not generated for primtiive classes (for example, + * <code>java.lang.Integer.TYPE</code>)." -- JDWP 1.4.2 + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ClassPrepareEvent + extends Event +{ + // The thread in which this event occurred + private Thread _thread; + + // The class that was prepared + private Class _class; + + // Prepare flags + private int _status; + + /** + * Class has been verified + */ + public static final int STATUS_VERIFIED + = JdwpConstants.ClassStatus.VERIFIED; + + /** + * Class has been prepared + */ + public static final int STATUS_PREPARED + = JdwpConstants.ClassStatus.PREPARED; + + /** + * Class has been initialized + */ + public static final int STATUS_INITIALIZED + = JdwpConstants.ClassStatus.INITIALIZED; + + /** + * Error preparing class + */ + public static final int STATUS_ERROR + = JdwpConstants.ClassStatus.ERROR; + + /** + * Constructs a new <code>ClassPrepareEvent</code> + * + * @param thread thread in which event occurred + * @param clazz class which was prepared + * @param flags prepare status flags + */ + public ClassPrepareEvent (Thread thread, Class clazz, int flags) + { + super (JdwpConstants.EventKind.CLASS_PREPARE); + _thread = thread; + _class = clazz; + _status = flags; + } + + /** + * Returns a specific filtering parameter for this event. + * Valid types are thread and class. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_CLASS) + return _class; + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId (_thread); + ReferenceTypeId rid = idm.getReferenceTypeId (_class); + + tid.write (outStream); + rid.writeTagged (outStream); + JdwpString.writeString (outStream, + Signature.computeClassSignature (_class)); + outStream.writeInt (_status); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/ClassUnloadEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/ClassUnloadEvent.java new file mode 100644 index 000000000..a35d3b9bd --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/ClassUnloadEvent.java @@ -0,0 +1,96 @@ +/* ClassUnloadEvent.java -- event generated when a class is unloaded + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.util.JdwpString; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of a class unload in the target VM" -- JDWP 1.4.2 + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class ClassUnloadEvent + extends Event +{ + //signature directly from VM + private String _signature; + + /** + * Constructs a new <code>ClassUnloadEvent</code> + * + * @param signature the signature reported from the VM + */ + public ClassUnloadEvent(String signature) + { + super(JdwpConstants.EventKind.CLASS_UNLOAD); + _signature = signature; + } + + /** + * Returns a specific filtering parameter for this event. Class is the only + * valid type. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter(int type) + { + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + */ + protected void _writeData(DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + + JdwpString.writeString(outStream, _signature); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/Event.java b/libjava/classpath/gnu/classpath/jdwp/event/Event.java new file mode 100644 index 000000000..492cadbcc --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/Event.java @@ -0,0 +1,180 @@ +/* Event.java -- a base class for all event types + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.transport.JdwpCommandPacket; +import gnu.classpath.jdwp.transport.JdwpPacket; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * This class is a base class for all VM->debugger event + * notifications. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public abstract class Event +{ + /** + * The class of the object in which the event occurred + */ + public static final int EVENT_CLASS = 1; + + /** + * The thread where the event occurred + */ + public static final int EVENT_THREAD = 2; + + /** + * The location where an event occurred + */ + public static final int EVENT_LOCATION = 3; + + /** + * The instance of the class where the event occurred + */ + public static final int EVENT_INSTANCE = 4; + + /** + * The field acted on by an event + */ + public static final int EVENT_FIELD = 5; + + /** + * The class of the exception for ExceptionEvent + */ + public static final int EVENT_EXCEPTION_CLASS = 6; + + /** + * Whether this exception was caught (only valid for ExceptionEvents) + */ + public static final int EVENT_EXCEPTION_CAUGHT = 7; + + // The kind of event represented by this event + private byte _eventKind; + + /** + * Constructs an <code>Event</code> of the given kind + * + * @param kind the type of event + */ + public Event (byte kind) + { + _eventKind = kind; + } + + /** + * Returns the event type of this event + * + * @returns the event kind + */ + public byte getEventKind () + { + return _eventKind; + } + + /** + * Abstract function used by implementing classes to fill in the + * event-specific data. Note that request ID is automatically added + * by this class (since it appears in all event notifications). + * + * @param outStream the stream to which to write data + */ + protected abstract void _writeData (DataOutputStream outStream) + throws IOException; + + /** + * Returns a specific filtering parameter for this event. For example, + * most events may be filtered by thread. Consequently, a call to this + * method with <code>ThreadId.class</code> should return a + * <code>Thread</code>. + * + * @param type the type of parameter to return + * @returns the parameter (not the ID) or <code>null</code> if none is + * is defined for this event + */ + public abstract Object getParameter (int type); + + /** + * Converts the events into to a single JDWP Event.COMPOSITE packet + * + * @param dos the stream to which to write data + * @param events the events to package into the packet + * @param requests the corresponding event requests + * @param suspendPolicy the suspend policy enforced by the VM + * @returns a <code>JdwpPacket</code> of the events + */ + public static JdwpPacket toPacket (DataOutputStream dos, + Event[] events, + EventRequest[] requests, + byte suspendPolicy) + { + JdwpPacket pkt; + try + { + dos.writeByte (suspendPolicy); + dos.writeInt (events.length); + for (int i = 0; i < events.length; ++i) + _toData (dos, events[i], requests[i]); + + pkt + = new JdwpCommandPacket (JdwpConstants.CommandSet.Event.CS_VALUE, + JdwpConstants.CommandSet.Event.COMPOSITE); + } + catch (IOException ioe) + { + pkt = null; + } + + return pkt; + } + + // Helper function for toPacket + private static void _toData (DataOutputStream dos, Event event, + EventRequest request) + throws IOException + { + dos.writeByte (event._eventKind); + dos.writeInt (request.getId ()); + event._writeData (dos); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/EventManager.java b/libjava/classpath/gnu/classpath/jdwp/event/EventManager.java new file mode 100644 index 000000000..3f34a5ee9 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/EventManager.java @@ -0,0 +1,305 @@ +/* EventManager.java -- event management and notification infrastructure + 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.event; + +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.InvalidEventTypeException; +import gnu.classpath.jdwp.exception.JdwpException; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.Iterator; + +/** + * Manages event requests and filters event notifications. + * + * The purpose of this class is actually two-fold: + * + * 1) Maintain a list of event requests from the debugger + * 2) Filter event notifications from the VM + * + * If an event request arrives from the debugger, the back-end will + * call {@link #requestEvent}, which will first check for a valid event. + * If it is valid, <code>EventManager</code> will record the request + * internally and register the event with the virtual machine, which may + * choose to handle the request itself (as is likely the case with + * breakpoints and other execution-related events), or it may decide to + * allow the <code>EventManager</code> to handle notifications and all + * filtering (which is convenient for other events such as class (un)loading). + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class EventManager +{ + // Single instance + private static EventManager _instance = null; + + // maps event (EVENT_*) to lists of EventRequests + private Hashtable _requests = null; + + /** + * Returns an instance of the event manager + * + * @return the event manager + */ + public static EventManager getDefault() + { + if (_instance == null) + _instance = new EventManager(); + + return _instance; + } + + // Private constructs a new <code>EventManager</code> + private EventManager () + { + _requests = new Hashtable (); + + // Add lists for all the event types + _requests.put (new Byte (EventRequest.EVENT_SINGLE_STEP), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_BREAKPOINT), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_FRAME_POP), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_EXCEPTION), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_USER_DEFINED), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_THREAD_START), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_THREAD_END), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_CLASS_PREPARE), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_CLASS_UNLOAD), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_CLASS_LOAD), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_FIELD_ACCESS), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_FIELD_MODIFY), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_METHOD_ENTRY), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_METHOD_EXIT), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_VM_INIT), + new Hashtable ()); + _requests.put (new Byte (EventRequest.EVENT_VM_DEATH), + new Hashtable ()); + + // Add auto-generated event notifications + // only two: VM_INIT, VM_DEATH + try + { + byte sp = (Jdwp.suspendOnStartup() + ? EventRequest.SUSPEND_THREAD : EventRequest.SUSPEND_NONE); + requestEvent (new EventRequest (0, + EventRequest.EVENT_VM_INIT, sp)); + requestEvent (new EventRequest (0, + EventRequest.EVENT_VM_DEATH, + EventRequest.SUSPEND_NONE)); + } + catch (JdwpException e) + { + // This can't happen + } + } + + /** + * Returns all requests for the given event. This method will only + * be used if the <code>EventManager</code> is handling event filtering. + * + * @param event the event + * @return requests that are interested in this event + * or <code>null</code> if none (and event should not be sent) + * @throws IllegalArgumentException for invalid event kind + */ + public EventRequest[] getEventRequests(Event event) + { + ArrayList interestedEvents = new ArrayList(); + Hashtable requests; + Byte kind = new Byte(event.getEventKind()); + requests = (Hashtable) _requests.get(kind); + if (requests == null) + { + // Did not get a valid event type + throw new IllegalArgumentException("invalid event kind: " + kind); + } + + // Loop through the requests. Must look at ALL requests in order + // to evaluate all filters (think count filter). + Iterator rIter = requests.values().iterator(); + while (rIter.hasNext()) + { + EventRequest request = (EventRequest) rIter.next(); + if (request.matches(event)) + interestedEvents.add(request); + } + + EventRequest[] r = new EventRequest[interestedEvents.size()]; + interestedEvents.toArray(r); + return r; + } + + /** + * Requests monitoring of an event. + * + * The debugger registers for event notification through + * an event filter. If no event filter is specified for an event + * in the VM, it is assumed that the debugger is not interested in + * receiving notifications of this event. + * + * The virtual machine will be notified of the request. + * + * @param request the request to monitor + * @throws InvalidEventTypeException for invalid event kind + * @throws JdwpException for other errors involving request + */ + public void requestEvent (EventRequest request) + throws JdwpException + { + // Add request to request list + Hashtable requests; + Byte kind = new Byte (request.getEventKind ()); + requests = (Hashtable) _requests.get (kind); + if (requests == null) + { + // Did not get a valid event type + throw new InvalidEventTypeException (request.getEventKind ()); + } + + // Register the event with the VM + VMVirtualMachine.registerEvent (request); + requests.put (new Integer (request.getId ()), request); + } + + /** + * Deletes the given request from the management table + * + * @param kind the event kind + * @param id the ID of the request to delete + * @throws IllegalArgumentException for invalid event kind + * @throws JdwpException for other errors deleting request + */ + public void deleteRequest (byte kind, int id) + throws JdwpException + { + Hashtable requests; + requests = (Hashtable) _requests.get (new Byte (kind)); + if (requests == null) + { + // Did not get a valid event type + throw new IllegalArgumentException ("invalid event kind: " + kind); + } + + Integer iid = new Integer (id); + EventRequest request = (EventRequest) requests.get (iid); + if (request != null) + { + VMVirtualMachine.unregisterEvent (request); + requests.remove (iid); + } + } + + /** + * Clears all the requests for a given event + * + * @param kind the event kind + * @throws IllegalArgumentException for invalid event kind + * @throws JdwpException for error clearing events + */ + public void clearRequests (byte kind) + throws JdwpException + { + Hashtable requests = (Hashtable) _requests.get (new Byte (kind)); + if (requests == null) + { + // Did not get a valid event type + throw new IllegalArgumentException ("invalid event kind: " + kind); + } + + VMVirtualMachine.clearEvents (kind); + requests.clear (); + } + + /** + * Returns a given event request for an event + * + * @param kind the kind of event for the request + * @param id the integer request id to return + * @return the request for the given event kind with the given id + * (or <code>null</code> if not found) + * @throws IllegalArgumentException for invalid event kind + */ + public EventRequest getRequest (byte kind, int id) + { + Hashtable requests = (Hashtable) _requests.get (new Byte (kind)); + if (requests == null) + { + // Did not get a valid event type + throw new IllegalArgumentException ("invalid event kind: " + kind); + } + + return (EventRequest) requests.get (new Integer (id)); + } + + /** + * Returns all requests of the given event kind + * + * @param kind the event kind + * @returns a <code>Collection</code> of all the registered requests + * @throws IllegalArgumentException for invalid event kind + */ + public Collection getRequests (byte kind) + { + Hashtable requests = (Hashtable) _requests.get (new Byte (kind)); + if (requests == null) + { + // Did not get a valid event type + throw new IllegalArgumentException ("invalid event kind: " + kind); + } + + return requests.values (); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/EventRequest.java b/libjava/classpath/gnu/classpath/jdwp/event/EventRequest.java new file mode 100644 index 000000000..891da229b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/EventRequest.java @@ -0,0 +1,383 @@ +/* EventRequest.java -- an event request from the debugger + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.event.filters.*; +import gnu.classpath.jdwp.exception.JdwpIllegalArgumentException; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * A class which represents a request by the debugger for an event + * in the VM. <code>EventRequest</code>s usually have event filters + * associated with them, which allow the debugger to specify conditions + * under which the notification should be sent (specific thread, specific + * class, ignore count, etc). + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class EventRequest +{ + /* + * Event types + */ + + /** + * Single step event + */ + public static final byte EVENT_SINGLE_STEP = + JdwpConstants.EventKind.SINGLE_STEP; + + /** + * Breakpoint event + */ + public static final byte EVENT_BREAKPOINT = + JdwpConstants.EventKind.BREAKPOINT; + + /** + * Frame pop event + */ + public static final byte EVENT_FRAME_POP = + JdwpConstants.EventKind.FRAME_POP; + + /** + * Exception event + */ + public static final byte EVENT_EXCEPTION = + JdwpConstants.EventKind.EXCEPTION; + + /** + * User-defined event + */ + public static final byte EVENT_USER_DEFINED = + JdwpConstants.EventKind.USER_DEFINED; + + /** + * Thread start event + */ + public static final byte EVENT_THREAD_START = + JdwpConstants.EventKind.THREAD_START; + + /** + * Thread end/death event + */ + public static final byte EVENT_THREAD_END = + JdwpConstants.EventKind.THREAD_END; + + /** + * Class prepare event + */ + public static final byte EVENT_CLASS_PREPARE = + JdwpConstants.EventKind.CLASS_PREPARE; + + /** + * Class unload event + */ + public static final byte EVENT_CLASS_UNLOAD = + JdwpConstants.EventKind.CLASS_UNLOAD; + + /** + * Class load event + */ + public static final byte EVENT_CLASS_LOAD = + JdwpConstants.EventKind.CLASS_LOAD; + + /** + * Field access event + */ + public static final byte EVENT_FIELD_ACCESS = + JdwpConstants.EventKind.FIELD_ACCESS; + + /** + * Field modify event + */ + public static final byte EVENT_FIELD_MODIFY = + JdwpConstants.EventKind.FIELD_MODIFICATION; + + /** + * Method entry event + */ + public static final byte EVENT_METHOD_ENTRY = + JdwpConstants.EventKind.METHOD_ENTRY; + + /** + * Method exit event + */ + public static final byte EVENT_METHOD_EXIT = + JdwpConstants.EventKind.METHOD_EXIT; + + /** + * Virtual machine initialization/start + */ + public static final byte EVENT_VM_INIT = + JdwpConstants.EventKind.VM_INIT; + + /** + * Virutal machine death + */ + public static final byte EVENT_VM_DEATH = + JdwpConstants.EventKind.VM_DEATH; + + + /* + * Suspend policies + */ + + /** + * Do not suspend any threads + */ + public static final byte SUSPEND_NONE = + JdwpConstants.SuspendPolicy.NONE; + + /** + * Suspend the thread in which the event occurred + */ + public static final byte SUSPEND_THREAD = + JdwpConstants.SuspendPolicy.EVENT_THREAD; + + /** + * Suspend all threads + */ + public static final byte SUSPEND_ALL = + JdwpConstants.SuspendPolicy.ALL; + + // ID of last EventRequest + private static int _last_id = 0; + private static Object _idLock = new Object (); + + // A list of filters + private LinkedList _filters; + + // The ID of this request + private int _id; + + // The suspend policy to enforce when this event occurs + private byte _suspendPolicy; + + // Kind of event requested + private byte _kind; + + /** + * Construct a new <code>EventRequest</code> + * + * @param kind the kind of event requested + * @param suspendPolicy how to suspend threads when event occurs + */ + public EventRequest (byte kind, byte suspendPolicy) + { + _filters = new LinkedList (); + synchronized (_idLock) + { + _id = ++_last_id; + } + _kind = kind; + _suspendPolicy = suspendPolicy; + } + + /** + * Construct a new <code>EventRequest</code> with the given ID + * + * @param id the id of the request to create + * @param kind the kind of event requested + * @param suspendPolicy how to suspend threads when event occurs + */ + public EventRequest (int id, byte kind, byte suspendPolicy) + { + _filters = new LinkedList (); + _kind = kind; + _suspendPolicy = suspendPolicy; + } + + /** + * Creates a new event filter, adding it to this request + * + * @param filter the filter to add + * @throws JdwpIllegalArgumentException if an invalid or illegal filter + * is added to the request + */ + public void addFilter (IEventFilter filter) + throws JdwpIllegalArgumentException + { + // Check validity of filter for this request + boolean valid = true; + + Class clazz = filter.getClass (); + if (clazz == ClassExcludeFilter.class) + { + if (_kind == EVENT_THREAD_START + || _kind == EVENT_THREAD_END) + valid = false; + } + else if (clazz == ClassMatchFilter.class) + { + if (_kind == EVENT_THREAD_START + || _kind == EVENT_THREAD_END) + valid = false; + } + else if (clazz == ClassOnlyFilter.class) + { + if (_kind == EVENT_CLASS_UNLOAD + || _kind == EVENT_THREAD_START + || _kind == EVENT_THREAD_END) + valid = false; + } + else if (clazz == ConditionalFilter.class) + { + // JDWP 1.4 does not say much about this + } + else if (clazz == CountFilter.class) + { + // may be used with any event + } + else if (clazz == ExceptionOnlyFilter.class) + { + if (_kind != EVENT_EXCEPTION) + valid = false; + } + else if (clazz == FieldOnlyFilter.class) + { + if (_kind != EVENT_FIELD_ACCESS + && _kind != EVENT_FIELD_MODIFY) + valid = false; + } + else if (clazz == InstanceOnlyFilter.class) + { + if (_kind == EVENT_CLASS_PREPARE + || _kind == EVENT_CLASS_UNLOAD + || _kind == EVENT_THREAD_START + || _kind == EVENT_THREAD_END) + valid = false; + } + else if (clazz == LocationOnlyFilter.class) + { + if (_kind != EVENT_BREAKPOINT + && _kind != EVENT_FIELD_ACCESS + && _kind != EVENT_FIELD_MODIFY + && _kind != EVENT_SINGLE_STEP + && _kind != EVENT_EXCEPTION) + valid = false; + } + else if (clazz == StepFilter.class) + { + if (_kind != EVENT_SINGLE_STEP) + valid = false; + } + else if (clazz == ThreadOnlyFilter.class) + { + if (_kind == EVENT_CLASS_UNLOAD) + valid = false; + } + + if (!valid) + { + String msg = ("cannot use " + filter.getClass ().getName () + + " with class unload events"); + throw new JdwpIllegalArgumentException (msg); + } + + // Add filter to list + _filters.add (filter); + } + + /** + * Returns the filters attached to this request + */ + public Collection getFilters () + { + return _filters; + } + + /** + * Returns the suspend policy for this request + */ + public byte getSuspendPolicy () + { + return _suspendPolicy; + } + + /** + * Returns the request id of this request + */ + public int getId () + { + return _id; + } + + /** + * Sets the id of the request (used for auto-generated events) + */ + public void setId (int id) + { + _id = id; + } + + /** + * Returns the kind of event for this request + */ + public byte getEventKind () + { + return _kind; + } + + /** + * Determines whether the given event matches this request + * + * @param theEvent the event to compare to + */ + public boolean matches (Event theEvent) + { + boolean matches = true; + + // Loop through filters; all must match + // Note that we must allow EVERY filter to evaluate. This way + // things like CountFilter will work. + Iterator iter = _filters.iterator (); + while (iter.hasNext ()) + { + IEventFilter filter = (IEventFilter) iter.next (); + if (!filter.matches (theEvent)) + matches = false; + } + + return matches; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/ExceptionEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/ExceptionEvent.java new file mode 100644 index 000000000..e63f5df12 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/ExceptionEvent.java @@ -0,0 +1,157 @@ +/* ExceptionEvent.java -- an event specifying an exception has been thrown + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Notification from the VM that an exception has occurred along with where it + * occurred, and if and where it was caught. + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class ExceptionEvent + extends Event +{ + //object instance + private Object _instance; + + // the exception thrown + private Throwable _exception; + + // the thread in which the exception occurred + private Thread _thread; + + // the location where the exception was thrown + private Location _location; + + //the location where the exception was caught + private Location _catchLocation; + + //the class where the exeption was thrown + private Class _klass; + + /** + * Constructs a new <code>ExceptionEvent</code> where the exception was + * caught. + * + * @param exception the throwable object that generated the event + * @param thread the thread where the exception occurred + * @param location the location where the exception was thrown + * @param catchLocation the location where the exception was caught + * @param instance the instance that threw the exception + */ + public ExceptionEvent(Throwable exception, Thread thread, Location location, + Location catchLocation, Class clazz, Object instance) + { + super(JdwpConstants.EventKind.EXCEPTION); + _exception = exception; + _thread = thread; + _location = location; + _catchLocation = catchLocation; + _klass = clazz; + _instance = instance; + } + + /** + * Returns a specific filtering parameter for this event. Valid types are + * thread, location, and catchLocation. + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter(int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_LOCATION) + return _location; + else if (type == EVENT_INSTANCE) + return _instance; + else if (type == EVENT_CLASS) + return _klass; + else if (type == EVENT_EXCEPTION_CLASS) + return _exception.getClass(); + else if (type == EVENT_EXCEPTION_CAUGHT) + if (_catchLocation.getMethod() != null) + return Boolean.TRUE; + else + return Boolean.FALSE; + + return null; + } + + /** + * Sets the catchLocation, used for exceptions that are caught in different + * stack frames from where they are thrown. + * + * @param catchLoc the location of the catch + */ + public void setCatchLoc(Location catchLoc) + { + _catchLocation = catchLoc; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + * @throws IOException + */ + protected void _writeData(DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId(_thread); + ObjectId oid = idm.getObjectId(_exception); + + tid.write(outStream); + _location.write(outStream); + oid.writeTagged(outStream); + _catchLocation.write(outStream); + + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/MethodEntryEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/MethodEntryEvent.java new file mode 100644 index 000000000..1ec1a5d4b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/MethodEntryEvent.java @@ -0,0 +1,118 @@ +/* MethodEntryEvent.java -- an event specifying that a method has been invoked + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Notification from the VM that that a method has been invoked + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class MethodEntryEvent + extends Event +{ + // The thread where the event occurred + private Thread _thread; + + // the location where the event occurred + private Location _location; + + //object instance + private Object _instance; + + /** + * Constructs a new <code>MethodEntryEvent</code> + * + * @param thread the thread where the exception occurred + * @param location the location single stepped to + * @param instance instance from which the method was called + */ + public MethodEntryEvent(Thread thread, Location location, Object instance) + { + super(JdwpConstants.EventKind.METHOD_ENTRY); + _thread = thread; + _location = location; + _instance = instance; + } + + /** + * Returns a specific filtering parameter for this event. Valid types are + * thread and location + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter(int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_LOCATION) + return _location; + else if (type == EVENT_INSTANCE) + return _instance; + else if (type == EVENT_CLASS) + return _instance.getClass(); + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + * @throws IOException + */ + protected void _writeData(DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId(_thread); + + tid.write(outStream); + _location.write(outStream); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/MethodExitEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/MethodExitEvent.java new file mode 100644 index 000000000..84c909901 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/MethodExitEvent.java @@ -0,0 +1,115 @@ +/* MethodExitEvent.java -- an event specifying that a method has returned + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Notification from the VM that that a method has returned + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class MethodExitEvent + extends Event +{ + // The thread where the event occurred + private Thread _thread; + + // the location where the event occurred + private Location _location; + + // object instance + private Object _instance; + + /** + * Constructs a new <code>MethodExitEvent</code> + * + * @param thread the thread where the exception occurred + * @param location the location single stepped to + * @param instance the instance from which the method was called + */ + public MethodExitEvent(Thread thread, Location location, Object instance) + { + super(JdwpConstants.EventKind.METHOD_EXIT); + _thread = thread; + _location = location; + _instance = instance; + } + + /** + * Returns a specific filtering parameter for this event. Valid types are + * thread and location + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter(int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_LOCATION) + return _location; + else if (type == EVENT_CLASS) + return _instance.getClass(); + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + * @throws IOException + */ + protected void _writeData(DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId(_thread); + + tid.write(outStream); + _location.write(outStream); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/SingleStepEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/SingleStepEvent.java new file mode 100644 index 000000000..40cf50c65 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/SingleStepEvent.java @@ -0,0 +1,121 @@ +/* SingleStepEvent.java -- an event specifying that a single step has + compleated + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; + + +/** + * Notification from the VM that a single step has compleated including the + * thread and location stepped to + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class SingleStepEvent + extends Event +{ + // the thread where the event occurred + private Thread _thread; + + // the location where the event occurred + private Location _location; + + //object instance + private Object _instance; + + /** + * Constructs a new <code>SingleStepEvent</code> + * + * @param thread the thread where the exception occurred + * @param location the location single stepped to + * @param instance the instance in which the single step occurred + */ + public SingleStepEvent(Thread thread, Location location, Object instance) + { + super(JdwpConstants.EventKind.SINGLE_STEP); + _thread = thread; + _location = location; + _instance = instance; + } + + /** + * Returns a specific filtering parameter for this event. Valid types are + * thread and location + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter(int type) + { + if (type == EVENT_THREAD) + return _thread; + else if (type == EVENT_LOCATION) + return _location; + else if (type == EVENT_INSTANCE) + return _instance; + else if (type == EVENT_CLASS) + return _instance.getClass(); + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + * @throws IOException + */ + protected void _writeData(DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId(_thread); + + tid.write(outStream); + _location.write(outStream); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/ThreadEndEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/ThreadEndEvent.java new file mode 100644 index 000000000..a36015a82 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/ThreadEndEvent.java @@ -0,0 +1,104 @@ +/* ThreadEndEvent.java -- An event specifying that a thread has died + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of a completed thread in the target VM. The notification + * is generated by the dying thread before it terminates. Because of this + * timing, it is possible for VirtualMachine.allThreads to return this + * thread after this event is received. + * + * <p>Note that this event gives no information about the lifetime of the + * thread object. It may or may not be collected soon depending on what + * references exist in the target VM." -- JDWP 1.4.2 + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ThreadEndEvent + extends Event +{ + private Thread _thread; + + /** + * Constructs a new <code>ThreadEndEvent</code> + * + * @param thread the deceased thread + */ + public ThreadEndEvent (Thread thread) + { + super (JdwpConstants.EventKind.THREAD_END); + _thread = thread; + } + + /** + * Returns a specific filtering parameter for this event. + * Valid types are ThreadId. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (int type) + { + if (type == EVENT_THREAD) + return _thread; + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId (_thread); + tid.write (outStream); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/ThreadStartEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/ThreadStartEvent.java new file mode 100644 index 000000000..4eff4409e --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/ThreadStartEvent.java @@ -0,0 +1,109 @@ +/* ThreadStartEvent.java -- An event specifying that a new thread + has started in the virtual machine + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of a new running thread in the target VM. The new + * thread can be the result of a call to {@link java.lang.Thread#start} or + * the result of attaching a new thread to the VM though JNI. The + * notification is generated by the new thread some time before its + * execution starts. Because of this timing, it is possible to receive + * other events for the thread before this event is received. (Notably, + * Method Entry Events and Method Exit Events might occur during thread + * initialization. It is also possible for the VirtualMachine AllThreads + * command to return a thread before its thread start event is received. + * + * <p>Note that this event gives no information about the creation of the + * thread object which may have happened much earlier, depending on the + * VM being debugged." -- JDWP 1.4.2 + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ThreadStartEvent + extends Event +{ + private Thread _thread; + + /** + * Constructs a new ThreadStartEvent object + * + * @param thread the thread ID in which event occurred + */ + public ThreadStartEvent (Thread thread) { + super (JdwpConstants.EventKind.THREAD_START); + _thread = thread; + } + + /** + * Returns a specific filtering parameter for this event. + * Valid types are ThreadId. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (int type) + { + if (type == EVENT_THREAD) + return _thread; + + return null; + } + + /** + * Writes the event to the given stream + * + * @param outStream the output stream to write the event to + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId (_thread); + tid.write (outStream); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java new file mode 100644 index 000000000..c197ecef4 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java @@ -0,0 +1,83 @@ +/* VmDeathEvent.java -- An event specifying that the VM has terminated + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Event notifying the debugger that the virtual machine has terminated. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VmDeathEvent + extends Event +{ + /** + * Constructs a new VmDeathEvent object + */ + public VmDeathEvent () + { + super (JdwpConstants.EventKind.VM_DEATH); + } + + /** + * Returns a specific filtering parameter for this event. + * This event has no valid types. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (int type) + { + return null; + } + + /** + * Writes out event-specific data + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + // no data (request ID done by VMIdManager) + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/VmInitEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/VmInitEvent.java new file mode 100644 index 000000000..8c1db4f33 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/VmInitEvent.java @@ -0,0 +1,94 @@ +/* VmInitEvent.java -- An event specifying that the VM has started + 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.event; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ThreadId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * "Notification of initialization of a target VM. This event is + * received before the main thread is started and before any application + * code has been executed." -- JDWP 1.4.2 + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VmInitEvent + extends Event +{ + private Thread _initialThread; + + /** + * Constructs a <code>VmInitEvent</code> object + * + * @param thread the initial thread + */ + public VmInitEvent (Thread thread) + { + super (JdwpConstants.EventKind.VM_INIT); + _initialThread = thread; + } + + /** + * Returns a specific filtering parameter for this event. + * This event has no valid types. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (int type) + { + return null; + } + + /** + * Writes out event-specific data + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ThreadId tid = (ThreadId) idm.getObjectId (_initialThread); + tid.write (outStream); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassExcludeFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassExcludeFilter.java new file mode 100644 index 000000000..5514f1b72 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassExcludeFilter.java @@ -0,0 +1,75 @@ +/* ClassExcludeFilter.java -- filter on class name (exclusive) + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidStringException; + +/** + * An event filter which excludes events matching a + * specified class pattern (exact match or start/end with "*"). + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ClassExcludeFilter + extends ClassMatchFilter +{ + /** + * Constructs a new <code>ClassExcludeFilter</code> + * + * @param pattern the pattern to use + * @throws InvalidStringException if pattern is invalid + */ + public ClassExcludeFilter (String pattern) + throws InvalidStringException + { + super (pattern); + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + return !super.matches (event); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassMatchFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassMatchFilter.java new file mode 100644 index 000000000..edb84d7ef --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassMatchFilter.java @@ -0,0 +1,112 @@ +/* ClassMatchFilter.java -- filter on class name (inclusive) + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidStringException; + +/** + * An event filter which includes events matching a + * specified class pattern (exact match or start/end with "*"). + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ClassMatchFilter + implements IEventFilter +{ + // Pattern to match + private String _pattern; + + /** + * Constructs a new <code>ClassMatchFilter</code> + * + * @param pattern the pattern to use + * @throws InvalidStringException if pattern is invalid + */ + public ClassMatchFilter (String pattern) + throws InvalidStringException + { + int index = pattern.indexOf ('*'); + if (index != -1 && index != 0 && index != (pattern.length () - 1)) + { + // '*' must be first char or last char + throw new InvalidStringException ("pattern may be an exact match or " + + "start/end with \"*\""); + } + _pattern = pattern; + } + + /** + * Returns the pattern to be matched + * + * @return the pattern + */ + public String getPattern () + { + return _pattern; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + Object type = event.getParameter (Event.EVENT_CLASS); + if (type != null) + { + Class eventClass = (Class) type; + String name = eventClass.getName (); + + if (_pattern.startsWith ("*")) + return name.endsWith (_pattern.substring (1)); + else if (_pattern.endsWith ("*")) + { + int end = _pattern.length () - 1; + return name.startsWith (_pattern.substring (0, end)); + } + else + return name.matches (_pattern); + } + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassOnlyFilter.java new file mode 100644 index 000000000..d912cb5ef --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ClassOnlyFilter.java @@ -0,0 +1,109 @@ +/* ClassOnlyFilter.java -- filter on specific class + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +/** + * An event filter which filters out events in uninteresting + * classes. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ClassOnlyFilter + implements IEventFilter +{ + // Class ID for which to filter + private ReferenceTypeId _id; + + /** + * Constructs a new <code>ClassOnlyFilter</code> + * + * @param refId the reference type id for a class for which events + * will be reported + * @throws InvalidClassException if the ID is no longer valid + */ + public ClassOnlyFilter (ReferenceTypeId refId) + throws InvalidClassException + { + // validity check + refId.getType (); + _id = refId; + } + + /** + * Returns the class to which to restrict events + * + * @return the class's ID + */ + public ReferenceTypeId getType () + { + return _id; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + Object type = event.getParameter (Event.EVENT_CLASS); + if (type != null) + { + try + { + Class clazz = _id.getType (); + Class eventClass = (Class) type; + if (clazz.isAssignableFrom (eventClass)) + return true; + } + catch (InvalidClassException ice) + { + // class is no longer valid + return false; + } + } + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ConditionalFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ConditionalFilter.java new file mode 100644 index 000000000..645a70f42 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ConditionalFilter.java @@ -0,0 +1,82 @@ +/* ConditionalFilter.java -- conditional expression filter + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.NotImplementedException; + +/** + * An event filter which allows expression conditionals. + * Note that in JDWP 1.4, this class is marked "for the + * future". + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ConditionalFilter + implements IEventFilter +{ + // private ConditionalId _exprId; + + /** + * Constructs a new <code>ConditionalFilter</code> with the + * given conditional. + * + * <p><b>NOTE:</b> This filter is marked "for the future", + * i.e, there is no way to actually use this yet. + * + * @param conditional the conditional expression + * @throws NotImplementedException if used + */ + public ConditionalFilter (Object conditional) + throws NotImplementedException + { + throw new NotImplementedException ("conditional filters"); + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/CountFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/CountFilter.java new file mode 100644 index 000000000..46148a504 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/CountFilter.java @@ -0,0 +1,95 @@ +/* CountFilter.java -- a step filter + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidCountException; + +/** + * An ignore count filter. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class CountFilter + implements IEventFilter +{ + // the count + private int _count; + + /** + * Constructs a new <code>CountFilter</code> with the given count. + * + * @param count the number of times the event will be ignored + * @throws InvalidCountException if count is invalid (< 1) + */ + public CountFilter (int count) + throws InvalidCountException + { + // Check for valid count + if (count < 1) + throw new InvalidCountException (count); + + _count = count; + } + + /** + * Returns the ignore count + * + * @return the number of times the event should be ignored + */ + public int getCount () + { + return _count; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + // This filter only relies on its count + if (--_count == 0) + return true; + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ExceptionOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ExceptionOnlyFilter.java new file mode 100644 index 000000000..d4687fa4e --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ExceptionOnlyFilter.java @@ -0,0 +1,123 @@ +/* ExceptionOnlyFilter.java -- filter for excetions by caught/uncaught and type + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +/** + * Restricts reported exceptions by their class and whether they are caught + * or uncaught. + * + * This modifier can be used with exception event kinds only. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ExceptionOnlyFilter + implements IEventFilter +{ + private ReferenceTypeId _refId; + private boolean _caught; + private boolean _uncaught; + + /** + * Constructs a new ExceptionOnlyFilter + * + * @param refId ID of the exception to report(null for all exceptions) + * @param caught Report caught exceptions + * @param uncaught Report uncaught exceptions + * @throws InvalidClassException if refid is invalid + */ + public ExceptionOnlyFilter (ReferenceTypeId refId, boolean caught, + boolean uncaught) + throws InvalidClassException + { + if (refId != null && refId.getReference().get() == null) + throw new InvalidClassException(refId.getId()); + + _refId = refId; + _caught = caught; + _uncaught = uncaught; + } + + /** + * Returns the exception class to report (<code>null</code> for all) + * + * @return the class's ID + */ + public ReferenceTypeId getType () + { + return _refId; + } + + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches(Event event) + { + boolean classMatch = true; + + // if not allowing all exceptions check if the exception matches + if (_refId != null) + { + try + { + Class klass + = (Class) event.getParameter(Event.EVENT_EXCEPTION_CLASS); + classMatch = klass == _refId.getType(); + } + catch (InvalidClassException ex) + { + classMatch = false; + } + } + + // check against the caught and uncaught options + Boolean caught + = (Boolean) event.getParameter(Event.EVENT_EXCEPTION_CAUGHT); + + return classMatch && ((caught.booleanValue()) ? _caught : _uncaught); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/FieldOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/FieldOnlyFilter.java new file mode 100644 index 000000000..47a804101 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/FieldOnlyFilter.java @@ -0,0 +1,112 @@ +/* FieldOnlyFilter.java -- filter on field + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidFieldException; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +/** + * Restricts reported events to those that occur for a given field. + * + * This modifier can be used with field access and field modification event + * kinds only. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class FieldOnlyFilter + implements IEventFilter +{ + private ReferenceTypeId _refId; + private ReferenceTypeId _fieldId; + + /** + * Constructs a new <code>FieldOnlyFilter</code>. + * + * @param refId class for field + * @param fid field + * @throws InvalidClassException if class is invalid + * @throws InvalidFieldException if field is invalid + */ + public FieldOnlyFilter (ReferenceTypeId refId, /*Field*/ReferenceTypeId fid) + throws InvalidClassException, InvalidFieldException + { + if (refId == null || refId.getReference().get () == null) + throw new InvalidClassException (refId.getId ()); + + if (fid == null) + throw new InvalidFieldException (fid.getId ()); + + _refId = refId; + _fieldId = fid; + } + + /** + * Returns the class in which the field is declared + * + * @return the class's id + */ + public ReferenceTypeId getType () + { + return _refId; + } + + /** + * Returns the field for which to restrict events + * + * @return the field's id + */ + public ReferenceTypeId getField () + { + return _fieldId; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + // FIXME + throw new RuntimeException ("FieldOnlyFilter.matches not implemented"); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/IEventFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/IEventFilter.java new file mode 100644 index 000000000..4a2b5431b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/IEventFilter.java @@ -0,0 +1,65 @@ +/* IEventFilter.java -- an interface for event filters + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; + +/** + * An interface for event filters. The debugger registers an event + * filter for a given event when it is interested in receiving + * notifications about that event from the VM. + * + * <p>Filters are attached to {@link gnu.classpath.jdwp.event.EventRequest}s + * in order to allow the debugger to specify that an event should be sent + * only when the filters for the event request all match. + * + * <p>No filters means "send all notifications". + * + * @author Keith Seitz (keiths@redhat.com) + */ +public interface IEventFilter +{ + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event); +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/InstanceOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/InstanceOnlyFilter.java new file mode 100644 index 000000000..45ab3c428 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/InstanceOnlyFilter.java @@ -0,0 +1,101 @@ +/* InstanceOnlyFilter.java -- filter on instance + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.id.ObjectId; + +/** + * Restricts reported events to those whose active 'this' object is the + * given object. Match value is the null object for static methods. + * + * This modifier can be used with any event kind except class prepare, + * class unload, thread start, and thread end. Introduced in JDWP version 1.4. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InstanceOnlyFilter + implements IEventFilter +{ + private ObjectId _instance; + + /** + * Constructs a new <code>InstanceOnlyFilter</code>. + * + * @param oid the object to which to restrict events (may be null) + * @throws InvalidObjectException if Object is invalid + */ + public InstanceOnlyFilter (ObjectId oid) + throws InvalidObjectException + { + if (oid != null && oid.getReference().get () == null) + throw new InvalidObjectException (oid.getId ()); + + _instance = oid; + } + + /** + * Returns the instance to which to restrict events + * + * @return the object's ID + */ + public ObjectId getInstance () + { + return _instance; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + Object eventInstance = event.getParameter (Event.EVENT_INSTANCE); + if (eventInstance != null) + { + Object myInstance = _instance.getReference().get (); + return ((myInstance != null) && (myInstance == eventInstance)); + } + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/LocationOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/LocationOnlyFilter.java new file mode 100644 index 000000000..a3125371c --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/LocationOnlyFilter.java @@ -0,0 +1,94 @@ +/* LocationOnlyFilter.java -- filter on location + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidLocationException; +import gnu.classpath.jdwp.util.Location; + +/** + * Restricts reported events to those that occur at the given location. + * + * May be used with breakpoint, field access, field modification, step, + * and exception event kinds. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class LocationOnlyFilter + implements IEventFilter +{ + private Location _location; + + /** + * Constructs a new <code>LocationOnlyFilter</code>. + * + * @param loc the location for which to report events + * @throws InvalidLocationException if location is invalid + */ + public LocationOnlyFilter (Location loc) + throws InvalidLocationException + { + _location = loc; + } + + /** + * Returns the location at which to restrict events + * + * @return the location + */ + public Location getLocation () + { + return _location; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches(Event event) + { + Location loc = (Location) event.getParameter(Event.EVENT_LOCATION); + if (loc != null) + return (getLocation().equals(loc)); + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java new file mode 100644 index 000000000..b620b7953 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java @@ -0,0 +1,126 @@ +/* StepFilter.java -- a step filter + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidThreadException; +import gnu.classpath.jdwp.id.ThreadId; + +/** + * "An event filter which restricts reported step events to those which + * satisfy depth and size constraints. This modifier can only be used with + * step event kinds." + * + * This "filter" is not really a filter. It is simply a way to communicate + * stepping information in a convenient way between the JDWP backend and + * the virtual machine. + * + * Consequently, this "filter" always matches. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class StepFilter + implements IEventFilter +{ + private ThreadId _tid; + private int _size; + private int _depth; + + /** + * Constructs a new StepFilter + * + * @param tid ID of the thread in which to step + * @param size size of each step + * @param depth relative call stack limit + * @throws InvalidThreadException if thread is invalid + */ + public StepFilter (ThreadId tid, int size, int depth) + throws InvalidThreadException + { + if (tid.getReference().get () == null) + throw new InvalidThreadException (tid.getId ()); + + _tid = tid; + _size = size; + _depth = depth; + } + + /** + * Returns the thread in which to step + * + * @return the thread's ID + */ + public ThreadId getThread () + { + return _tid; + } + + /** + * Returns the size of each step (insn, line) + * + * @return the step size + * @see gnu.classpath.jdwp.JdwpConstants.StepSize + */ + public int getSize () + { + return _size; + } + + /** + * Returns the relative call stack limit (into, over, out) + * + * @return how to step + * @see gnu.classpath.jdwp.JdwpConstants.StepDepth + */ + public int getDepth () + { + return _depth; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + return true; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java new file mode 100644 index 000000000..de9fb3ec6 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java @@ -0,0 +1,101 @@ +/* ThreadOnlyFilter.java -- a thread filter + 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.event.filters; + +import gnu.classpath.jdwp.event.Event; +import gnu.classpath.jdwp.exception.InvalidThreadException; +import gnu.classpath.jdwp.id.ThreadId; + +/** + * An event filter which allows only events within a specific + * thread + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class ThreadOnlyFilter + implements IEventFilter +{ + // the thread + private ThreadId _tid; + + /** + * Constructs a new <code>ThreadOnlyFilter</code> for the given + * thread id + * + * @param tid ID of the thread on which to filter + * @throws InvalidThreadException if the thread is not valid + */ + public ThreadOnlyFilter (ThreadId tid) + throws InvalidThreadException + { + if (tid == null || tid.getReference().get () == null) + throw new InvalidThreadException (tid.getId ()); + + _tid = tid; + } + + /** + * Returns the thread in which to restrict events + * + * @return the thread's ID + */ + public ThreadId getThread () + { + return _tid; + } + + /** + * Does the given event match the filter? + * + * @param event the <code>Event</code> to scrutinize + */ + public boolean matches (Event event) + { + Object thread = event.getParameter (Event.EVENT_THREAD); + if (thread != null) + { + Thread eventThread = (Thread) thread; + Thread myThread = (Thread) _tid.getReference().get (); + return (eventThread == myThread); + } + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/AbsentInformationException.java b/libjava/classpath/gnu/classpath/jdwp/exception/AbsentInformationException.java new file mode 100644 index 000000000..5bf383f58 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/AbsentInformationException.java @@ -0,0 +1,56 @@ +/* AbsentInformationException.java -- information not present exception + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the requested information is not available. + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class AbsentInformationException + extends JdwpException +{ + public AbsentInformationException(String str) + { + super(JdwpConstants.Error.ABSENT_INFORMATION, str); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassException.java new file mode 100644 index 000000000..de15000a4 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassException.java @@ -0,0 +1,63 @@ +/* InvalidClassException.java -- invalid/unknown class reference id exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown by the JDWP back-end when an invalid reference + * type id is used by the debugger. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidClassException + extends JdwpException +{ + public InvalidClassException (long id) + { + super (JdwpConstants.Error.INVALID_CLASS, + "invalid class id (" + id + ")"); + } + + public InvalidClassException (Throwable t) + { + super (JdwpConstants.Error.INVALID_CLASS, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassLoaderException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassLoaderException.java new file mode 100644 index 000000000..ca91e6eb6 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidClassLoaderException.java @@ -0,0 +1,62 @@ +/* InvalidClassLoaderException.java -- an invalid class loader exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger uses an invalid class loader + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidClassLoaderException + extends JdwpException +{ + public InvalidClassLoaderException (long id) + { + super (JdwpConstants.Error.INVALID_CLASS_LOADER, + "invalid class loader (" + id + ")"); + } + + public InvalidClassLoaderException (Throwable t) + { + super (JdwpConstants.Error.INVALID_CLASS_LOADER, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidCountException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidCountException.java new file mode 100644 index 000000000..d5f40c96b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidCountException.java @@ -0,0 +1,61 @@ +/* InvalidCountException -- an invalid count exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when a count filter is given an invalid count. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidCountException + extends JdwpException +{ + public InvalidCountException (int id) + { + super (JdwpConstants.Error.INVALID_COUNT, "invalid count (" + id + ")"); + } + + public InvalidCountException (Throwable t) + { + super (JdwpConstants.Error.INVALID_COUNT, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidEventTypeException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidEventTypeException.java new file mode 100644 index 000000000..17341ce1d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidEventTypeException.java @@ -0,0 +1,63 @@ +/* InvalidEventTypeException.java -- an invalid event kind exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger asks for an event request + * for a non-existant event + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidEventTypeException + extends JdwpException +{ + public InvalidEventTypeException (byte kind) + { + super (JdwpConstants.Error.INVALID_EVENT_TYPE, + "invalid event type (" + kind + ")"); + } + + public InvalidEventTypeException (Throwable t) + { + super (JdwpConstants.Error.INVALID_EVENT_TYPE, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFieldException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFieldException.java new file mode 100644 index 000000000..47470ab8c --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFieldException.java @@ -0,0 +1,63 @@ +/* InvalidFieldException.java -- an invalid field id exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid field id is used by the + * debugger + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidFieldException + extends JdwpException +{ + public InvalidFieldException (long id) + { + super (JdwpConstants.Error.INVALID_FIELDID, + "invalid field id (" + id + ")"); + } + + public InvalidFieldException (Throwable t) + { + super (JdwpConstants.Error.INVALID_FIELDID, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java new file mode 100644 index 000000000..876c0a88c --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java @@ -0,0 +1,63 @@ +/* InvalidFrameException.java -- invalid jframeid + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger requests an invalid frame in the call + * stack. + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class InvalidFrameException + extends JdwpException +{ + public InvalidFrameException(long id) + { + super(JdwpConstants.Error.INVALID_FRAMEID, + "invalid frame id (" + id + ")"); + } + + public InvalidFrameException(String msg) + { + super(JdwpConstants.Error.INVALID_FRAMEID, msg); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidLocationException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidLocationException.java new file mode 100644 index 000000000..e8cc78fac --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidLocationException.java @@ -0,0 +1,62 @@ +/* InvalidLocationException.java -- an invalid location exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger specifies an invalid location + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidLocationException + extends JdwpException +{ + public InvalidLocationException (/*something*/) + { + super (JdwpConstants.Error.INVALID_LOCATION, + "invalid location (" + "something" + ")"); + } + + public InvalidLocationException (Throwable t) + { + super (JdwpConstants.Error.INVALID_LOCATION, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidMethodException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidMethodException.java new file mode 100644 index 000000000..83569f481 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidMethodException.java @@ -0,0 +1,63 @@ +/* InvalidMethodException.java -- an invalid method id exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid method id is used + * by the debugger + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidMethodException + extends JdwpException +{ + public InvalidMethodException (long id) + { + super (JdwpConstants.Error.INVALID_METHODID, + "invalid method id (" + id + ")"); + } + + public InvalidMethodException (Throwable t) + { + super (JdwpConstants.Error.INVALID_METHODID, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidObjectException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidObjectException.java new file mode 100644 index 000000000..8b1a2802d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidObjectException.java @@ -0,0 +1,63 @@ +/* InvalidObjectException.java -- an invalid object id exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid object id is used by + * the debugger + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidObjectException + extends JdwpException +{ + public InvalidObjectException (long id) + { + super (JdwpConstants.Error.INVALID_OBJECT, + "invalid object id (" + id + ")"); + } + + public InvalidObjectException (Throwable t) + { + super (JdwpConstants.Error.INVALID_OBJECT, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidSlotException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidSlotException.java new file mode 100644 index 000000000..bf6bc904d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidSlotException.java @@ -0,0 +1,62 @@ +/* InvalidSlotException.java -- an invalid variable slot exception + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid Slot id is used by the debugger + * (i.e. when trying to access a variable slot which doesn't exist). + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class InvalidSlotException + extends JdwpException +{ + public InvalidSlotException(int slot) + { + super(JdwpConstants.Error.INVALID_SLOT, "invalid slot: " + slot); + } + + public InvalidSlotException(String msg) + { + super(JdwpConstants.Error.INVALID_SLOT, msg); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidStringException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidStringException.java new file mode 100644 index 000000000..b9864a6e6 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidStringException.java @@ -0,0 +1,68 @@ +/* InvalidStringException.java -- an invalid string exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger uses an invalid String. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidStringException + extends JdwpException +{ + public InvalidStringException (String str) + { + super (JdwpConstants.Error.INVALID_STRING, + "invalid string (" + str + ")"); + } + + public InvalidStringException (long id) + { + super (JdwpConstants.Error.INVALID_STRING, + "invalid string id (" + id + ")"); + } + + public InvalidStringException (Throwable t) + { + super (JdwpConstants.Error.INVALID_STRING, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidTagException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidTagException.java new file mode 100644 index 000000000..738b5e734 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidTagException.java @@ -0,0 +1,57 @@ +/* InvalidTagException.java -- an invalid type tag exception + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid tag is used by + * the debugger + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class InvalidTagException + extends JdwpException +{ + public InvalidTagException (byte tag) + { + super (JdwpConstants.Error.INVALID_TAG, + "invalid tag (" + tag + ")"); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadException.java new file mode 100644 index 000000000..9cebfba50 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadException.java @@ -0,0 +1,63 @@ +/* InvalidThreadException.java -- an invalid thread exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid thread is used + * by the debugger + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidThreadException + extends JdwpException +{ + public InvalidThreadException (long id) + { + super (JdwpConstants.Error.INVALID_THREAD, + "invalid thread id (" + id + ")"); + } + + public InvalidThreadException (Throwable t) + { + super (JdwpConstants.Error.INVALID_THREAD, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java new file mode 100644 index 000000000..7d9e62252 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java @@ -0,0 +1,63 @@ +/* InvalidThreadGroupException.java -- an invalid thread group exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when an invalid thread group is used + * by the debugger + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class InvalidThreadGroupException + extends JdwpException +{ + public InvalidThreadGroupException (long id) + { + super (JdwpConstants.Error.INVALID_THREAD_GROUP, + "invalid thread group id (" + id + ")"); + } + + public InvalidThreadGroupException (Throwable t) + { + super (JdwpConstants.Error.INVALID_THREAD_GROUP, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/JdwpException.java b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpException.java new file mode 100644 index 000000000..5c96cc56b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpException.java @@ -0,0 +1,86 @@ +/* JdwpException.java -- an exception base class for all JDWP exceptions + 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.exception; + +/** + * A base class exception for all JDWP back-end exceptions + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class JdwpException + extends Exception +{ + // The integer error code defined by JDWP + private short _errorCode; + + /** + * Constructs a new <code>JdwpException</code> with the + * given error code and given cause + * + * @param code the JDWP error code + * @param t the cause of the exception + */ + public JdwpException (short code, Throwable t) + { + super (t); + _errorCode = code; + } + + /** + * Constructs a new <code>JdwpException</code> with the + * given error code and string error message + * + * @param code the JDWP error code + * @param str an error message + */ + public JdwpException (short code, String str) + { + super (str); + _errorCode = code; + } + + /** + * Returns the JDWP error code represented by this exception + */ + public short getErrorCode () + { + return _errorCode; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/JdwpIllegalArgumentException.java b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpIllegalArgumentException.java new file mode 100644 index 000000000..1ede37f83 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpIllegalArgumentException.java @@ -0,0 +1,62 @@ +/* JdwpIllegalArgumentException.java -- an illegal argument exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An illegal argument exception for JDWP. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class JdwpIllegalArgumentException + extends JdwpException +{ + /** + * Constructs a new <code>JdwpIllegalArgumentException</code> with + * the given error code and given cause + * + * @param msg a message explaining the illegal argument + */ + public JdwpIllegalArgumentException (String msg) + { + super (JdwpConstants.Error.ILLEGAL_ARGUMENT, msg); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java new file mode 100644 index 000000000..3cf8592f4 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java @@ -0,0 +1,62 @@ +/* JdwpInternalErrorException.java -- an internal error exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown by the JDWP back-end when an unusual runtime + * error occurs internally + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class JdwpInternalErrorException + extends JdwpException +{ + public JdwpInternalErrorException(Throwable cause) + { + super(JdwpConstants.Error.INTERNAL, cause); + } + + public JdwpInternalErrorException(String msg) + { + super(JdwpConstants.Error.INTERNAL, msg); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/NativeMethodException.java b/libjava/classpath/gnu/classpath/jdwp/exception/NativeMethodException.java new file mode 100644 index 000000000..36c03c431 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/NativeMethodException.java @@ -0,0 +1,63 @@ +/* NativeMethodException.java -- a native method exception + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the debugger attempts to invoke + * an unsupported command on a native method (like setting a breakpoint). + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class NativeMethodException + extends JdwpException +{ + public NativeMethodException(long id) + { + super(JdwpConstants.Error.NATIVE_METHOD, + "invalid method id (" + id + ")"); + } + + public NativeMethodException(Throwable t) + { + super(JdwpConstants.Error.NATIVE_METHOD, t); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/NotImplementedException.java b/libjava/classpath/gnu/classpath/jdwp/exception/NotImplementedException.java new file mode 100644 index 000000000..a4ec7b224 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/NotImplementedException.java @@ -0,0 +1,58 @@ +/* NotImplementedException.java -- an exception for unimplemented JDWP + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown by virtual machines when functionality + * or features are not implemented + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class NotImplementedException + extends JdwpException +{ + public NotImplementedException (String feature) + { + super (JdwpConstants.Error.NOT_IMPLEMENTED, + feature + " is not yet implemented"); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/TypeMismatchException.java b/libjava/classpath/gnu/classpath/jdwp/exception/TypeMismatchException.java new file mode 100644 index 000000000..c6af65223 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/TypeMismatchException.java @@ -0,0 +1,62 @@ +/* TypeMismatchException.java -- mismatched type of local variable + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception throw when attempting to access a local variable of the wrong + * type. + * + * @author Kyle Galloway (kgallowa@redhat.com) + */ +public class TypeMismatchException + extends JdwpException +{ + public TypeMismatchException(byte tag) + { + super(JdwpConstants.Error.TYPE_MISMATCH, "incorrect tag: " + tag); + } + + public TypeMismatchException(String msg) + { + super(JdwpConstants.Error.TYPE_MISMATCH, msg); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/exception/VmDeadException.java b/libjava/classpath/gnu/classpath/jdwp/exception/VmDeadException.java new file mode 100644 index 000000000..f3c4a152b --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/exception/VmDeadException.java @@ -0,0 +1,55 @@ +/* VmDeadException.java -- dead virtual machine exception + 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.exception; + +import gnu.classpath.jdwp.JdwpConstants; + +/** + * An exception thrown when the virtual machine is dead + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VmDeadException + extends JdwpException +{ + public VmDeadException () + { + super (JdwpConstants.Error.VM_DEAD, "Virtual machine is dead"); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ArrayId.java b/libjava/classpath/gnu/classpath/jdwp/id/ArrayId.java new file mode 100644 index 000000000..cd428a172 --- /dev/null +++ b/libjava/classpath/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., 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.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/libjava/classpath/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java b/libjava/classpath/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java new file mode 100644 index 000000000..14a73dc5b --- /dev/null +++ b/libjava/classpath/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., 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.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/libjava/classpath/gnu/classpath/jdwp/id/ClassLoaderId.java b/libjava/classpath/gnu/classpath/jdwp/id/ClassLoaderId.java new file mode 100644 index 000000000..37c4c3655 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ClassLoaderId.java @@ -0,0 +1,82 @@ +/* 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., 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.id; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidClassLoaderException; + +/** + * 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); + } + + /** + * Gets the ClassLoader represented by this ID + * + * @throws InvalidClassLoaderException if ClassLoader is garbage collected, + * or otherwise invalid + */ + public ClassLoader getClassLoader () + throws InvalidClassLoaderException + { + ClassLoader cl = (ClassLoader) _reference.get (); + + if (cl == null) + throw new InvalidClassLoaderException (getId ()); + + return cl; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ClassObjectId.java b/libjava/classpath/gnu/classpath/jdwp/id/ClassObjectId.java new file mode 100644 index 000000000..3e1642212 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ClassObjectId.java @@ -0,0 +1,82 @@ +/* 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., 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.id; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidClassException; + +/** + * 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); + } + + /** + * Gets the Class object represented by this ID + * + * @throws InvalidClassException if Class is garbage collected, + * or otherwise invalid + */ + public Class getClassObject () + throws InvalidClassException + { + Class cl = (Class) _reference.get (); + + if (cl == null) + throw new InvalidClassException (getId ()); + + return cl; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ClassReferenceTypeId.java b/libjava/classpath/gnu/classpath/jdwp/id/ClassReferenceTypeId.java new file mode 100644 index 000000000..6b57673f8 --- /dev/null +++ b/libjava/classpath/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., 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.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/libjava/classpath/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java b/libjava/classpath/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java new file mode 100644 index 000000000..bdbd6b6eb --- /dev/null +++ b/libjava/classpath/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., 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.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/libjava/classpath/gnu/classpath/jdwp/id/JdwpId.java b/libjava/classpath/gnu/classpath/jdwp/id/JdwpId.java new file mode 100644 index 000000000..6caaa3a01 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/JdwpId.java @@ -0,0 +1,151 @@ +/* JdwpId.java -- base class for all object ID types + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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; +import java.lang.ref.SoftReference; + +/** + * A baseclass for all object types reported to the debugger + * + * @author Keith Seitz <keiths@redhat.com> + */ +public abstract class JdwpId +{ + /** + * The size of an ID. The default is 8 bytes (a long). + */ + public static final int SIZE = 8; + + /** + * 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.jdwp.JdwpConstants.TypeTag}) for reference type IDs. + */ + private byte _tag; + + /** + * The object/class represented by this Id + */ + protected SoftReference _reference; + + /** + * Constructs an empty <code>JdwpId</code> + */ + public JdwpId (byte tag) + { + _tag = tag; + } + + /** + * Sets the id for this object reference + */ + public void setId (long id) + { + _id = id; + } + + /** + * Returns the id for this object reference + */ + public long getId () + { + return _id; + } + + /** + * Gets the object/class reference for this ID + * + * @returns a refernce to the object or class + */ + public SoftReference getReference () + { + return _reference; + } + + /** + * Sets the object/class reference for this ID + * + * @param ref a refernce to the object or class + */ + public void setReference (SoftReference ref) + { + _reference = ref; + } + + /** + * 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. + */ + public boolean equals (JdwpId id) + { + return (id.getId () == getId ()); + } + + /** + * 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/libjava/classpath/gnu/classpath/jdwp/id/NullObjectId.java b/libjava/classpath/gnu/classpath/jdwp/id/NullObjectId.java new file mode 100644 index 000000000..5dc9753b7 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/NullObjectId.java @@ -0,0 +1,79 @@ +/* NullObjectId.java -- special objectId for null values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.id; + +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.util.NullObject; + +import java.lang.ref.SoftReference; + +/** + * This is a special case of an ObjectId. When a varaible slot contains + * null as its value, this is a valid value despite the fact that it does + * not reference an object. To represent this, this will always be the id + * of the NullObject (0). + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public class NullObjectId + extends ObjectId +{ + /** + * The object class that this id represents + */ + public static final Class typeClass = NullObject.class; + + /** + * Constructs a new <code>NullObjectId</code> + */ + public NullObjectId() + { + super(); + setId((long) 0); + _reference = new SoftReference<NullObject>(new NullObject()); + try + { + disableCollection(); + } + catch(InvalidObjectException ex) + { + //This will not happen + } + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ObjectId.java b/libjava/classpath/gnu/classpath/jdwp/id/ObjectId.java new file mode 100644 index 000000000..a4a37fd13 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ObjectId.java @@ -0,0 +1,131 @@ +/* ObjectId.java -- object IDs + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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 gnu.classpath.jdwp.exception.InvalidObjectException; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * This is a base class for all ObjectID-like entities in JDWP, + * inculding Objects, ClassObject, ClassLoader, Thread, ThreadGroup, + * etc. + * + * @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; + + // Handle to disable garbage collection + private Object _handle; + + /** + * 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 object referred to by this ID + * + * @returns the object + * @throws InvalidObjectException if the object was garbage collected + * or is invalid + */ + public Object getObject () + throws InvalidObjectException + { + Object obj = _reference.get (); + if (obj == null) + throw new InvalidObjectException (_id); + + return obj; + } + + /** + * 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); + } + + /** + * Disable garbage collection on object + */ + public void disableCollection () + throws InvalidObjectException + { + _handle = getObject (); + } + + /** + * Enable garbage collection on object + */ + public void enableCollection () + { + _handle = null; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ReferenceTypeId.java b/libjava/classpath/gnu/classpath/jdwp/id/ReferenceTypeId.java new file mode 100644 index 000000000..b82acf34a --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ReferenceTypeId.java @@ -0,0 +1,91 @@ +/* ReferenceTypeId.java -- a base class for all reference type IDs + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.exception.InvalidClassException; + +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); + } + + /** + * Gets the class associated with this ID + * + * @returns the class + * @throws InvalidClassException if the class is not valid + */ + public Class getType () + throws InvalidClassException + { + Class clazz = (Class) _reference.get (); + if (clazz == null) + throw new InvalidClassException (_id); + + return clazz; + } + + /** + * 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/libjava/classpath/gnu/classpath/jdwp/id/StringId.java b/libjava/classpath/gnu/classpath/jdwp/id/StringId.java new file mode 100644 index 000000000..1ba8f6d4d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/StringId.java @@ -0,0 +1,82 @@ +/* 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., 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.id; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidStringException; + +/** + * 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); + } + + /** + * Gets the String represented by this ID + * + * @throws InvalidStringException if String is garbage collected, + * or otherwise invalid + */ + public String getString () + throws InvalidStringException + { + String string = (String) _reference.get (); + + if (string == null) + throw new InvalidStringException (getId ()); + + return string; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ThreadGroupId.java b/libjava/classpath/gnu/classpath/jdwp/id/ThreadGroupId.java new file mode 100644 index 000000000..f4d9d803d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ThreadGroupId.java @@ -0,0 +1,82 @@ +/* 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., 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.id; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidThreadGroupException; + +/** + * 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); + } + + /** + * Gets the thread group represented by this ID + * + * @throws InvalidThreadGroupException if the group is invalid + * or garbage collected + */ + public ThreadGroup getThreadGroup () + throws InvalidThreadGroupException + { + ThreadGroup group = (ThreadGroup) _reference.get (); + + if (group == null) + throw new InvalidThreadGroupException (getId ()); + + return group; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/id/ThreadId.java b/libjava/classpath/gnu/classpath/jdwp/id/ThreadId.java new file mode 100644 index 000000000..207d6b0a1 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/id/ThreadId.java @@ -0,0 +1,85 @@ +/* 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., 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.id; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidThreadException; + +/** + * 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); + } + + /** + * Gets the Thread represented by this ID + * + * @throws InvalidThreadException if thread is garbage collected, + * exited, or otherwise invalid + */ + public Thread getThread () + throws InvalidThreadException + { + Thread thread = (Thread) _reference.get (); + + /* Spec says if thread is null, not valid, or exited, + throw invalid thread */ + // FIXME: not valid? exited? Is this check valid? + if (thread == null || !thread.isAlive ()) + throw new InvalidThreadException (getId ()); + + return thread; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java new file mode 100644 index 000000000..93c9d73e3 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java @@ -0,0 +1,176 @@ +/* ArrayReferenceCommandSet.java -- class to implement the Array + Reference Command Set + 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +import java.nio.ByteBuffer; + +/** + * A class representing the ArrayReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ArrayReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ArrayReference.LENGTH: + executeLength(bb, os); + break; + case JdwpConstants.CommandSet.ArrayReference.GET_VALUES: + executeGetValues(bb, os); + break; + case JdwpConstants.CommandSet.ArrayReference.SET_VALUES: + executeSetValues(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in Array Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeLength(ByteBuffer bb, DataOutputStream os) + throws InvalidObjectException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object array = oid.getObject(); + os.writeInt(Array.getLength(array)); + } + + private void executeGetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object array = oid.getObject(); + int first = bb.getInt(); + int length = bb.getInt(); + + // We need to write out the byte signifying the type of array first + Class clazz = array.getClass().getComponentType(); + + // Uugh, this is a little ugly but it's the only time we deal with + // arrayregions + if (clazz == byte.class) + os.writeByte(JdwpConstants.Tag.BYTE); + else if (clazz == char.class) + os.writeByte(JdwpConstants.Tag.CHAR); + else if (clazz == float.class) + os.writeByte(JdwpConstants.Tag.FLOAT); + else if (clazz == double.class) + os.writeByte(JdwpConstants.Tag.DOUBLE); + else if (clazz == int.class) + os.writeByte(JdwpConstants.Tag.BYTE); + else if (clazz == long.class) + os.writeByte(JdwpConstants.Tag.LONG); + else if (clazz == short.class) + os.writeByte(JdwpConstants.Tag.SHORT); + else if (clazz == void.class) + os.writeByte(JdwpConstants.Tag.VOID); + else if (clazz == boolean.class) + os.writeByte(JdwpConstants.Tag.BOOLEAN); + else if (clazz.isArray()) + os.writeByte(JdwpConstants.Tag.ARRAY); + else if (String.class.isAssignableFrom(clazz)) + os.writeByte(JdwpConstants.Tag.STRING); + else if (Thread.class.isAssignableFrom(clazz)) + os.writeByte(JdwpConstants.Tag.THREAD); + else if (ThreadGroup.class.isAssignableFrom(clazz)) + os.writeByte(JdwpConstants.Tag.THREAD_GROUP); + else if (ClassLoader.class.isAssignableFrom(clazz)) + os.writeByte(JdwpConstants.Tag.CLASS_LOADER); + else if (Class.class.isAssignableFrom(clazz)) + os.writeByte(JdwpConstants.Tag.CLASS_OBJECT); + else + os.writeByte(JdwpConstants.Tag.OBJECT); + + // Write all the values, primitives should be untagged and Objects must be + // tagged + for (int i = first; i < first + length; i++) + { + Value val = ValueFactory.createFromObject(Array.get(array, i), clazz); + if (clazz.isPrimitive()) + val.writeUntagged(os); + else + val.writeTagged(os); + } + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws IOException, JdwpException + { + ObjectId oid = idMan.readObjectId(bb); + Object array = oid.getObject(); + int first = bb.getInt(); + int length = bb.getInt(); + Class type = array.getClass().getComponentType(); + for (int i = first; i < first + length; i++) + { + Object value = Value.getUntaggedObject(bb, type); + Array.set(array, i, value); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java new file mode 100644 index 000000000..899bf2997 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java @@ -0,0 +1,105 @@ +/* ArrayTypeCommandSet.java -- class to implement the ArrayType Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +import java.nio.ByteBuffer; + +/** + * A class representing the ArrayType Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ArrayTypeCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + + // Although there's only a single command to choose from we still use + // a switch to maintain consistency with the rest of the CommandSets + try + { + switch (command) + { + case JdwpConstants.CommandSet.ArrayType.NEW_INSTANCE: + executeNewInstance(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ArrayType Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + public void executeNewInstance(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class arrayType = refId.getType(); + Class componentType = arrayType.getComponentType(); + + int length = bb.getInt(); + Object newArray = Array.newInstance(componentType, length); + ObjectId oid = idMan.getObjectId(newArray); + + // Since this array isn't referenced anywhere we'll disable garbage + // collection on it so it's still around when the debugger gets back to it. + oid.disableCollection(); + oid.writeTagged(os); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java new file mode 100644 index 000000000..295410f6c --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java @@ -0,0 +1,108 @@ +/* ClassLoaderReferenceCommandSet.java -- class to implement the + ClassLoaderReference Command Set + 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * A class representing the ClassLoaderReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ClassLoaderReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + + // Although there's only a single command to choose from we still use + // a switch to maintain consistency with the rest of the CommandSets + try + { + switch (command) + { + case JdwpConstants.CommandSet.ClassLoaderReference.VISIBLE_CLASSES: + executeVisibleClasses(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ClassLoaderReference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + public void executeVisibleClasses(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oId = idMan.readObjectId(bb); + ClassLoader cl = (ClassLoader) oId.getObject(); + ArrayList loadRequests = VMVirtualMachine.getLoadRequests(cl); + os.writeInt(loadRequests.size()); + for (Iterator iter = loadRequests.iterator(); iter.hasNext();) + { + Class clazz = (Class)iter.next(); + ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); + refId.writeTagged(os); + } + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java new file mode 100644 index 000000000..b32dbc2e5 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java @@ -0,0 +1,97 @@ +/* ClassObjectReferenceCommandSet.java -- class to implement the + ClassObjectReference Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the ClassObjectReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ClassObjectReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ClassObjectReference.REFLECTED_TYPE: + executeReflectedType(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ClassObject Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + public void executeReflectedType(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Class clazz = (Class) oid.getObject(); + + // The difference between a ClassObjectId and a ReferenceTypeId is one is + // stored as an ObjectId and the other as a ReferenceTypeId. + ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); + refId.writeTagged(os); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java new file mode 100644 index 000000000..ec496bfe9 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java @@ -0,0 +1,205 @@ +/* ClassTypeCommandSet.java -- class to implement the ClassType + Command Set + 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMMethod; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.InvalidFieldException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.MethodResult; +import gnu.classpath.jdwp.value.ObjectValue; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.ByteBuffer; + +/** + * A class representing the ClassType Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ClassTypeCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ClassType.SUPERCLASS: + executeSuperclass(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.SET_VALUES: + executeSetValues(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.INVOKE_METHOD: + executeInvokeMethod(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.NEW_INSTANCE: + executeNewInstance(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ClassType Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeSuperclass(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + Class superClazz = clazz.getSuperclass(); + + if (superClazz == null) { + os.writeLong(0L); + } else { + ReferenceTypeId clazzId = idMan.getReferenceTypeId(superClazz); + clazzId.write(os); + } + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + + // We don't actually seem to need this... + Class clazz = refId.getType(); + + int numValues = bb.getInt(); + + for (int i = 0; i < numValues; i++) + { + ObjectId fieldId = idMan.readObjectId(bb); + Field field = (Field) (fieldId.getObject()); + Object value = Value.getUntaggedObject(bb, field.getType()); + try + { + field.setAccessible(true); // Might be a private field + field.set(null, value); + } + catch (IllegalArgumentException ex) + { + throw new InvalidFieldException(ex); + } + catch (IllegalAccessException ex) + { // Since we set it as accessible this really shouldn't happen + throw new JdwpInternalErrorException(ex); + } + } + } + + private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + MethodResult mr = invokeMethod(bb); + + Throwable exception = mr.getThrownException(); + ObjectId eId = idMan.getObjectId(exception); + mr.getReturnedValue().writeTagged(os); + eId.writeTagged(os); + } + + private void executeNewInstance(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + MethodResult mr = invokeMethod(bb); + Throwable exception = mr.getThrownException(); + + if (exception == null && ! (mr.getReturnedValue() instanceof ObjectValue)) + throw new JdwpInternalErrorException("new instance returned non-object"); + + ObjectValue ov = (ObjectValue) mr.getReturnedValue(); + ObjectId oId = idMan.getObjectId(ov.getValue()); + + ObjectId eId = idMan.getObjectId(exception); + + oId.writeTagged(os); + eId.writeTagged(os); + } + + /** + * Execute the static method and return the resulting MethodResult. + */ + private MethodResult invokeMethod(ByteBuffer bb) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + ObjectId tId = idMan.readObjectId(bb); + Thread thread = (Thread) tId.getObject(); + + VMMethod method = VMMethod.readId(clazz, bb); + + int args = bb.getInt(); + Value[] values = new Value[args]; + + for (int i = 0; i < args; i++) + values[i] = ValueFactory.createFromTagged(bb); + + int invokeOpts = bb.getInt(); + MethodResult mr = VMVirtualMachine.executeMethod(null, thread, + clazz, method, + values, invokeOpts); + return mr; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/CommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/CommandSet.java new file mode 100644 index 000000000..e1b71c10d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/CommandSet.java @@ -0,0 +1,74 @@ +/* CommandSet.java -- An interface defining JDWP Command Sets + 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.processor; + +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.VMIdManager; + +import java.io.DataOutputStream; +import java.nio.ByteBuffer; + +/** + * A class representing a JDWP Command Set. This class serves as a generic + * interface for all Command Sets types used by JDWP. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public abstract class CommandSet +{ + /** + * The VM's ID manager + */ + protected final VMIdManager idMan = VMIdManager.getDefault (); + + /** + * Runs the given command with the data in distr and writes the data for the + * reply packet to ostr. + * + * @param bb holds the data portion of the Command Packet + * @param os data portion of the Reply Packet will be written here + * @param command the command field of the Command Packet + * @return true if the JDWP layer should shut down in response to this packet + * @throws JdwpException command wasn't carried out successfully + */ + public abstract boolean runCommand(ByteBuffer bb, DataOutputStream os, + byte command) + throws JdwpException; +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java new file mode 100644 index 000000000..477a79d83 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java @@ -0,0 +1,220 @@ +/* EventRequestCommandSet.java -- class to implement the EventRequest Command + Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.event.EventManager; +import gnu.classpath.jdwp.event.EventRequest; +import gnu.classpath.jdwp.event.filters.ClassExcludeFilter; +import gnu.classpath.jdwp.event.filters.ClassMatchFilter; +import gnu.classpath.jdwp.event.filters.ClassOnlyFilter; +import gnu.classpath.jdwp.event.filters.ConditionalFilter; +import gnu.classpath.jdwp.event.filters.CountFilter; +import gnu.classpath.jdwp.event.filters.ExceptionOnlyFilter; +import gnu.classpath.jdwp.event.filters.FieldOnlyFilter; +import gnu.classpath.jdwp.event.filters.IEventFilter; +import gnu.classpath.jdwp.event.filters.InstanceOnlyFilter; +import gnu.classpath.jdwp.event.filters.LocationOnlyFilter; +import gnu.classpath.jdwp.event.filters.StepFilter; +import gnu.classpath.jdwp.event.filters.ThreadOnlyFilter; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the EventRequest Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class EventRequestCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.EventRequest.SET: + executeSet(bb, os); + break; + case JdwpConstants.CommandSet.EventRequest.CLEAR: + executeClear(bb, os); + break; + case JdwpConstants.CommandSet.EventRequest.CLEAR_ALL_BREAKPOINTS: + executeClearAllBreakpoints(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in EventRequest Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeSet(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + byte eventKind = bb.get(); + byte suspendPolicy = bb.get(); + int modifiers = bb.getInt(); + + switch (eventKind) + { + case JdwpConstants.EventKind.FIELD_ACCESS: + if (!VMVirtualMachine.canWatchFieldAccess) + { + String msg = "watching field accesses is not supported"; + throw new NotImplementedException(msg); + } + break; + + case JdwpConstants.EventKind.FIELD_MODIFICATION: + if (!VMVirtualMachine.canWatchFieldModification) + { + String msg = "watching field modifications is not supported"; + throw new NotImplementedException(msg); + } + break; + + default: + // okay + } + + EventRequest eventReq = new EventRequest(eventKind, suspendPolicy); + IEventFilter filter = null; + ReferenceTypeId refId; + for (int i = 0; i < modifiers; i++) + { + byte modKind = bb.get(); + switch (modKind) + { + case JdwpConstants.ModKind.COUNT: + filter = new CountFilter(bb.getInt()); + break; + case JdwpConstants.ModKind.CONDITIONAL: + filter = new ConditionalFilter(idMan.readObjectId(bb)); + break; + case JdwpConstants.ModKind.THREAD_ONLY: + filter = new ThreadOnlyFilter((ThreadId) idMan.readObjectId(bb)); + break; + case JdwpConstants.ModKind.CLASS_ONLY: + filter = new ClassOnlyFilter(idMan.readReferenceTypeId(bb)); + break; + case JdwpConstants.ModKind.CLASS_MATCH: + filter = new ClassMatchFilter(JdwpString.readString(bb)); + break; + case JdwpConstants.ModKind.CLASS_EXCLUDE: + filter = new ClassExcludeFilter(JdwpString.readString(bb)); + break; + case JdwpConstants.ModKind.LOCATION_ONLY: + filter = new LocationOnlyFilter(new Location(bb)); + break; + case JdwpConstants.ModKind.EXCEPTION_ONLY: + long id = bb.getLong(); + if (id == 0) + refId = null; + else + refId = idMan.getReferenceType(id); + boolean caught = (bb.get() == 0) ? false : true; + boolean unCaught = (bb.get() == 0) ? false : true; + filter = new ExceptionOnlyFilter(refId, caught, unCaught); + break; + case JdwpConstants.ModKind.FIELD_ONLY: + refId = idMan.readReferenceTypeId(bb); + ReferenceTypeId fieldId = idMan.readReferenceTypeId(bb); + filter = new FieldOnlyFilter(refId, fieldId); + break; + case JdwpConstants.ModKind.STEP: + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + int size = bb.getInt(); + int depth = bb.getInt(); + filter = new StepFilter(tid, size, depth); + break; + case JdwpConstants.ModKind.INSTANCE_ONLY: + ObjectId oid = idMan.readObjectId(bb); + filter = new InstanceOnlyFilter(oid); + break; + default: + throw new NotImplementedException("modKind " + modKind + + " is not implemented."); + } + eventReq.addFilter(filter); + } + + EventManager.getDefault().requestEvent(eventReq); + os.writeInt(eventReq.getId()); + + } + + private void executeClear(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + byte eventKind = bb.get(); + int requestId = bb.getInt(); + EventManager.getDefault().deleteRequest(eventKind, requestId); + } + + private void executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + byte eventKind = bb.get (); + EventManager.getDefault().clearRequests (eventKind); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/FieldCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/FieldCommandSet.java new file mode 100644 index 000000000..d7bb64878 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/FieldCommandSet.java @@ -0,0 +1,67 @@ +/* FieldCommandSet.java -- class to implement the Field Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.NotImplementedException; + +import java.io.DataOutputStream; +import java.nio.ByteBuffer; + +/** + * A class representing the Field Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class FieldCommandSet + extends CommandSet +{ + /** + * There are no commands for this CommandSet at this time so we just throw a + * NotImplementedException whenever it's called. + * + * @throws JdwpException An exception will always be thrown + */ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + throw new NotImplementedException( + "No commands for command set Field implemented."); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java new file mode 100644 index 000000000..74e2f4c4d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java @@ -0,0 +1,68 @@ +/* InterfaceTypeCommandSet.java -- class to implement the InterfaceType + Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.NotImplementedException; + +import java.io.DataOutputStream; +import java.nio.ByteBuffer; + +/** + * A class representing the InterfaceType Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class InterfaceTypeCommandSet + extends CommandSet +{ + /** + * There are no commands for this CommandSet at this time so we just throw a + * NotImplementedException whenever it's called. + * + * @throws JdwpException An exception will always be thrown + */ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + throw new NotImplementedException( + "No commands for command set InterfaceType implemented."); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java new file mode 100644 index 000000000..043be7cf0 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java @@ -0,0 +1,157 @@ +/* MethodCommandSet.java -- class to implement the Method Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMMethod; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.LineTable; +import gnu.classpath.jdwp.util.VariableTable; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the Method Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class MethodCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.Method.LINE_TABLE: + executeLineTable(bb, os); + break; + case JdwpConstants.CommandSet.Method.VARIABLE_TABLE: + executeVariableTable(bb, os); + break; + case JdwpConstants.CommandSet.Method.BYTE_CODES: + executeByteCodes(bb, os); + break; + case JdwpConstants.CommandSet.Method.IS_OBSOLETE: + executeIsObsolete(bb, os); + break; + case JdwpConstants.CommandSet.Method.VARIABLE_TABLE_WITH_GENERIC: + executeVariableTableWithGeneric(bb, os); + break; + default: + throw new NotImplementedException( + "Command " + command + " not found in Method Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeLineTable(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + VMMethod method = VMMethod.readId(clazz, bb); + LineTable lt = method.getLineTable(); + lt.write(os); + } + + private void executeVariableTable(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + VMMethod method = VMMethod.readId(clazz, bb); + VariableTable vt = method.getVariableTable(); + vt.write(os); + } + + private void executeByteCodes(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canGetBytecodes) + { + String msg = "getting bytecodes is unsupported"; + throw new NotImplementedException(msg); + } + + ReferenceTypeId id = idMan.readReferenceTypeId(bb); + Class klass = id.getType(); + VMMethod method = VMMethod.readId(klass, bb); + byte[] bytecode = VMVirtualMachine.getBytecodes(method); + os.writeInt(bytecode.length); + os.write(bytecode); + } + + private void executeIsObsolete(ByteBuffer bb, DataOutputStream os) + throws IOException + { + // The debugger is really asking if this method has been redefined using + // VirtualMachineCommandSet.RedefineClasses. Since we don't implement that + // command the answer to this will always be false. + os.writeBoolean(false); + } + + private void executeVariableTableWithGeneric(ByteBuffer bb, + DataOutputStream os) + throws JdwpException + { + // We don't have generics yet + throw new NotImplementedException( + "Command VariableTableWithGeneric not implemented."); + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java new file mode 100644 index 000000000..f6bf8a656 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java @@ -0,0 +1,255 @@ +/* ObjectReferenceCommandSet.java -- class to implement the ObjectReference + Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMMethod; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.InvalidFieldException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.MethodResult; +import gnu.classpath.jdwp.util.MonitorInfo; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.ByteBuffer; + +/** + * A class representing the ObjectReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ObjectReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ObjectReference.REFERENCE_TYPE: + executeReferenceType(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.GET_VALUES: + executeGetValues(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.SET_VALUES: + executeSetValues(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.MONITOR_INFO: + executeMonitorInfo(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.INVOKE_METHOD: + executeInvokeMethod(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.DISABLE_COLLECTION: + executeDisableCollection(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.ENABLE_COLLECTION: + executeEnableCollection(bb, os); + break; + case JdwpConstants.CommandSet.ObjectReference.IS_COLLECTED: + executeIsCollected(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ObjectReference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeReferenceType(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object obj = oid.getObject(); + Class clazz = obj.getClass(); + ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); + refId.writeTagged(os); + } + + private void executeGetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object obj = oid.getObject(); + + int numFields = bb.getInt(); + + os.writeInt(numFields); // Looks pointless but this is the protocol + + for (int i = 0; i < numFields; i++) + { + Field field = (Field) idMan.readObjectId(bb).getObject(); + try + { + field.setAccessible(true); // Might be a private field + Object value = field.get(obj); + Value val = ValueFactory.createFromObject(value, + field.getType()); + val.writeTagged(os); + } + catch (IllegalArgumentException ex) + { + // I suppose this would best qualify as an invalid field then + throw new InvalidFieldException(ex); + } + catch (IllegalAccessException ex) + { + // Since we set it as accessible this really shouldn't happen + throw new JdwpInternalErrorException(ex); + } + } + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object obj = oid.getObject(); + + int numFields = bb.getInt(); + + for (int i = 0; i < numFields; i++) + { + Field field = (Field) idMan.readObjectId(bb).getObject(); + Object value = Value.getUntaggedObject(bb, field.getType()); + try + { + field.setAccessible(true); // Might be a private field + field.set(obj, value); + } + catch (IllegalArgumentException ex) + { + // I suppose this would best qualify as an invalid field then + throw new InvalidFieldException(ex); + } + catch (IllegalAccessException ex) + { + // Since we set it as accessible this really shouldn't happen + throw new JdwpInternalErrorException(ex); + } + } + } + + private void executeMonitorInfo(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canGetMonitorInfo) + { + String msg = "getting monitor info not supported"; + throw new NotImplementedException(msg); + } + + ObjectId oid = idMan.readObjectId(bb); + Object obj = oid.getObject(); + MonitorInfo info = VMVirtualMachine.getMonitorInfo(obj); + info.write(os); + } + + private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + Object obj = oid.getObject(); + + ObjectId tid = idMan.readObjectId(bb); + Thread thread = (Thread) tid.getObject(); + + ReferenceTypeId rid = idMan.readReferenceTypeId(bb); + Class clazz = rid.getType(); + + VMMethod method = VMMethod.readId(clazz, bb); + + int args = bb.getInt(); + Value[] values = new Value[args]; + + for (int i = 0; i < args; i++) + values[i] = ValueFactory.createFromTagged(bb); + + int invokeOptions = bb.getInt(); + MethodResult mr = VMVirtualMachine.executeMethod(obj, thread, + clazz, method, + values, invokeOptions); + Throwable exception = mr.getThrownException(); + ObjectId eId = idMan.getObjectId(exception); + mr.getReturnedValue().writeTagged(os); + eId.writeTagged(os); + } + + private void executeDisableCollection(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + oid.disableCollection(); + } + + private void executeEnableCollection(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + oid.enableCollection(); + } + + private void executeIsCollected(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + boolean collected = (oid.getReference().get () == null); + os.writeBoolean(collected); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/PacketProcessor.java b/libjava/classpath/gnu/classpath/jdwp/processor/PacketProcessor.java new file mode 100644 index 000000000..c4818aed8 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/PacketProcessor.java @@ -0,0 +1,221 @@ +/* PacketProcessor.java -- a thread which processes command packets + from the debugger + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.processor; + +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.transport.JdwpCommandPacket; +import gnu.classpath.jdwp.transport.JdwpConnection; +import gnu.classpath.jdwp.transport.JdwpPacket; +import gnu.classpath.jdwp.transport.JdwpReplyPacket; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.PrivilegedAction; + +/** + * This class is responsible for processing packets from the + * debugger. It waits for an available packet from the connection + * ({@link gnu.classpath.jdwp.transport.JdwpConnection}) and then + * processes the packet and any reply. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class PacketProcessor + implements PrivilegedAction +{ + // The connection to the debugger + private JdwpConnection _connection; + + // Shutdown this thread? + private boolean _shutdown; + + // A Mapping of the command set (Byte) to the specific CommandSet + private CommandSet[] _sets; + + // Contents of the ReplyPackets data field + private ByteArrayOutputStream _outputBytes; + + // Output stream around _outputBytes + private DataOutputStream _os; + + /** + * Constructs a new <code>PacketProcessor</code> object + * Connection must be validated before getting here! + * + * @param con the connection + */ + public PacketProcessor (JdwpConnection con) + { + _connection = con; + _shutdown = false; + + // MAXIMUM is the value of the largest command set we may receive + _sets = new CommandSet[JdwpConstants.CommandSet.MAXIMUM + 1]; + _outputBytes = new ByteArrayOutputStream(); + _os = new DataOutputStream (_outputBytes); + + // Create all the Command Sets and add them to our array + _sets[JdwpConstants.CommandSet.VirtualMachine.CS_VALUE] = + new VirtualMachineCommandSet(); + _sets[JdwpConstants.CommandSet.ReferenceType.CS_VALUE] = + new ReferenceTypeCommandSet(); + _sets[JdwpConstants.CommandSet.ClassType.CS_VALUE] = + new ClassTypeCommandSet(); + _sets[JdwpConstants.CommandSet.ArrayType.CS_VALUE] = + new ArrayTypeCommandSet(); + _sets[JdwpConstants.CommandSet.InterfaceType.CS_VALUE] = + new InterfaceTypeCommandSet(); + _sets[JdwpConstants.CommandSet.Method.CS_VALUE] = + new MethodCommandSet(); + _sets[JdwpConstants.CommandSet.Field.CS_VALUE] = + new FieldCommandSet(); + _sets[JdwpConstants.CommandSet.ObjectReference.CS_VALUE] = + new ObjectReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.StringReference.CS_VALUE] = + new StringReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.ThreadReference.CS_VALUE] = + new ThreadReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.ThreadGroupReference.CS_VALUE] = + new ThreadGroupReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.ArrayReference.CS_VALUE] = + new ArrayReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.ClassLoaderReference.CS_VALUE] = + new ClassLoaderReferenceCommandSet(); + _sets[JdwpConstants.CommandSet.EventRequest.CS_VALUE] = + new EventRequestCommandSet(); + _sets[JdwpConstants.CommandSet.StackFrame.CS_VALUE] = + new StackFrameCommandSet(); + _sets[JdwpConstants.CommandSet.ClassObjectReference.CS_VALUE] = + new ClassObjectReferenceCommandSet(); + } + + /** + * Main run routine for this thread. Will loop getting packets + * from the connection and processing them. + */ + public Object run () + { + // Notify initialization thread (gnu.classpath.jdwp.Jdwp) that + // the PacketProcessor thread is ready. + Jdwp.getDefault().subcomponentInitialized (); + + try + { + while (!_shutdown) + { + _processOnePacket (); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + // Time to shutdown, tell Jdwp to shutdown + Jdwp.getDefault().shutdown(); + return null; + } + + /** + * Shutdown the packet processor + */ + public void shutdown () + { + _shutdown = true; + } + + // Helper function which actually does all the work of waiting + // for a packet and getting it processed. + private void _processOnePacket () + throws IOException + { + JdwpPacket pkt = _connection.getPacket (); + + if (!(pkt instanceof JdwpCommandPacket)) + { + // We're not supposed to get these from the debugger! + // Drop it on the floor + return; + } + + if (pkt != null) + { + JdwpCommandPacket commandPkt = (JdwpCommandPacket) pkt; + JdwpReplyPacket reply = new JdwpReplyPacket(commandPkt); + + // Reset our output stream + _outputBytes.reset(); + + // Create a ByteBuffer around the command packet + ByteBuffer bb = ByteBuffer.wrap(commandPkt.getData()); + byte command = commandPkt.getCommand(); + byte commandSet = commandPkt.getCommandSet(); + + CommandSet set = null; + try + { + // There is no command set with value 0 + if (commandSet > 0 && commandSet < _sets.length) + { + set = _sets[commandPkt.getCommandSet()]; + } + if (set != null) + { + _shutdown = set.runCommand(bb, _os, command); + reply.setData(_outputBytes.toByteArray()); + } + else + { + // This command set wasn't in our tree + reply.setErrorCode(JdwpConstants.Error.NOT_IMPLEMENTED); + } + } + catch (JdwpException ex) + { + reply.setErrorCode(ex.getErrorCode ()); + } + _connection.sendPacket (reply); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java new file mode 100644 index 000000000..3489588df --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java @@ -0,0 +1,341 @@ +/* ReferenceTypeCommandSet.java -- class to implement the ReferenceType + Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMMethod; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.InvalidFieldException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Signature; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.ByteBuffer; + +/** + * A class representing the ReferenceType Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ReferenceTypeCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ReferenceType.SIGNATURE: + executeSignature(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.CLASS_LOADER: + executeClassLoader(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.MODIFIERS: + executeModifiers(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.FIELDS: + executeFields(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.METHODS: + executeMethods(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.GET_VALUES: + executeGetValues(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.SOURCE_FILE: + executeSourceFile(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.NESTED_TYPES: + executeNestedTypes(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.STATUS: + executeStatus(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.INTERFACES: + executeInterfaces(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.CLASS_OBJECT: + executeClassObject(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.SOURCE_DEBUG_EXTENSION: + executeSourceDebugExtension(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.SIGNATURE_WITH_GENERIC: + executeSignatureWithGeneric(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.FIELDS_WITH_GENERIC: + executeFieldWithGeneric(bb, os); + break; + case JdwpConstants.CommandSet.ReferenceType.METHODS_WITH_GENERIC: + executeMethodsWithGeneric(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ReferenceType Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeSignature(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + String sig = Signature.computeClassSignature(refId.getType()); + JdwpString.writeString(os, sig); + } + + private void executeClassLoader(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + + Class clazz = refId.getType(); + ClassLoader loader = clazz.getClassLoader(); + ObjectId oid = idMan.getObjectId(loader); + oid.write(os); + } + + private void executeModifiers(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + + Class clazz = refId.getType(); + os.writeInt(clazz.getModifiers()); + } + + private void executeFields(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + Field[] fields = clazz.getFields(); + os.writeInt(fields.length); + for (int i = 0; i < fields.length; i++) + { + Field field = fields[i]; + idMan.getObjectId(field).write(os); + JdwpString.writeString(os, field.getName()); + JdwpString.writeString(os, Signature.computeFieldSignature(field)); + os.writeInt(field.getModifiers()); + } + } + + private void executeMethods(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + VMMethod[] methods = VMVirtualMachine.getAllClassMethods(clazz); + os.writeInt (methods.length); + for (int i = 0; i < methods.length; i++) + { + VMMethod method = methods[i]; + method.writeId(os); + JdwpString.writeString(os, method.getName()); + JdwpString.writeString(os, method.getSignature()); + os.writeInt(method.getModifiers()); + } + } + + private void executeGetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + int numFields = bb.getInt(); + os.writeInt(numFields); // Looks pointless but this is the protocol + for (int i = 0; i < numFields; i++) + { + ObjectId fieldId = idMan.readObjectId(bb); + Field field = (Field) (fieldId.getObject()); + Class fieldClazz = field.getDeclaringClass(); + + // We don't actually need the clazz to get the field but we might as + // well check that the debugger got it right + if (fieldClazz.isAssignableFrom(clazz)) + { + try + { + field.setAccessible(true); // Might be a private field + Object value = field.get(null); + Value val = ValueFactory.createFromObject(value, + field.getType()); + val.writeTagged(os); + } + catch (IllegalArgumentException ex) + { + // I suppose this would best qualify as an invalid field then + throw new InvalidFieldException(ex); + } + catch (IllegalAccessException ex) + { + // Since we set it as accessible this really shouldn't happen + throw new JdwpInternalErrorException(ex); + } + } + else + throw new InvalidFieldException(fieldId.getId()); + } + } + + private void executeSourceFile(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + // We'll need to go into the jvm for this unless there's an easier way + String sourceFileName = VMVirtualMachine.getSourceFile(clazz); + JdwpString.writeString(os, sourceFileName); + // clazz.getProtectionDomain().getCodeSource().getLocation(); + } + + private void executeNestedTypes(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + Class[] declaredClazzes = clazz.getDeclaredClasses(); + os.writeInt(declaredClazzes.length); + for (int i = 0; i < declaredClazzes.length; i++) + { + Class decClazz = declaredClazzes[i]; + ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz); + clazzId.writeTagged(os); + } + } + + private void executeStatus(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + // I don't think there's any other way to get this + int status = VMVirtualMachine.getClassStatus(clazz); + os.writeInt(status); + } + + private void executeInterfaces(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + Class[] interfaces = clazz.getInterfaces(); + os.writeInt(interfaces.length); + for (int i = 0; i < interfaces.length; i++) + { + Class interfaceClass = interfaces[i]; + ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass); + intId.write(os); + } + } + + private void executeClassObject(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + ObjectId clazzObjectId = idMan.getObjectId(clazz); + clazzObjectId.write(os); + } + + private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canGetSourceDebugExtension) + { + String msg = "source debug extension is not supported"; + throw new NotImplementedException(msg); + } + + ReferenceTypeId id = idMan.readReferenceTypeId(bb); + String ext = VMVirtualMachine.getSourceDebugExtension (id.getType()); + JdwpString.writeString(os, ext); + } + + private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + // We don't have generics yet + throw new NotImplementedException( + "Command SignatureWithGeneric not implemented."); + } + + private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + // We don't have generics yet + throw new NotImplementedException( + "Command executeFieldWithGeneric not implemented."); + } + + private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + // We don't have generics yet + throw new NotImplementedException( + "Command executeMethodsWithGeneric not implemented."); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java new file mode 100644 index 000000000..2b82e05ff --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java @@ -0,0 +1,170 @@ +/* StackFrameCommandSet.java -- class to implement the StackFrame Command Set + 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMFrame; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.value.ObjectValue; +import gnu.classpath.jdwp.value.Value; +import gnu.classpath.jdwp.value.ValueFactory; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the StackFrame Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class StackFrameCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + boolean keepRunning = true; + try + { + switch (command) + { + case JdwpConstants.CommandSet.StackFrame.GET_VALUES: + executeGetValues(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.SET_VALUES: + executeSetValues(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.THIS_OBJECT: + executeThisObject(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.POP_FRAMES: + executePopFrames(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in Stack Frame Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeGetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tId = (ThreadId) idMan.readObjectId(bb); + Thread thread = tId.getThread(); + + // Although Frames look like other ids they are not. First they are not + // ObjectIds since they don't exist in the users code. Storing them as an + // ObjectId would mean they could be garbage collected since no one else + // has a reference to them. Furthermore they are not ReferenceTypeIds since + // these are held permanently and we want these to be held only as long as + // the Thread is suspended. + long frameID = bb.getLong(); + VMFrame frame = VMVirtualMachine.getFrame(thread, frameID); + int slots = bb.getInt(); + os.writeInt(slots); // Looks pointless but this is the protocol + for (int i = 0; i < slots; i++) + { + int slot = bb.getInt(); + byte sig = bb.get(); + Value val = frame.getValue(slot, sig); + val.writeTagged(os); + } + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tId = (ThreadId) idMan.readObjectId(bb); + Thread thread = tId.getThread(); + + long frameID = bb.getLong(); + VMFrame frame = VMVirtualMachine.getFrame(thread, frameID); + + int slots = bb.getInt(); + for (int i = 0; i < slots; i++) + { + int slot = bb.getInt(); + Value value = ValueFactory.createFromTagged(bb); + frame.setValue(slot, value); + } + } + + private void executeThisObject(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tId = (ThreadId) idMan.readObjectId(bb); + Thread thread = tId.getThread(); + + long frameID = bb.getLong(); + VMFrame frame = VMVirtualMachine.getFrame(thread, frameID); + + ObjectValue objVal = new ObjectValue(frame.getObject()); + objVal.writeTagged(os); + } + + private void executePopFrames(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canPopFrames) + { + String msg = "popping frames is unsupported"; + throw new NotImplementedException(msg); + } + + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + long fid = bb.getLong(); + VMVirtualMachine.popFrames(thread, fid); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java new file mode 100644 index 000000000..6571bc8e2 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java @@ -0,0 +1,99 @@ +/* StringReferenceCommandSet.java -- class to implement the StringReference + Command Set + 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.util.JdwpString; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the StringReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class StringReferenceCommandSet + extends CommandSet +{ + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + + // Although there's only a single command to choose from we still use + // a switch to maintain consistency with the rest of the CommandSets + switch (command) + { + case JdwpConstants.CommandSet.StringReference.VALUE: + executeValue(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in String Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeValue(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + + String str = (String) oid.getObject(); + JdwpString.writeString(os, str); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java new file mode 100644 index 000000000..7682fa9bf --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java @@ -0,0 +1,179 @@ +/* ThreadGroupReferenceCommandSet.java -- class to implement the + ThreadGroupReference Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.util.JdwpString; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the ThreadGroupReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ThreadGroupReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ThreadGroupReference.NAME: + executeName(bb, os); + break; + case JdwpConstants.CommandSet.ThreadGroupReference.PARENT: + executeParent(bb, os); + break; + case JdwpConstants.CommandSet.ThreadGroupReference.CHILDREN: + executeChildren(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ThreadGroupReference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeName(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + ThreadGroup group = (ThreadGroup) oid.getObject(); + JdwpString.writeString(os, group.getName()); + } + + private void executeParent(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + ThreadGroup group = (ThreadGroup) oid.getObject(); + ThreadGroup parent = group.getParent(); + if (parent == null) { + os.writeLong(0L); + } else { + ObjectId parentId = idMan.getObjectId(parent); + parentId.write(os); + } + } + + private void executeChildren(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oid = idMan.readObjectId(bb); + ThreadGroup group = (ThreadGroup) oid.getObject(); + + ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup(); + int numThreads = group.activeCount(); + Thread allThreads[] = new Thread[numThreads]; + + group.enumerate(allThreads, false); + + // We need to loop through for the true count since some threads may have + // been destroyed since we got activeCount so those spots in the array will + // be null. As well we must ignore any threads that belong to jdwp + numThreads = 0; + for (int i = 0; i < allThreads.length; i++) + { + Thread thread = allThreads[i]; + if (thread == null) + break; // No threads after this point + if (!thread.getThreadGroup().equals(jdwpGroup)) + numThreads++; + } + + os.writeInt(numThreads); + + for (int i = 0; i < allThreads.length; i++) + { + Thread thread = allThreads[i]; + if (thread == null) + break; // No threads after this point + if (!thread.getThreadGroup().equals(jdwpGroup)) + idMan.getObjectId(thread).write(os); + } + + int numGroups = group.activeCount(); + ThreadGroup allGroups[] = new ThreadGroup[numGroups]; + + group.enumerate(allGroups, false); + + // We need to loop through for the true count since some ThreadGroups may + // have been destroyed since we got activeCount so those spots in the array + // will be null. As well we must ignore any threads that belong to jdwp. + numGroups = 0; + for (int i = 0; i < allGroups.length; i++) + { + ThreadGroup tgroup = allGroups[i]; + if (tgroup == null) + break; // No ThreadGroups after this point + if (!tgroup.equals(jdwpGroup)) + numGroups++; + } + + os.writeInt(numGroups); + + for (int i = 0; i < allGroups.length; i++) + { + ThreadGroup tgroup = allGroups[i]; + if (tgroup == null) + break; // No ThreadGroups after this point + if (!tgroup.equals(jdwpGroup)) + idMan.getObjectId(tgroup).write(os); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java new file mode 100644 index 000000000..2bbff44de --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java @@ -0,0 +1,265 @@ +/* ThreadReferenceCommandSet.java -- class to implement the ThreadReference + Command Set 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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMFrame; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +/** + * A class representing the ThreadReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ThreadReferenceCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ThreadReference.NAME: + executeName(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.SUSPEND: + executeSuspend(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.RESUME: + executeResume(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.STATUS: + executeStatus(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.THREAD_GROUP: + executeThreadGroup(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.FRAMES: + executeFrames(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.FRAME_COUNT: + executeFrameCount(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.OWNED_MONITORS: + executeOwnedMonitors(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.CURRENT_CONTENDED_MONITOR: + executeCurrentContendedMonitor(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.STOP: + executeStop(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.INTERRUPT: + executeInterrupt(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.SUSPEND_COUNT: + executeSuspendCount(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in Thread Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return false; + } + + private void executeName(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + JdwpString.writeString(os, thread.getName()); + } + + private void executeSuspend(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + VMVirtualMachine.suspendThread(thread); + } + + private void executeResume(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + VMVirtualMachine.resumeThread(thread); + } + + private void executeStatus(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + int threadStatus = VMVirtualMachine.getThreadStatus(thread); + // There's only one possible SuspendStatus... + int suspendStatus = JdwpConstants.SuspendStatus.SUSPENDED; + + os.writeInt(threadStatus); + os.writeInt(suspendStatus); + } + + private void executeThreadGroup(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + ThreadGroup group = thread.getThreadGroup(); + ObjectId groupId = idMan.getObjectId(group); + groupId.write(os); + } + + private void executeFrames(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + int startFrame = bb.getInt(); + int length = bb.getInt(); + + ArrayList frames = VMVirtualMachine.getFrames(thread, startFrame, length); + os.writeInt(frames.size()); + for (int i = 0; i < frames.size(); i++) + { + VMFrame frame = (VMFrame) frames.get(i); + os.writeLong(frame.getId()); + Location loc = frame.getLocation(); + loc.write(os); + } + } + + private void executeFrameCount(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + + int frameCount = VMVirtualMachine.getFrameCount(thread); + os.writeInt(frameCount); + } + + private void executeOwnedMonitors(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canGetOwnedMonitorInfo) + { + String msg = "getting owned monitors is not supported"; + throw new NotImplementedException(msg); + } + + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + Object[] monitors = VMVirtualMachine.getOwnedMonitors(thread); + + os.write(monitors.length); + for (int i = 0; i < monitors.length; ++i) + { + ObjectId id = idMan.getObjectId(monitors[i]); + id.writeTagged(os); + } + } + + private void executeCurrentContendedMonitor(ByteBuffer bb, + DataOutputStream os) + throws JdwpException, IOException + { + if (!VMVirtualMachine.canGetCurrentContendedMonitor) + { + String msg = "getting current contended monitor is not supported"; + throw new NotImplementedException(msg); + } + + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + + Object monitor = VMVirtualMachine.getCurrentContendedMonitor(thread); + ObjectId id = idMan.getObjectId(monitor); + id.writeTagged(os); + } + + private void executeStop(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + ObjectId exception = idMan.readObjectId(bb); + Throwable throwable = (Throwable) exception.getObject(); + thread.stop (throwable); + } + + private void executeInterrupt(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + thread.interrupt(); + } + + private void executeSuspendCount(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readObjectId(bb); + Thread thread = tid.getThread(); + int suspendCount = VMVirtualMachine.getSuspendCount(thread); + os.writeInt(suspendCount); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java new file mode 100644 index 000000000..c476a04e9 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java @@ -0,0 +1,472 @@ +/* VirtualMachineCommandSet.java -- class to implement the VirtualMachine + Command Set + 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 +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.processor; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMFrame; +import gnu.classpath.jdwp.VMVirtualMachine; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Signature; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Properties; + +/** + * A class representing the VirtualMachine Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class VirtualMachineCommandSet + extends CommandSet +{ + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + boolean shutdown = false; + try + { + switch (command) + { + case JdwpConstants.CommandSet.VirtualMachine.VERSION: + executeVersion(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.CLASSES_BY_SIGNATURE: + executeClassesBySignature(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES: + executeAllClasses(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.ALL_THREADS: + executeAllThreads(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.TOP_LEVEL_THREAD_GROUPS: + executeTopLevelThreadGroups(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.IDSIZES: + executeIDsizes(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.DISPOSE: + shutdown = true; + executeDispose(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.SUSPEND: + executeSuspend(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.RESUME: + executeResume(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.EXIT: + shutdown = true; + executeExit(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING: + executeCreateString(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES: + executeCapabilities(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.CLASS_PATHS: + executeClassPaths(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.DISPOSE_OBJECTS: + executeDisposeObjects(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.HOLD_EVENTS: + executeHoldEvents(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.RELEASE_EVENTS: + executeReleaseEvents(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES_NEW: + executeCapabilitiesNew(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.REDEFINE_CLASSES: + executeRedefineClasses(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.SET_DEFAULT_STRATUM: + executeSetDefaultStratum(bb, os); + break; + case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES_WITH_GENERIC: + executeAllClassesWithGeneric(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in VirtualMachine Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + + return shutdown; + } + + private void executeVersion(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + + Properties props = System.getProperties(); + + int jdwpMajor = JdwpConstants.Version.MAJOR; + int jdwpMinor = JdwpConstants.Version.MINOR; + // The description field is pretty loosely defined + String description = "JDWP version " + jdwpMajor + "." + jdwpMinor + + ", JVM version " + props.getProperty("java.vm.name") + + " " + props.getProperty("java.vm.version") + " " + + props.getProperty("java.version"); + String vmVersion = props.getProperty("java.version"); + String vmName = props.getProperty("java.vm.name"); + JdwpString.writeString(os, description); + os.writeInt(jdwpMajor); + os.writeInt(jdwpMinor); + JdwpString.writeString(os, vmName); + JdwpString.writeString(os, vmVersion); + } + + private void executeClassesBySignature(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + String sig = JdwpString.readString(bb); + ArrayList allMatchingClasses = new ArrayList(); + + // This will be an Iterator over all loaded Classes + Collection classes = VMVirtualMachine.getAllLoadedClasses(); + Iterator iter = classes.iterator (); + + while (iter.hasNext()) + { + Class clazz = (Class) iter.next(); + String clazzSig = Signature.computeClassSignature(clazz); + if (clazzSig.equals(sig)) + allMatchingClasses.add(clazz); + } + + os.writeInt(allMatchingClasses.size()); + for (int i = 0; i < allMatchingClasses.size(); i++) + { + Class clazz = (Class) allMatchingClasses.get(i); + ReferenceTypeId id = idMan.getReferenceTypeId(clazz); + id.writeTagged(os); + int status = VMVirtualMachine.getClassStatus(clazz); + os.writeInt(status); + } + } + + private void executeAllClasses(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + Collection classes = VMVirtualMachine.getAllLoadedClasses(); + os.writeInt(classes.size ()); + + Iterator iter = classes.iterator (); + while (iter.hasNext()) + { + Class clazz = (Class) iter.next(); + ReferenceTypeId id = idMan.getReferenceTypeId(clazz); + id.writeTagged(os); + String sig = Signature.computeClassSignature(clazz); + JdwpString.writeString(os, sig); + int status = VMVirtualMachine.getClassStatus(clazz); + os.writeInt(status); + } + } + + private void executeAllThreads(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup(); + ThreadGroup root = getRootThreadGroup(jdwpGroup); + + int numThreads = root.activeCount(); + Thread allThreads[] = new Thread[numThreads]; + root.enumerate(allThreads); + + // We need to loop through for the true count since some threads may have + // been destroyed since we got + // activeCount so those spots in the array will be null. As well we must + // ignore any threads that belong to jdwp + numThreads = 0; + for (int i = 0; i < allThreads.length; i++) + { + Thread thread = allThreads[i]; + if (thread == null) + break; // No threads after this point + if (!thread.getThreadGroup().equals(jdwpGroup)) + numThreads++; + } + + os.writeInt(numThreads); + + for (int i = 0; i < allThreads.length; i++) + { + Thread thread = allThreads[i]; + if (thread == null) + break; // No threads after this point + if (!thread.getThreadGroup().equals(jdwpGroup)) + idMan.getObjectId(thread).write(os); + } + } + + private void executeTopLevelThreadGroups(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup (); + ThreadGroup root = getRootThreadGroup(jdwpGroup); + + os.writeInt(1); // Just one top level group allowed? + idMan.getObjectId(root).write(os); + } + + private void executeDispose(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // resumeAllThreads isn't sufficient as a thread may have been + // suspended multiple times, we likely need a way to keep track of how many + // times a thread has been suspended or else a stronger resume method for + // this purpose + // VMVirtualMachine.resumeAllThreads (); + + // Simply shutting down the jdwp layer will take care of the rest of the + // shutdown other than disabling debugging in the VM + // VMVirtualMachine.disableDebugging(); + + // Don't implement this until we're sure how to remove all the debugging + // effects from the VM. + throw new NotImplementedException( + "Command VirtualMachine.Dispose not implemented"); + + } + + private void executeIDsizes(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + os.writeInt(ObjectId.SIZE); // fieldId FIXME + os.writeInt(ObjectId.SIZE); // methodId FIXME + os.writeInt(ObjectId.SIZE); // objectId + os.writeInt(ReferenceTypeId.SIZE); // referenceTypeId + os.writeInt(VMFrame.SIZE); // frameId + } + + private void executeSuspend(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + VMVirtualMachine.suspendAllThreads (); + } + + private void executeResume(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + VMVirtualMachine.resumeAllThreads (); + } + + private void executeExit(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + int exitCode = bb.getInt(); + System.exit (exitCode); + } + + private void executeCreateString(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + String string = JdwpString.readString(bb); + ObjectId stringId = idMan.getObjectId(string); + + // Since this string isn't referenced anywhere we'll disable garbage + // collection on it so it's still around when the debugger gets back to it. + stringId.disableCollection(); + stringId.write(os); + } + + private void executeCapabilities(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + os.writeBoolean(VMVirtualMachine.canWatchFieldModification); + os.writeBoolean(VMVirtualMachine.canWatchFieldAccess); + os.writeBoolean(VMVirtualMachine.canGetBytecodes); + os.writeBoolean(VMVirtualMachine.canGetSyntheticAttribute); + os.writeBoolean(VMVirtualMachine.canGetOwnedMonitorInfo); + os.writeBoolean(VMVirtualMachine.canGetCurrentContendedMonitor); + os.writeBoolean(VMVirtualMachine.canGetMonitorInfo); + } + + private void executeClassPaths(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + String baseDir = System.getProperty("user.dir"); + JdwpString.writeString(os, baseDir); + + // Find and write the classpath + String classPath = System.getProperty("java.class.path"); + String[] paths = classPath.split(":"); + + os.writeInt(paths.length); + for (int i = 0; i < paths.length; i++) + JdwpString.writeString(os, paths[i]); + + // Now the bootpath + String bootPath = System.getProperty("sun.boot.class.path"); + paths = bootPath.split(":"); + os.writeInt(paths.length); + for (int i = 0; i < paths.length; i++) + JdwpString.writeString(os, paths[i]); + } + + private void executeDisposeObjects(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // Instead of going through the list of objects they give us it's probably + // better just to find the garbage collected objects ourselves + //idMan.update(); + } + + private void executeHoldEvents(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // Going to have to implement a send queue somewhere and do this without + // triggering events + // Until then just don't implement + throw new NotImplementedException( + "Command VirtualMachine.HoldEvents not implemented"); + } + + // Opposite of executeHoldEvents + private void executeReleaseEvents(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + throw new NotImplementedException( + "Command VirtualMachine.ReleaseEvents not implemented"); + } + + private void executeCapabilitiesNew(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + final int CAPABILITIES_NEW_SIZE = 32; + + executeCapabilities(bb, os); + os.writeBoolean(VMVirtualMachine.canRedefineClasses); + os.writeBoolean(VMVirtualMachine.canAddMethod); + os.writeBoolean(VMVirtualMachine.canUnrestrictedlyRedefineClasses); + os.writeBoolean(VMVirtualMachine.canPopFrames); + os.writeBoolean(VMVirtualMachine.canUseInstanceFilters); + os.writeBoolean(VMVirtualMachine.canGetSourceDebugExtension); + os.writeBoolean(VMVirtualMachine.canRequestVMDeathEvent); + os.writeBoolean(VMVirtualMachine.canSetDefaultStratum); + for (int i = 15; i < CAPABILITIES_NEW_SIZE; i++) + { + // Future capabilities (currently unused) + os.writeBoolean(false); + } + } + + private void executeRedefineClasses(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + if (!VMVirtualMachine.canRedefineClasses) + { + String msg = "redefinition of classes is not supported"; + throw new NotImplementedException(msg); + } + + int classes = bb.getInt(); + Class[] types = new Class[classes]; + byte[][] bytecodes = new byte[classes][]; + for (int i = 0; i < classes; ++i) + { + ReferenceTypeId id = idMan.readReferenceTypeId(bb); + int classfile = bb.getInt(); + byte[] bytecode = new byte[classfile]; + bb.get(bytecode); + types[i] = id.getType(); + bytecodes[i] = bytecode; + } + + VMVirtualMachine.redefineClasses (types, bytecodes); + } + + private void executeSetDefaultStratum(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + if (!VMVirtualMachine.canSetDefaultStratum) + { + String msg = "setting the default stratum is not supported"; + throw new NotImplementedException(msg); + } + + String stratum = JdwpString.readString(bb); + VMVirtualMachine.setDefaultStratum(stratum); + } + + private void executeAllClassesWithGeneric(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // We don't handle generics + throw new NotImplementedException( + "Command VirtualMachine.AllClassesWithGeneric not implemented"); + } + + /** + * Find the root ThreadGroup of this ThreadGroup + */ + private ThreadGroup getRootThreadGroup(ThreadGroup group) + { + ThreadGroup parent = group.getParent(); + + while (parent != null) + { + group = parent; + parent = group.getParent(); + } + return group; // This group was the root + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/transport/ITransport.java b/libjava/classpath/gnu/classpath/jdwp/transport/ITransport.java new file mode 100644 index 000000000..cf5542560 --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/JdwpCommandPacket.java b/libjava/classpath/gnu/classpath/jdwp/transport/JdwpCommandPacket.java new file mode 100644 index 000000000..c565ee779 --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/JdwpConnection.java b/libjava/classpath/gnu/classpath/jdwp/transport/JdwpConnection.java new file mode 100644 index 000000000..3c91f048e --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/JdwpPacket.java b/libjava/classpath/gnu/classpath/jdwp/transport/JdwpPacket.java new file mode 100644 index 000000000..b967d9bc5 --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/JdwpReplyPacket.java b/libjava/classpath/gnu/classpath/jdwp/transport/JdwpReplyPacket.java new file mode 100644 index 000000000..a8dc9978e --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/SocketTransport.java b/libjava/classpath/gnu/classpath/jdwp/transport/SocketTransport.java new file mode 100644 index 000000000..4872ba176 --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/TransportException.java b/libjava/classpath/gnu/classpath/jdwp/transport/TransportException.java new file mode 100644 index 000000000..057422a87 --- /dev/null +++ b/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/libjava/classpath/gnu/classpath/jdwp/transport/TransportFactory.java b/libjava/classpath/gnu/classpath/jdwp/transport/TransportFactory.java new file mode 100644 index 000000000..681967b77 --- /dev/null +++ b/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"); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/JdwpString.java b/libjava/classpath/gnu/classpath/jdwp/util/JdwpString.java new file mode 100644 index 000000000..eca7060fd --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/JdwpString.java @@ -0,0 +1,95 @@ +/* JdwpString.java -- utility class to read and write jdwp strings + 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 +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.util; + +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +/** + * A class to compute the JDWP representation of Strings. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class JdwpString +{ + + /** + * Write this String to the outStream as a string understood by jdwp. + * + * @param os write the String here + * @param string the String to write + * @throws IOException + */ + public static void writeString(DataOutputStream os, String string) + throws IOException + { + // Get the bytes of the string as a string in UTF-8 + byte[] strBytes = string.getBytes("UTF-8"); + os.writeInt(strBytes.length); + os.write(strBytes); + } + + /** + * Read a jdwp style string from the ByteBuffer. + * + * @param bb contains the string + * @return the String that was read + * @throws JdwpInternalErrorException bb didn't contain a value UTF-8 string + */ + public static String readString(ByteBuffer bb) + throws JdwpInternalErrorException + { + int length = bb.getInt(); + byte[] strBytes = new byte[length]; + bb.get(strBytes); + try + { + return new String(strBytes, "UTF-8"); + } + catch (UnsupportedEncodingException ex) + { + // Any string from the VM should be in UTF-8 so an encoding error + // shouldn't be possible + throw new JdwpInternalErrorException(ex); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/LineTable.java b/libjava/classpath/gnu/classpath/jdwp/util/LineTable.java new file mode 100644 index 000000000..2307fa27e --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/LineTable.java @@ -0,0 +1,95 @@ +/* LineTable.java -- A class representing a Line Table for a method + Copyright (C) 2005, 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +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.io.DataOutputStream; +import java.io.IOException; + +/** + * A class representing a Line Table for a method. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class LineTable +{ + + private final long start; + private final long end; + private final int[] lineNum; + private final long[] lineCI; + + /** + * Construct a line table with the given parameters. + * + * @param start lowest code index for method, -1 if native + * @param end highest code index for method, -1 if native + * @param lineNum line numbers for in line tables + * @param lineCI code indicies for entries in line tables + */ + public LineTable(long start, long end, int[] lineNum, long[] lineCI) + { + if (lineNum.length != lineCI.length) + throw new AssertionError("code index and line numbers tables " + + "not same length"); + this.start = start; + this.end = end; + this.lineNum = lineNum; + this.lineCI = lineCI; + } + + /** + * Writes this line table to the given DataOutputStream. + * + * @param os the stream to write it to + * @throws IOException + */ + public void write(DataOutputStream os) + throws IOException + { + os.writeLong(start); + os.writeLong(end); + os.writeInt(lineNum.length); + for (int i = 0; i < lineNum.length; i++) + { + os.writeLong(lineCI[i]); + os.writeInt(lineNum[i]); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/Location.java b/libjava/classpath/gnu/classpath/jdwp/util/Location.java new file mode 100644 index 000000000..6d8c2e7b9 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/Location.java @@ -0,0 +1,168 @@ +/* Location.java -- class to read/write JDWP locations + 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 +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.VMMethod; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.id.ClassReferenceTypeId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class to read/write JDWP locations. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class Location +{ + private VMMethod method; + private long index; + + /** + * Create a location with the given parameters. + * + * @param method the method + * @param index location in the method + */ + public Location(VMMethod method, long index) + { + this.method = method; + this.index = index; + } + + /** + * Read a location from the given bytebuffer, consists of a TAG (byte), + * followed by a ReferenceTypeId, a MethodId and an index (long). + * + * @param bb this holds the location + * @throws IOException when an error occurs reading from the buffer + * @throws JdwpException for invalid class or method IDs + */ + public Location(ByteBuffer bb) + throws IOException, JdwpException + { + byte tag = bb.get(); + ClassReferenceTypeId classId = + (ClassReferenceTypeId) VMIdManager.getDefault().readReferenceTypeId(bb); + Class klass = classId.getType(); + method = VMMethod.readId(klass, bb); + index = bb.getLong(); + } + + /** + * Write the given location to an output stream. + * + * @param os stream to write to + * @throws IOException when an error occurs writing to the stream + */ + public void write(DataOutputStream os) + throws IOException + { + // check if this is an empty location + if (method != null) + { + VMIdManager idm = VMIdManager.getDefault(); + ClassReferenceTypeId crti = + (ClassReferenceTypeId) + idm.getReferenceTypeId(method.getDeclaringClass()); + + crti.writeTagged(os); + method.writeId(os); + os.writeLong(index); + } + else + { + os.writeByte(1); + os.writeLong((long) 0); + os.writeLong((long) 0); + os.writeLong((long) 0); + } + } + + /** + * Sets up an empty location + * + * @return new Location (setup as empty) + */ + public static Location getEmptyLocation() + { + return new Location(null, 0); + } + + /** + * Gets the method of this location + * + * @return the method + */ + public VMMethod getMethod() + { + return method; + } + + /** + * Gets the code index of this location + * + * @return the code index + */ + public long getIndex () + { + return index; + } + + // convenient for debugging + public String toString () + { + return method.toString () + "." + index; + } + + public boolean equals(Object obj) + { + if (obj instanceof Location) + { + Location l = (Location) obj; + return (getMethod().equals(l.getMethod()) + && getIndex() == l.getIndex()); + } + + return false; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/MethodResult.java b/libjava/classpath/gnu/classpath/jdwp/util/MethodResult.java new file mode 100644 index 000000000..76d8828f6 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/MethodResult.java @@ -0,0 +1,86 @@ +/* MethodResult.java -- class to wrap around values returned from a Method call + in the VM + 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.util; + +import gnu.classpath.jdwp.value.Value; + +/** + * A class to wrap around values returned from a Method call in the VM. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class MethodResult +{ + // The Object returned by the executing method + private Value returnedValue; + + // Any Exception that was thrown by the executing method + private Throwable thrownException; + + /** + * Constructs a new MethodResult object + * + * @param return_value the return value of the method invocation + * @param exc exception thrown during the invocation (or null if none) + */ + public MethodResult (Value return_value, Throwable exc) + { + returnedValue = return_value; + thrownException = exc; + } + + /** + * Returns the return value of the method invocation + */ + public Value getReturnedValue() + { + return returnedValue; + } + + /** + * Returns the exception thrown during the method invocation + * (or null if none) + */ + public Throwable getThrownException() + { + return thrownException; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/MonitorInfo.java b/libjava/classpath/gnu/classpath/jdwp/util/MonitorInfo.java new file mode 100644 index 000000000..34c098da2 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/MonitorInfo.java @@ -0,0 +1,76 @@ +/* MonitorInfo.java -- class used to return monitor information + for JDWP. + + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * This class is used to pass monitor information between + * the JDWP back-end and the virtual machine. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class MonitorInfo +{ + public int entryCount; + public Thread owner; + public Thread[] waiters; + + public void write(DataOutputStream os) + throws IOException + { + VMIdManager idm = VMIdManager.getDefault(); + ObjectId id = idm.getObjectId(owner); + id.write(os); + os.write(entryCount); + os.write(waiters.length); + for (int i = 0; i < waiters.length; ++i) + { + id = idm.getObjectId(waiters[i]); + id.write(os); + } + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/NullObject.java b/libjava/classpath/gnu/classpath/jdwp/util/NullObject.java new file mode 100644 index 000000000..ec762fc2f --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/NullObject.java @@ -0,0 +1,50 @@ +/* NullObject.java -- placeholder for null values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.util; + +/** + * This is a placeholder for null. There are several places in JDWP where null + * is a valid value (i.e. when geting the value of a variable slot that + * contains a null reference at that time). This class distinguishes between + * these "meaningful" null values and invalid null pointers. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public class NullObject +{ +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/Signature.java b/libjava/classpath/gnu/classpath/jdwp/util/Signature.java new file mode 100644 index 000000000..3d192e897 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/Signature.java @@ -0,0 +1,151 @@ +/* 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., 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.util; + +import gnu.java.lang.CPStringBuilder; + +import java.lang.reflect.Field; +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) + { + CPStringBuilder sb = new CPStringBuilder (); + _addToSignature (sb, theClass); + return sb.toString (); + } + + /** + * Computes the field signature which is just the class signature of the + * field's type, ie a Field of type java.lang.String this will return + * "Ljava/lang/String;". + * + * @param field the field for which to compute the signature + * @return the field's type signature + */ + public static String computeFieldSignature (Field field) + { + return computeClassSignature (field.getType()); + } + + /** + * 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) + { + CPStringBuilder sb = new CPStringBuilder ("("); + 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 (CPStringBuilder 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(';'); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/util/VariableTable.java b/libjava/classpath/gnu/classpath/jdwp/util/VariableTable.java new file mode 100644 index 000000000..8cbb299c2 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/util/VariableTable.java @@ -0,0 +1,110 @@ +/* VariableTable.java -- A class representing a Variable Table for a method + 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.util; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A class representing a Variable Table for a method. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class VariableTable +{ + + private final int argCnt; + + private final int slots; + + private final long[] lineCI; + + private int[] slot; + + private int[] lengths; + + private String[] sigs; + + private String[] names; + + /** + * Make a new variable table with the given values. + * + * @param argCnt number of words used by arguments in this frame + * @param slots number of variables + * @param lineCI first code index of given variable (size slots) + * @param names name of given variable (size slots) + * @param sigs signature of given variable (size slots) + * @param lengths size of region where variable is active (size slots) + * @param slot index of variable in this frame (size slots) + */ + public VariableTable(int argCnt, int slots, long lineCI[], String names[], + String sigs[], int lengths[], int slot[]) + { + this.argCnt = argCnt; + this.slots = slots; + this.lineCI = lineCI; + this.names = names; + this.sigs = sigs; + this.lengths = lengths; + this.slot = slot; + } + + /** + * Writes this line table to the given DataOutputStream. + * + * @param os the stream to write it to + * @throws IOException + */ + public void write(DataOutputStream os) throws IOException + { + os.writeInt(argCnt); + os.writeInt(slots); + for (int i = 0; i < slots; i++) + { + os.writeLong(lineCI[i]); + JdwpString.writeString(os, names[i]); + JdwpString.writeString(os, sigs[i]); + os.writeInt(lengths[i]); + os.writeInt(slot[i]); + } + } + +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/ArrayValue.java b/libjava/classpath/gnu/classpath/jdwp/value/ArrayValue.java new file mode 100644 index 000000000..69b1ebd2a --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/ArrayValue.java @@ -0,0 +1,92 @@ +/* ObjectValue.java -- JDWP wrapper class for an Object value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an Array value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public class ArrayValue + extends Value +{ + // The Array wrapped by this class represented as a Object + Object _value; + + /** + * Create a new ArrayValue from an Object + * + * @param value the Object to wrap + */ + public ArrayValue(Object value) + { + super(JdwpConstants.Tag.ARRAY); + _value = value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return _value; + } + + /** + * Write the wrapped object to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + ObjectId oid = VMIdManager.getDefault().getObjectId(_value); + oid.write(os); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/BooleanValue.java b/libjava/classpath/gnu/classpath/jdwp/value/BooleanValue.java new file mode 100644 index 000000000..1ae5b4dee --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/BooleanValue.java @@ -0,0 +1,99 @@ +/* BooleanValue.java -- JDWP wrapper class for a boolean value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an boolean value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class BooleanValue + extends Value +{ + // The boolean wrapped by this class + boolean _value; + + /** + * Create a new BooleanValue from an boolean + * + * @param value the boolean to wrap + */ + public BooleanValue(boolean value) + { + super(JdwpConstants.Tag.BOOLEAN); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public boolean getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Boolean(_value); + } + + /** + * Write the wrapped boolean to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeBoolean(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/ByteValue.java b/libjava/classpath/gnu/classpath/jdwp/value/ByteValue.java new file mode 100644 index 000000000..64de0dc88 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/ByteValue.java @@ -0,0 +1,99 @@ +/* ByteValue.java -- JDWP wrapper class for a byte value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an byte value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class ByteValue + extends Value +{ + // The byte wrapped by this class + byte _value; + + /** + * Create a new ByteValue from an byte + * + * @param value the byte to wrap + */ + public ByteValue(byte value) + { + super(JdwpConstants.Tag.BYTE); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public byte getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Byte(_value); + } + + /** + * Write the wrapped byte to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeByte(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/CharValue.java b/libjava/classpath/gnu/classpath/jdwp/value/CharValue.java new file mode 100644 index 000000000..3781065a6 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/CharValue.java @@ -0,0 +1,99 @@ +/* CharValue.java -- JDWP wrapper class for a char value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an char value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class CharValue + extends Value +{ + // The char wrapped by this class + char _value; + + /** + * Create a new CharValue from an char + * + * @param value the char to wrap + */ + public CharValue(char value) + { + super(JdwpConstants.Tag.CHAR); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public char getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Character(_value); + } + + /** + * Write the wrapped char to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeChar(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/DoubleValue.java b/libjava/classpath/gnu/classpath/jdwp/value/DoubleValue.java new file mode 100644 index 000000000..1c9a8714d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/DoubleValue.java @@ -0,0 +1,99 @@ +/* DoubleValue.java -- JDWP wrapper class for a double value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an double value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class DoubleValue + extends Value +{ + // The double wrapped by this class + double _value; + + /** + * Create a new DoubleValue from an double + * + * @param value the double to wrap + */ + public DoubleValue(double value) + { + super(JdwpConstants.Tag.DOUBLE); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public double getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Double(_value); + } + + /** + * Write the wrapped double to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeDouble(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/FloatValue.java b/libjava/classpath/gnu/classpath/jdwp/value/FloatValue.java new file mode 100644 index 000000000..ffd79f660 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/FloatValue.java @@ -0,0 +1,99 @@ +/* FloatValue.java -- JDWP wrapper class for a float value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +afloat with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an float value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class FloatValue + extends Value +{ + // The float wrapped by this class + float _value; + + /** + * Create a new FloatValue from an float + * + * @param value the float to wrap + */ + public FloatValue(float value) + { + super(JdwpConstants.Tag.FLOAT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public float getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Float(_value); + } + + /** + * Write the wrapped float to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeFloat(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/IntValue.java b/libjava/classpath/gnu/classpath/jdwp/value/IntValue.java new file mode 100644 index 000000000..b1a07fd1e --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/IntValue.java @@ -0,0 +1,99 @@ +/* IntValue.java -- JDWP wrapper class for an int value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an int value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class IntValue + extends Value +{ + // The int wrapped by this class + int _value; + + /** + * Create a new IntValue from an int + * + * @param value the int to wrap + */ + public IntValue(int value) + { + super(JdwpConstants.Tag.INT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public int getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Integer(_value); + } + + /** + * Write the wrapped int to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeInt(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/LongValue.java b/libjava/classpath/gnu/classpath/jdwp/value/LongValue.java new file mode 100644 index 000000000..748311708 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/LongValue.java @@ -0,0 +1,99 @@ +/* LongValue.java -- JDWP wrapper class for a long value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an long value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class LongValue + extends Value +{ + // The long wrapped by this class + long _value; + + /** + * Create a new LongValue from an long + * + * @param value the long to wrap + */ + public LongValue(long value) + { + super(JdwpConstants.Tag.LONG); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public long getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Long(_value); + } + + /** + * Write the wrapped long to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeLong(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/ObjectValue.java b/libjava/classpath/gnu/classpath/jdwp/value/ObjectValue.java new file mode 100644 index 000000000..d7dc7dae9 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/ObjectValue.java @@ -0,0 +1,102 @@ +/* ObjectValue.java -- JDWP wrapper class for an Object value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an Object value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class ObjectValue + extends Value +{ + // The Object wrapped by this class + Object _value; + + /** + * Create a new ObjectValue from an Object + * + * @param value the Object to wrap + */ + public ObjectValue(Object value) + { + super(JdwpConstants.Tag.OBJECT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public Object getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return _value; + } + + /** + * Write the wrapped object to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + ObjectId oid = VMIdManager.getDefault().getObjectId(_value); + oid.write(os); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/ShortValue.java b/libjava/classpath/gnu/classpath/jdwp/value/ShortValue.java new file mode 100644 index 000000000..16fae4759 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/ShortValue.java @@ -0,0 +1,99 @@ +/* ShortValue.java -- JDWP wrapper class for a short value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an short value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class ShortValue + extends Value +{ + // The short wrapped by this class + short _value; + + /** + * Create a new ShortValue from a short + * + * @param value the short to wrap + */ + public ShortValue(short value) + { + super(JdwpConstants.Tag.SHORT); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public short getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return new Short(_value); + } + + /** + * Write the wrapped short to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + os.writeShort(_value); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/StringValue.java b/libjava/classpath/gnu/classpath/jdwp/value/StringValue.java new file mode 100644 index 000000000..f64661f9f --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/StringValue.java @@ -0,0 +1,103 @@ +/* StringValue.java -- JDWP wrapper class for an String value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an String value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public final class StringValue + extends Value +{ + // The String wrapped by this class + String _value; + + /** + * Create a new StringValue from an String + * + * @param value the String to wrap + */ + public StringValue(String value) + { + super(JdwpConstants.Tag.STRING); + _value = value; + } + + /** + * Get the value held in this Value + * + * @return the value represented by this Value object + */ + public String getValue() + { + return _value; + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return _value; + } + + /** + * Write the wrapped object to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + ObjectId oid = VMIdManager.getDefault().getObjectId (_value); + oid.write (os); + + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/Value.java b/libjava/classpath/gnu/classpath/jdwp/value/Value.java new file mode 100644 index 000000000..39f1c9cce --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/Value.java @@ -0,0 +1,155 @@ +/* Value.java -- base class of JDWP values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.InvalidTagException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * Superclass for all JDWP Values. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public abstract class Value +{ + // A Tag representing the type of this value + private byte _tag; + + /** + * Create a new value of type tag. + * + * @param tag the type of the value + */ + protected Value(byte tag) + { + _tag = tag; + } + + /** + * Get the tag for this Value + * + * @return the byte tag of this Value + */ + public byte getTag() + { + return _tag; + } + + /** + * Calls the dervied classes writeValue method to write its value to the + * DataOutputStream. + * + * @param os write the value here + * @throws IOException + */ + public void writeUntagged(DataOutputStream os) + throws IOException + { + write(os); + } + + /** + * Will write the given object as a tagged value to the DataOutputStream. + * + * @param os write the value here + * @param obj the Object to write + * @throws IOException + */ + public void writeTagged(DataOutputStream os) + throws IOException + { + os.write (_tag); + write(os); + } + + /** + * This method must write the value to the DataOutputStream in a manner + * appropriate for the type of the value. + * + * @param os DataOutputStream to write to + * @throws IOException + */ + protected abstract void write(DataOutputStream os) + throws IOException; + + /** + * Returns an object representing this type + * + * @return an Object represntation of this value + */ + protected abstract Object getObject(); + + /** + * Get an untagged object from the ByteBuffer + * + * @param bb the ByteBuffer to extract the value from + * @param type a Class representing the type + * @return an Object from the ByteBuffer of the type of the Class parameter + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Object getUntaggedObject(ByteBuffer bb, Class type) + throws JdwpInternalErrorException, InvalidObjectException, InvalidClassException + { + Value val = ValueFactory.createFromUntagged(bb, type); + return val.getObject(); + } + + /** + * Get an untagged object from the ByteBuffer + * + * @param bb the ByteBuffer to extract the value from + * @param tag a byte tag representing the type + * @return an Object from the ByteBuffer of the type of the Class parameter + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Object getTaggedObject(ByteBuffer bb) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + Value val = ValueFactory.createFromTagged(bb); + return val.getObject(); + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/ValueFactory.java b/libjava/classpath/gnu/classpath/jdwp/value/ValueFactory.java new file mode 100644 index 000000000..ee7ddfae1 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/ValueFactory.java @@ -0,0 +1,247 @@ +/* ValueFactory.java -- factory to create JDWP Values + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.VMIdManager; +import gnu.classpath.jdwp.exception.InvalidClassException; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.InvalidTagException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.util.JdwpString; + +import java.nio.ByteBuffer; + +/** + * A factory to create JDWP Values. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public class ValueFactory +{ + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer + * by reading the tag byte from the front of the buffer. + * + * @param bb contains the Object + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Value createFromTagged(ByteBuffer bb) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + return create(bb, bb.get()); + } + + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer + * by checking the type of the Class passed in. + * + * @param bb contains the Object + * @param type a Class representing the type of the value in the ByteBuffer + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + public static Value createFromUntagged(ByteBuffer bb, Class type) + throws JdwpInternalErrorException, InvalidObjectException, InvalidClassException + { + byte tag = getTagForClass(type); + + try + { + return create(bb, tag); + } + catch (InvalidTagException ite) + { + throw new InvalidClassException(ite); + } + } + + /** + * Creates a new Value of appropriate type for the value in the ByteBuffer. + * + * @param bb contains the Object + * @param tag a byte representing the type of the object + * @return A new Value of appropriate type + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + private static Value create(ByteBuffer bb, byte tag) + throws JdwpInternalErrorException, InvalidObjectException, InvalidTagException + { + Value val = null; + switch(tag) + { + case JdwpConstants.Tag.BYTE: + val = new ByteValue(bb.get()); + break; + case JdwpConstants.Tag.BOOLEAN: + val = new BooleanValue((bb.get() != 0)); + break; + case JdwpConstants.Tag.CHAR: + val = new CharValue(bb.getChar()); + break; + case JdwpConstants.Tag.SHORT: + val = new ShortValue(bb.getShort()); + break; + case JdwpConstants.Tag.INT: + val = new IntValue(bb.getInt()); + break; + case JdwpConstants.Tag.FLOAT: + val = new FloatValue(bb.getFloat()); + break; + case JdwpConstants.Tag.LONG: + val = new LongValue(bb.getLong()); + break; + case JdwpConstants.Tag.DOUBLE: + val = new DoubleValue(bb.getDouble()); + break; + case JdwpConstants.Tag.VOID: + val = new VoidValue(); + break; + case JdwpConstants.Tag.ARRAY: + case JdwpConstants.Tag.THREAD: + case JdwpConstants.Tag.OBJECT: + case JdwpConstants.Tag.THREAD_GROUP: + case JdwpConstants.Tag.CLASS_LOADER: + case JdwpConstants.Tag.CLASS_OBJECT: + ObjectId oid = VMIdManager.getDefault().readObjectId(bb); + val = new ObjectValue(oid.getObject()); + break; + case JdwpConstants.Tag.STRING: + val = new StringValue(JdwpString.readString(bb)); + break; + default: + throw new InvalidTagException(tag); + } + + return val; + } + + /** + * Creates a tag for the type of the class. + * + * @param klass the type to get a tag for + * @return a byte tag representing the class + * @throws JdwpInternalErrorException + * @throws InvalidObjectException + */ + private static byte getTagForClass(Class klass) + throws JdwpInternalErrorException + { + byte tag; + + if (klass.isPrimitive()) + { + if (klass == byte.class) + tag = JdwpConstants.Tag.BYTE; + else if (klass == boolean.class) + tag = JdwpConstants.Tag.BOOLEAN; + else if (klass == char.class) + tag = JdwpConstants.Tag.CHAR; + else if (klass == short.class) + tag = JdwpConstants.Tag.SHORT; + else if (klass == int.class) + tag = JdwpConstants.Tag.INT; + else if (klass == float.class) + tag = JdwpConstants.Tag.FLOAT; + else if (klass == long.class) + tag = JdwpConstants.Tag.LONG; + else if (klass == double.class) + tag = JdwpConstants.Tag.DOUBLE; + else if (klass == void.class) + tag = JdwpConstants.Tag.VOID; + else + throw new JdwpInternalErrorException("Invalid primitive class"); + } + else + { + tag = JdwpConstants.Tag.OBJECT; + } + + return tag; + } + + /** + * Create a value type for an Object of type determined by a Class. This is + * a special case where a value needs to be created, but the value to create + * it for is already in an object, not in a buffer. + * + * @param value the Object to convert to a Value + * @param type the Class type of the object + * @return a new Value representing this object + */ + public static Value createFromObject(Object value, Class type) + { + Value val = null; + + if (type.isPrimitive()) + { + if (type == byte.class) + val = new ByteValue(((Byte) value).byteValue()); + else if (type == boolean.class) + val = new BooleanValue(((Boolean) value).booleanValue()); + else if (type == char.class) + val = new CharValue(((Character) value).charValue()); + else if (type == short.class) + val = new ShortValue(((Short) value).shortValue()); + else if (type == int.class) + val = new IntValue(((Integer) value).intValue()); + else if (type == float.class) + val = new FloatValue(((Float) value).floatValue()); + else if (type == long.class) + val = new LongValue(((Long) value).longValue()); + else if (type == double.class) + val = new DoubleValue(((Double) value).doubleValue()); + else if (type == void.class) + val = new VoidValue(); + } + else + { + if (type.isAssignableFrom(String.class)) + val = new StringValue ((String) value); + else + val = new ObjectValue(value); + } + + return val; + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/value/VoidValue.java b/libjava/classpath/gnu/classpath/jdwp/value/VoidValue.java new file mode 100644 index 000000000..ae117347d --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/value/VoidValue.java @@ -0,0 +1,82 @@ +/* VoidValue.java -- JDWP wrapper class for a void value + Copyright (C) 2007 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath.jdwp.value; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Wrapper for an void value. + * + * @author Kyle Galloway <kgallowa@redhat.com> + */ +public class VoidValue + extends Value +{ + /** + * Create a new VoidValue. + */ + public VoidValue () + { + super(JdwpConstants.Tag.VOID); + } + + /** + * Return an object representing this type + * + * @return an Object represntation of this value + */ + @Override + protected Object getObject() + { + return null; + } + + /** + * Write the wrapped void to the given DataOutputStream. + * + * @param os the output stream to write to + */ + @Override + protected void write(DataOutputStream os) + throws IOException + { + } +} |