/uClinux-dist/lib/classpath/gnu/classpath/jdwp/event/EventRequest.java

https://bitbucket.org/__wp__/mb-linux-msli · Java · 383 lines · 178 code · 44 blank · 161 comment · 77 complexity · 6c86341fc340d1679b9b5b08c3852436 MD5 · raw file

  1. /* EventRequest.java -- an event request from the debugger
  2. Copyright (C) 2005, 2006 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package gnu.classpath.jdwp.event;
  33. import gnu.classpath.jdwp.JdwpConstants;
  34. import gnu.classpath.jdwp.event.filters.*;
  35. import gnu.classpath.jdwp.exception.JdwpIllegalArgumentException;
  36. import java.util.Collection;
  37. import java.util.Iterator;
  38. import java.util.LinkedList;
  39. /**
  40. * A class which represents a request by the debugger for an event
  41. * in the VM. <code>EventRequest</code>s usually have event filters
  42. * associated with them, which allow the debugger to specify conditions
  43. * under which the notification should be sent (specific thread, specific
  44. * class, ignore count, etc).
  45. *
  46. * @author Keith Seitz (keiths@redhat.com)
  47. */
  48. public class EventRequest
  49. {
  50. /*
  51. * Event types
  52. */
  53. /**
  54. * Single step event
  55. */
  56. public static final byte EVENT_SINGLE_STEP =
  57. JdwpConstants.EventKind.SINGLE_STEP;
  58. /**
  59. * Breakpoint event
  60. */
  61. public static final byte EVENT_BREAKPOINT =
  62. JdwpConstants.EventKind.BREAKPOINT;
  63. /**
  64. * Frame pop event
  65. */
  66. public static final byte EVENT_FRAME_POP =
  67. JdwpConstants.EventKind.FRAME_POP;
  68. /**
  69. * Exception event
  70. */
  71. public static final byte EVENT_EXCEPTION =
  72. JdwpConstants.EventKind.EXCEPTION;
  73. /**
  74. * User-defined event
  75. */
  76. public static final byte EVENT_USER_DEFINED =
  77. JdwpConstants.EventKind.USER_DEFINED;
  78. /**
  79. * Thread start event
  80. */
  81. public static final byte EVENT_THREAD_START =
  82. JdwpConstants.EventKind.THREAD_START;
  83. /**
  84. * Thread end/death event
  85. */
  86. public static final byte EVENT_THREAD_END =
  87. JdwpConstants.EventKind.THREAD_END;
  88. /**
  89. * Class prepare event
  90. */
  91. public static final byte EVENT_CLASS_PREPARE =
  92. JdwpConstants.EventKind.CLASS_PREPARE;
  93. /**
  94. * Class unload event
  95. */
  96. public static final byte EVENT_CLASS_UNLOAD =
  97. JdwpConstants.EventKind.CLASS_UNLOAD;
  98. /**
  99. * Class load event
  100. */
  101. public static final byte EVENT_CLASS_LOAD =
  102. JdwpConstants.EventKind.CLASS_LOAD;
  103. /**
  104. * Field access event
  105. */
  106. public static final byte EVENT_FIELD_ACCESS =
  107. JdwpConstants.EventKind.FIELD_ACCESS;
  108. /**
  109. * Field modify event
  110. */
  111. public static final byte EVENT_FIELD_MODIFY =
  112. JdwpConstants.EventKind.FIELD_MODIFICATION;
  113. /**
  114. * Method entry event
  115. */
  116. public static final byte EVENT_METHOD_ENTRY =
  117. JdwpConstants.EventKind.METHOD_ENTRY;
  118. /**
  119. * Method exit event
  120. */
  121. public static final byte EVENT_METHOD_EXIT =
  122. JdwpConstants.EventKind.METHOD_EXIT;
  123. /**
  124. * Virtual machine initialization/start
  125. */
  126. public static final byte EVENT_VM_INIT =
  127. JdwpConstants.EventKind.VM_INIT;
  128. /**
  129. * Virutal machine death
  130. */
  131. public static final byte EVENT_VM_DEATH =
  132. JdwpConstants.EventKind.VM_DEATH;
  133. /*
  134. * Suspend policies
  135. */
  136. /**
  137. * Do not suspend any threads
  138. */
  139. public static final byte SUSPEND_NONE =
  140. JdwpConstants.SuspendPolicy.NONE;
  141. /**
  142. * Suspend the thread in which the event occurred
  143. */
  144. public static final byte SUSPEND_THREAD =
  145. JdwpConstants.SuspendPolicy.EVENT_THREAD;
  146. /**
  147. * Suspend all threads
  148. */
  149. public static final byte SUSPEND_ALL =
  150. JdwpConstants.SuspendPolicy.ALL;
  151. // ID of last EventRequest
  152. private static int _last_id = 0;
  153. private static Object _idLock = new Object ();
  154. // A list of filters
  155. private LinkedList _filters;
  156. // The ID of this request
  157. private int _id;
  158. // The suspend policy to enforce when this event occurs
  159. private byte _suspendPolicy;
  160. // Kind of event requested
  161. private byte _kind;
  162. /**
  163. * Construct a new <code>EventRequest</code>
  164. *
  165. * @param kind the kind of event requested
  166. * @param suspendPolicy how to suspend threads when event occurs
  167. */
  168. public EventRequest (byte kind, byte suspendPolicy)
  169. {
  170. _filters = new LinkedList ();
  171. synchronized (_idLock)
  172. {
  173. _id = ++_last_id;
  174. }
  175. _kind = kind;
  176. _suspendPolicy = suspendPolicy;
  177. }
  178. /**
  179. * Construct a new <code>EventRequest</code> with the given ID
  180. *
  181. * @param id the id of the request to create
  182. * @param kind the kind of event requested
  183. * @param suspendPolicy how to suspend threads when event occurs
  184. */
  185. public EventRequest (int id, byte kind, byte suspendPolicy)
  186. {
  187. _filters = new LinkedList ();
  188. _kind = kind;
  189. _suspendPolicy = suspendPolicy;
  190. }
  191. /**
  192. * Creates a new event filter, adding it to this request
  193. *
  194. * @param filter the filter to add
  195. * @throws JdwpIllegalArgumentException if an invalid or illegal filter
  196. * is added to the request
  197. */
  198. public void addFilter (IEventFilter filter)
  199. throws JdwpIllegalArgumentException
  200. {
  201. // Check validity of filter for this request
  202. boolean valid = true;
  203. Class clazz = filter.getClass ();
  204. if (clazz == ClassExcludeFilter.class)
  205. {
  206. if (_kind == EVENT_THREAD_START
  207. || _kind == EVENT_THREAD_END)
  208. valid = false;
  209. }
  210. else if (clazz == ClassMatchFilter.class)
  211. {
  212. if (_kind == EVENT_THREAD_START
  213. || _kind == EVENT_THREAD_END)
  214. valid = false;
  215. }
  216. else if (clazz == ClassOnlyFilter.class)
  217. {
  218. if (_kind == EVENT_CLASS_UNLOAD
  219. || _kind == EVENT_THREAD_START
  220. || _kind == EVENT_THREAD_END)
  221. valid = false;
  222. }
  223. else if (clazz == ConditionalFilter.class)
  224. {
  225. // JDWP 1.4 does not say much about this
  226. }
  227. else if (clazz == CountFilter.class)
  228. {
  229. // may be used with any event
  230. }
  231. else if (clazz == ExceptionOnlyFilter.class)
  232. {
  233. if (_kind != EVENT_EXCEPTION)
  234. valid = false;
  235. }
  236. else if (clazz == FieldOnlyFilter.class)
  237. {
  238. if (_kind != EVENT_FIELD_ACCESS
  239. && _kind != EVENT_FIELD_MODIFY)
  240. valid = false;
  241. }
  242. else if (clazz == InstanceOnlyFilter.class)
  243. {
  244. if (_kind == EVENT_CLASS_PREPARE
  245. || _kind == EVENT_CLASS_UNLOAD
  246. || _kind == EVENT_THREAD_START
  247. || _kind == EVENT_THREAD_END)
  248. valid = false;
  249. }
  250. else if (clazz == LocationOnlyFilter.class)
  251. {
  252. if (_kind != EVENT_BREAKPOINT
  253. && _kind != EVENT_FIELD_ACCESS
  254. && _kind != EVENT_FIELD_MODIFY
  255. && _kind != EVENT_SINGLE_STEP
  256. && _kind != EVENT_EXCEPTION)
  257. valid = false;
  258. }
  259. else if (clazz == StepFilter.class)
  260. {
  261. if (_kind != EVENT_SINGLE_STEP)
  262. valid = false;
  263. }
  264. else if (clazz == ThreadOnlyFilter.class)
  265. {
  266. if (_kind == EVENT_CLASS_UNLOAD)
  267. valid = false;
  268. }
  269. if (!valid)
  270. {
  271. String msg = ("cannot use " + filter.getClass ().getName ()
  272. + " with class unload events");
  273. throw new JdwpIllegalArgumentException (msg);
  274. }
  275. // Add filter to list
  276. _filters.add (filter);
  277. }
  278. /**
  279. * Returns the filters attached to this request
  280. */
  281. public Collection getFilters ()
  282. {
  283. return _filters;
  284. }
  285. /**
  286. * Returns the suspend policy for this request
  287. */
  288. public byte getSuspendPolicy ()
  289. {
  290. return _suspendPolicy;
  291. }
  292. /**
  293. * Returns the request id of this request
  294. */
  295. public int getId ()
  296. {
  297. return _id;
  298. }
  299. /**
  300. * Sets the id of the request (used for auto-generated events)
  301. */
  302. public void setId (int id)
  303. {
  304. _id = id;
  305. }
  306. /**
  307. * Returns the kind of event for this request
  308. */
  309. public byte getEventKind ()
  310. {
  311. return _kind;
  312. }
  313. /**
  314. * Determines whether the given event matches this request
  315. *
  316. * @param theEvent the event to compare to
  317. */
  318. public boolean matches (Event theEvent)
  319. {
  320. boolean matches = true;
  321. // Loop through filters; all must match
  322. // Note that we must allow EVERY filter to evaluate. This way
  323. // things like CountFilter will work.
  324. Iterator iter = _filters.iterator ();
  325. while (iter.hasNext ())
  326. {
  327. IEventFilter filter = (IEventFilter) iter.next ();
  328. if (!filter.matches (theEvent))
  329. matches = false;
  330. }
  331. return matches;
  332. }
  333. }