1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jdwp
.host
;
12 import cc
.squirreljme
.jdwp
.JDWPCommand
;
13 import cc
.squirreljme
.jdwp
.JDWPCommandSetEventRequest
;
14 import cc
.squirreljme
.jdwp
.JDWPErrorType
;
15 import cc
.squirreljme
.jdwp
.JDWPEventKind
;
16 import cc
.squirreljme
.jdwp
.JDWPEventModifierKind
;
17 import cc
.squirreljme
.jdwp
.JDWPException
;
18 import cc
.squirreljme
.jdwp
.JDWPHostController
;
19 import cc
.squirreljme
.jdwp
.JDWPHostEventRequest
;
20 import cc
.squirreljme
.jdwp
.JDWPHostLocation
;
21 import cc
.squirreljme
.jdwp
.JDWPPacket
;
22 import cc
.squirreljme
.jdwp
.JDWPSuspendPolicy
;
23 import cc
.squirreljme
.jdwp
.host
.event
.JDWPHostCallStackStepping
;
24 import cc
.squirreljme
.jdwp
.JDWPClassPatternMatcher
;
25 import cc
.squirreljme
.jdwp
.host
.event
.JDWPHostExceptionOnly
;
26 import cc
.squirreljme
.jdwp
.host
.event
.JDWPHostFieldOnly
;
27 import cc
.squirreljme
.jdwp
.host
.event
.JDWPHostEventFilter
;
28 import cc
.squirreljme
.jdwp
.JDWPStepDepth
;
29 import cc
.squirreljme
.jdwp
.JDWPStepSize
;
32 * Event request command set.
36 public enum JDWPHostCommandSetEventRequest
37 implements JDWPCommandHandler
39 /** Set event requests. */
40 SET(JDWPCommandSetEventRequest
.SET
)
47 public JDWPPacket
execute(JDWPHostController __controller
,
51 // Which kind of event? If not supported, it is not valid
52 JDWPEventKind eventKind
= JDWPEventKind
.of(__packet
.readByte());
53 if (eventKind
== null)
54 return __controller
.reply(__packet
.id(),
55 JDWPErrorType
.INVALID_EVENT_TYPE
);
57 // How does this suspend?
58 JDWPSuspendPolicy suspendPolicy
=
59 JDWPSuspendPolicy
.of(__packet
.readByte());
61 // Is there at least one filter?
62 boolean hasFilter
= false;
64 // Modifier properties
65 int occurrenceLimit
= -1;
68 JDWPClassPatternMatcher includeClass
= null;
69 JDWPClassPatternMatcher excludeClass
= null;
70 JDWPHostFieldOnly fieldOnly
= null;
71 JDWPHostLocation location
= null;
72 Object thisInstance
= null;
73 boolean thisInstanceSet
= false;
74 JDWPHostExceptionOnly exception
= null;
75 JDWPHostCallStackStepping callStackStepping
= null;
78 int numModifiers
= __packet
.readInt();
79 for (int i
= 0; i
< numModifiers
; i
++)
81 // Check if the kind if supported or known about
82 JDWPEventModifierKind modKind
= JDWPEventModifierKind
.of(__packet
.readByte());
84 return __controller
.reply(__packet
.id(),
85 JDWPErrorType
.NOT_IMPLEMENTED
);
87 // If this is not a valid modifier, ignore this
88 if (!eventKind
.isValidModifier(modKind
))
89 throw JDWPErrorType
.ILLEGAL_ARGUMENT
.toss(
90 null, modKind
.ordinal(), null);
92 // Everything except occurrences has a filter!
93 if (modKind
!= JDWPEventModifierKind
.LIMIT_OCCURRENCES
)
96 // Depends on the kind
99 case LIMIT_OCCURRENCES
:
100 occurrenceLimit
= __packet
.readInt();
104 thread
= __controller
.readThread(__packet
);
107 __controller
.getState().items
.put(thread
);
111 type
= __controller
.readType(__packet
, false);
114 __controller
.getState().items
.put(type
);
117 case CLASS_MATCH_PATTERN
:
118 includeClass
= new JDWPClassPatternMatcher(
119 __packet
.readString());
122 case CLASS_EXCLUDE_PATTERN
:
123 excludeClass
= new JDWPClassPatternMatcher(
124 __packet
.readString());
127 // A specific location in a class
129 location
= __controller
.readLocation(__packet
);
133 exception
= new JDWPHostExceptionOnly(
134 __controller
.readType(__packet
, true),
135 __packet
.readBoolean(),
136 __packet
.readBoolean());
141 // Make sure this is a valid field
142 Object atType
= __controller
.readType(__packet
,
144 int fieldDx
= __packet
.readId();
145 if (!__controller
.viewType().isValidField(atType
,
147 JDWPErrorType
.INVALID_FIELD_ID
.toss(atType
,
150 fieldOnly
= new JDWPHostFieldOnly(atType
, fieldDx
);
154 case CALL_STACK_STEPPING
:
155 callStackStepping
= new JDWPHostCallStackStepping(
156 __controller
.readThread(__packet
),
157 JDWPStepSize
.of(__packet
.readInt()),
158 JDWPStepDepth
.of(__packet
.readInt()));
161 case THIS_INSTANCE_ONLY
:
162 thisInstance
= __controller
.readObject(__packet
, true);
163 thisInstanceSet
= true;
166 // Report not-implemented
168 return __controller
.reply(__packet
.id(),
169 JDWPErrorType
.NOT_IMPLEMENTED
);
173 // Initialize the event filter with all the modifier parameters
175 eventFilter
= (hasFilter ?
new JDWPHostEventFilter(thread
,
176 type
, includeClass
, excludeClass
, fieldOnly
, location
,
177 thisInstanceSet
, thisInstance
, exception
,
178 callStackStepping
) : null);
180 // Register the event request
181 JDWPHostEventRequest request
= new JDWPHostEventRequest(
182 __controller
.getCommLink().nextId(), eventKind
, suspendPolicy
,
183 occurrenceLimit
, eventFilter
);
184 __controller
.getEventManager().addEventRequest(request
);
186 // Perform injection for the event so whatever we are using for
187 // the call can trip events
188 __controller
.tripRequest(request
);
190 // Respond with the ID of this event
191 JDWPPacket rv
= __controller
.reply(
192 __packet
.id(), JDWPErrorType
.NO_ERROR
);
193 rv
.writeInt(request
.id
);
200 CLEAR(JDWPCommandSetEventRequest
.CLEAR
)
207 public JDWPPacket
execute(JDWPHostController __controller
,
211 // Which kind of event? If not supported, it is not valid
212 JDWPEventKind eventKind
= JDWPEventKind
.of(__packet
.readByte());
213 if (eventKind
== null)
214 return __controller
.reply(__packet
.id(),
215 JDWPErrorType
.INVALID_EVENT_TYPE
);
217 // Delete the event, if it is known... the kind is ignored since
218 // we always use unique IDs regardless of type
219 __controller
.getEventManager().delete(__packet
.readInt());
221 // Always successful, even if the ID is not valid
226 /** Clear all breakpoints. */
227 CLEAR_ALL_BREAKPOINTS(JDWPCommandSetEventRequest
.CLEAR_ALL_BREAKPOINTS
)
234 public JDWPPacket
execute(JDWPHostController __controller
,
238 __controller
.getEventManager().clear(JDWPEventKind
.BREAKPOINT
);
247 /** The base command. */
248 public final JDWPCommand command
;
250 /** The ID of the packet. */
254 * Returns the ID used.
256 * @param __id The ID used.
259 JDWPHostCommandSetEventRequest(JDWPCommand __id
)
262 this.id
= __id
.debuggerId();
270 public final JDWPCommand
command()
280 public final int debuggerId()