Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / classpath / jdwp / event / EventRequest.java
blobeadad2840b69c41025e9fd4b79f9b23ac127ccf8
1 /* EventRequest.java -- an event request from the debugger
2 Copyright (C) 2005 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package gnu.classpath.jdwp.event;
42 import gnu.classpath.jdwp.JdwpConstants;
43 import gnu.classpath.jdwp.event.filters.*;
44 import gnu.classpath.jdwp.exception.JdwpIllegalArgumentException;
45 import gnu.classpath.jdwp.id.*;
47 import java.util.LinkedList;
48 import java.util.ListIterator;
50 /**
51 * A class which represents a request by the debugger for an event
52 * in the VM. <code>EventRequest</code>s usually have event filters
53 * associated with them, which allow the debugger to specify conditions
54 * under which the notification should be sent (specific thread, specific
55 * class, ignore count, etc).
57 * @author Keith Seitz (keiths@redhat.com)
59 public class EventRequest
62 * Event types
65 /**
66 * Single step event
68 public static final byte EVENT_SINGLE_STEP =
69 JdwpConstants.EventKind.SINGLE_STEP;
71 /**
72 * Breakpoint event
74 public static final byte EVENT_BREAKPOINT =
75 JdwpConstants.EventKind.BREAKPOINT;
77 /**
78 * Frame pop event
80 public static final byte EVENT_FRAME_POP =
81 JdwpConstants.EventKind.FRAME_POP;
83 /**
84 * Exception event
86 public static final byte EVENT_EXCEPTION =
87 JdwpConstants.EventKind.EXCEPTION;
89 /**
90 * User-defined event
92 public static final byte EVENT_USER_DEFINED =
93 JdwpConstants.EventKind.USER_DEFINED;
95 /**
96 * Thread start event
98 public static final byte EVENT_THREAD_START =
99 JdwpConstants.EventKind.THREAD_START;
102 * Thread end/death event
104 public static final byte EVENT_THREAD_END =
105 JdwpConstants.EventKind.THREAD_END;
108 * Class prepare event
110 public static final byte EVENT_CLASS_PREPARE =
111 JdwpConstants.EventKind.CLASS_PREPARE;
114 * Class unload event
116 public static final byte EVENT_CLASS_UNLOAD =
117 JdwpConstants.EventKind.CLASS_UNLOAD;
120 * Class load event
122 public static final byte EVENT_CLASS_LOAD =
123 JdwpConstants.EventKind.CLASS_LOAD;
126 * Field access event
128 public static final byte EVENT_FIELD_ACCESS =
129 JdwpConstants.EventKind.FIELD_ACCESS;
132 * Field modify event
134 public static final byte EVENT_FIELD_MODIFY =
135 JdwpConstants.EventKind.FIELD_MODIFICATION;
138 * Method entry event
140 public static final byte EVENT_METHOD_ENTRY =
141 JdwpConstants.EventKind.METHOD_ENTRY;
144 * Method exit event
146 public static final byte EVENT_METHOD_EXIT =
147 JdwpConstants.EventKind.METHOD_EXIT;
150 * Virtual machine initialization/start
152 public static final byte EVENT_VM_INIT =
153 JdwpConstants.EventKind.VM_INIT;
156 * Virutal machine death
158 public static final byte EVENT_VM_DEATH =
159 JdwpConstants.EventKind.VM_DEATH;
163 * Suspend policies
167 * Do not suspend any threads
169 public static final byte SUSPEND_NONE =
170 JdwpConstants.SuspendPolicy.NONE;
173 * Suspend the thread in which the event occurred
175 public static final byte SUSPEND_THREAD =
176 JdwpConstants.SuspendPolicy.EVENT_THREAD;
179 * Suspend all threads
181 public static final byte SUSPEND_ALL =
182 JdwpConstants.SuspendPolicy.ALL;
184 // ID of last EventRequest
185 private static int _last_id = 0;
186 private static Object _idLock = new Object ();
188 // A list of filters
189 private LinkedList _filters;
191 // The ID of this request
192 private int _id;
194 // The suspend policy to enforce when this event occurs
195 private byte _suspendPolicy;
197 // Kind of event requested
198 private byte _kind;
201 * Construct a new <code>EventRequest</code>
203 * @param kind the kind of event requested
204 * @param suspendPolicy how to suspend threads when event occurs
206 public EventRequest (byte kind, byte suspendPolicy)
208 _filters = new LinkedList ();
209 synchronized (_idLock)
211 _id = ++_last_id;
213 _kind = kind;
214 _suspendPolicy = suspendPolicy;
218 * Construct a new <code>EventRequest</code> with the given ID
220 * @param id the id of the request to create
221 * @param kind the kind of event requested
222 * @param suspendPolicy how to suspend threads when event occurs
224 public EventRequest (int id, byte kind, byte suspendPolicy)
226 _filters = new LinkedList ();
227 _kind = kind;
228 _suspendPolicy = suspendPolicy;
232 * Creates a new event filter, adding it to this request
234 * @param filter the filter to add
235 * @throws JdwpIllegalArgumentException if an invalid or illegal filter
236 * is added to the request
238 public void addFilter (IEventFilter filter)
239 throws JdwpIllegalArgumentException
241 // Check validity of filter for this request
242 boolean valid = true;
244 Class clazz = filter.getClass ();
245 if (clazz == ClassExcludeFilter.class)
247 if (_kind == EVENT_THREAD_START
248 || _kind == EVENT_THREAD_END)
249 valid = false;
251 else if (clazz == ClassMatchFilter.class)
253 if (_kind == EVENT_THREAD_START
254 || _kind == EVENT_THREAD_END)
255 valid = false;
257 else if (clazz == ClassOnlyFilter.class)
259 if (_kind == EVENT_CLASS_UNLOAD
260 || _kind == EVENT_THREAD_START
261 || _kind == EVENT_THREAD_END)
262 valid = false;
264 else if (clazz == ConditionalFilter.class)
266 // JDWP 1.4 does not say much about this
268 else if (clazz == CountFilter.class)
270 // may be used with any event
272 else if (clazz == ExceptionOnlyFilter.class)
274 if (_kind != EVENT_EXCEPTION)
275 valid = false;
277 else if (clazz == FieldOnlyFilter.class)
279 if (_kind != EVENT_FIELD_ACCESS
280 && _kind != EVENT_FIELD_MODIFY)
281 valid = false;
283 else if (clazz == InstanceOnlyFilter.class)
285 if (_kind == EVENT_CLASS_PREPARE
286 || _kind == EVENT_CLASS_UNLOAD
287 || _kind == EVENT_THREAD_START
288 || _kind == EVENT_THREAD_END)
289 valid = false;
291 else if (clazz == LocationOnlyFilter.class)
293 if (_kind != EVENT_BREAKPOINT
294 && _kind != EVENT_FIELD_ACCESS
295 && _kind != EVENT_FIELD_MODIFY
296 && _kind != EVENT_SINGLE_STEP
297 && _kind != EVENT_EXCEPTION)
298 valid = false;
300 else if (clazz == StepFilter.class)
302 if (_kind != EVENT_SINGLE_STEP)
303 valid = false;
305 else if (clazz == ThreadOnlyFilter.class)
307 if (_kind == EVENT_CLASS_UNLOAD)
308 valid = false;
311 if (!valid)
313 String msg = ("cannot use " + filter.getClass ().getName ()
314 + " with class unload events");
315 throw new JdwpIllegalArgumentException (msg);
318 // Add filter to list
319 _filters.add (filter);
323 * Returns the suspend policy for this request
325 public byte getSuspendPolicy ()
327 return _suspendPolicy;
331 * Returns the request id of this request
333 public int getId ()
335 return _id;
339 * Sets the id of the request (used for auto-generated events)
341 public void setId (int id)
343 _id = id;
347 * Returns the kind of event for this request
349 public byte getEventKind ()
351 return _kind;
355 * Determines whether the given event matches this request
357 * @param theEvent the event to compare to
359 public boolean matches (Event theEvent)
361 boolean matches = true;
363 // Loop through filters; all must match
364 // Note that we must allow EVERY filter to evaluate. This way
365 // things like CountFilter will work.
366 ListIterator iter = _filters.listIterator ();
367 while (iter.hasNext ())
369 IEventFilter filter = (IEventFilter) iter.next ();
370 if (!filter.matches (theEvent))
371 matches = false;
374 return matches;