Merge from mainline.
[official-gcc.git] / libjava / classpath / gnu / classpath / jdwp / event / EventRequest.java
blob34637f6a2f9366b9b0c45276a81f133bf63abed2
1 /* EventRequest.java -- an event request from the debugger
2 Copyright (C) 2005, 2006 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 java.util.Collection;
46 import java.util.Iterator;
47 import java.util.LinkedList;
49 /**
50 * A class which represents a request by the debugger for an event
51 * in the VM. <code>EventRequest</code>s usually have event filters
52 * associated with them, which allow the debugger to specify conditions
53 * under which the notification should be sent (specific thread, specific
54 * class, ignore count, etc).
56 * @author Keith Seitz (keiths@redhat.com)
58 public class EventRequest
61 * Event types
64 /**
65 * Single step event
67 public static final byte EVENT_SINGLE_STEP =
68 JdwpConstants.EventKind.SINGLE_STEP;
70 /**
71 * Breakpoint event
73 public static final byte EVENT_BREAKPOINT =
74 JdwpConstants.EventKind.BREAKPOINT;
76 /**
77 * Frame pop event
79 public static final byte EVENT_FRAME_POP =
80 JdwpConstants.EventKind.FRAME_POP;
82 /**
83 * Exception event
85 public static final byte EVENT_EXCEPTION =
86 JdwpConstants.EventKind.EXCEPTION;
88 /**
89 * User-defined event
91 public static final byte EVENT_USER_DEFINED =
92 JdwpConstants.EventKind.USER_DEFINED;
94 /**
95 * Thread start event
97 public static final byte EVENT_THREAD_START =
98 JdwpConstants.EventKind.THREAD_START;
101 * Thread end/death event
103 public static final byte EVENT_THREAD_END =
104 JdwpConstants.EventKind.THREAD_END;
107 * Class prepare event
109 public static final byte EVENT_CLASS_PREPARE =
110 JdwpConstants.EventKind.CLASS_PREPARE;
113 * Class unload event
115 public static final byte EVENT_CLASS_UNLOAD =
116 JdwpConstants.EventKind.CLASS_UNLOAD;
119 * Class load event
121 public static final byte EVENT_CLASS_LOAD =
122 JdwpConstants.EventKind.CLASS_LOAD;
125 * Field access event
127 public static final byte EVENT_FIELD_ACCESS =
128 JdwpConstants.EventKind.FIELD_ACCESS;
131 * Field modify event
133 public static final byte EVENT_FIELD_MODIFY =
134 JdwpConstants.EventKind.FIELD_MODIFICATION;
137 * Method entry event
139 public static final byte EVENT_METHOD_ENTRY =
140 JdwpConstants.EventKind.METHOD_ENTRY;
143 * Method exit event
145 public static final byte EVENT_METHOD_EXIT =
146 JdwpConstants.EventKind.METHOD_EXIT;
149 * Virtual machine initialization/start
151 public static final byte EVENT_VM_INIT =
152 JdwpConstants.EventKind.VM_INIT;
155 * Virutal machine death
157 public static final byte EVENT_VM_DEATH =
158 JdwpConstants.EventKind.VM_DEATH;
162 * Suspend policies
166 * Do not suspend any threads
168 public static final byte SUSPEND_NONE =
169 JdwpConstants.SuspendPolicy.NONE;
172 * Suspend the thread in which the event occurred
174 public static final byte SUSPEND_THREAD =
175 JdwpConstants.SuspendPolicy.EVENT_THREAD;
178 * Suspend all threads
180 public static final byte SUSPEND_ALL =
181 JdwpConstants.SuspendPolicy.ALL;
183 // ID of last EventRequest
184 private static int _last_id = 0;
185 private static Object _idLock = new Object ();
187 // A list of filters
188 private LinkedList _filters;
190 // The ID of this request
191 private int _id;
193 // The suspend policy to enforce when this event occurs
194 private byte _suspendPolicy;
196 // Kind of event requested
197 private byte _kind;
200 * Construct a new <code>EventRequest</code>
202 * @param kind the kind of event requested
203 * @param suspendPolicy how to suspend threads when event occurs
205 public EventRequest (byte kind, byte suspendPolicy)
207 _filters = new LinkedList ();
208 synchronized (_idLock)
210 _id = ++_last_id;
212 _kind = kind;
213 _suspendPolicy = suspendPolicy;
217 * Construct a new <code>EventRequest</code> with the given ID
219 * @param id the id of the request to create
220 * @param kind the kind of event requested
221 * @param suspendPolicy how to suspend threads when event occurs
223 public EventRequest (int id, byte kind, byte suspendPolicy)
225 _filters = new LinkedList ();
226 _kind = kind;
227 _suspendPolicy = suspendPolicy;
231 * Creates a new event filter, adding it to this request
233 * @param filter the filter to add
234 * @throws JdwpIllegalArgumentException if an invalid or illegal filter
235 * is added to the request
237 public void addFilter (IEventFilter filter)
238 throws JdwpIllegalArgumentException
240 // Check validity of filter for this request
241 boolean valid = true;
243 Class clazz = filter.getClass ();
244 if (clazz == ClassExcludeFilter.class)
246 if (_kind == EVENT_THREAD_START
247 || _kind == EVENT_THREAD_END)
248 valid = false;
250 else if (clazz == ClassMatchFilter.class)
252 if (_kind == EVENT_THREAD_START
253 || _kind == EVENT_THREAD_END)
254 valid = false;
256 else if (clazz == ClassOnlyFilter.class)
258 if (_kind == EVENT_CLASS_UNLOAD
259 || _kind == EVENT_THREAD_START
260 || _kind == EVENT_THREAD_END)
261 valid = false;
263 else if (clazz == ConditionalFilter.class)
265 // JDWP 1.4 does not say much about this
267 else if (clazz == CountFilter.class)
269 // may be used with any event
271 else if (clazz == ExceptionOnlyFilter.class)
273 if (_kind != EVENT_EXCEPTION)
274 valid = false;
276 else if (clazz == FieldOnlyFilter.class)
278 if (_kind != EVENT_FIELD_ACCESS
279 && _kind != EVENT_FIELD_MODIFY)
280 valid = false;
282 else if (clazz == InstanceOnlyFilter.class)
284 if (_kind == EVENT_CLASS_PREPARE
285 || _kind == EVENT_CLASS_UNLOAD
286 || _kind == EVENT_THREAD_START
287 || _kind == EVENT_THREAD_END)
288 valid = false;
290 else if (clazz == LocationOnlyFilter.class)
292 if (_kind != EVENT_BREAKPOINT
293 && _kind != EVENT_FIELD_ACCESS
294 && _kind != EVENT_FIELD_MODIFY
295 && _kind != EVENT_SINGLE_STEP
296 && _kind != EVENT_EXCEPTION)
297 valid = false;
299 else if (clazz == StepFilter.class)
301 if (_kind != EVENT_SINGLE_STEP)
302 valid = false;
304 else if (clazz == ThreadOnlyFilter.class)
306 if (_kind == EVENT_CLASS_UNLOAD)
307 valid = false;
310 if (!valid)
312 String msg = ("cannot use " + filter.getClass ().getName ()
313 + " with class unload events");
314 throw new JdwpIllegalArgumentException (msg);
317 // Add filter to list
318 _filters.add (filter);
322 * Returns the filters attached to this request
324 public Collection getFilters ()
326 return _filters;
330 * Returns the suspend policy for this request
332 public byte getSuspendPolicy ()
334 return _suspendPolicy;
338 * Returns the request id of this request
340 public int getId ()
342 return _id;
346 * Sets the id of the request (used for auto-generated events)
348 public void setId (int id)
350 _id = id;
354 * Returns the kind of event for this request
356 public byte getEventKind ()
358 return _kind;
362 * Determines whether the given event matches this request
364 * @param theEvent the event to compare to
366 public boolean matches (Event theEvent)
368 boolean matches = true;
370 // Loop through filters; all must match
371 // Note that we must allow EVERY filter to evaluate. This way
372 // things like CountFilter will work.
373 Iterator iter = _filters.iterator ();
374 while (iter.hasNext ())
376 IEventFilter filter = (IEventFilter) iter.next ();
377 if (!filter.matches (theEvent))
378 matches = false;
381 return matches;