1:
38:
39:
40: package ;
41:
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66:
67: import ;
68: import ;
69: import ;
70:
71:
76: public class EventRequestCommandSet
77: extends CommandSet
78: {
79: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
80: throws JdwpException
81: {
82: try
83: {
84: switch (command)
85: {
86: case JdwpConstants.CommandSet.EventRequest.SET:
87: executeSet(bb, os);
88: break;
89: case JdwpConstants.CommandSet.EventRequest.CLEAR:
90: executeClear(bb, os);
91: break;
92: case JdwpConstants.CommandSet.EventRequest.CLEAR_ALL_BREAKPOINTS:
93: executeClearAllBreakpoints(bb, os);
94: break;
95: default:
96: throw new NotImplementedException("Command " + command +
97: " not found in EventRequest Reference Command Set.");
98: }
99: }
100: catch (IOException ex)
101: {
102:
103:
104: throw new JdwpInternalErrorException(ex);
105: }
106:
107: return false;
108: }
109:
110: private void executeSet(ByteBuffer bb, DataOutputStream os)
111: throws JdwpException, IOException
112: {
113: byte eventKind = bb.get();
114: byte suspendPolicy = bb.get();
115: int modifiers = bb.getInt();
116:
117: switch (eventKind)
118: {
119: case JdwpConstants.EventKind.FIELD_ACCESS:
120: if (!VMVirtualMachine.canWatchFieldAccess)
121: {
122: String msg = "watching field accesses is not supported";
123: throw new NotImplementedException(msg);
124: }
125: break;
126:
127: case JdwpConstants.EventKind.FIELD_MODIFICATION:
128: if (!VMVirtualMachine.canWatchFieldModification)
129: {
130: String msg = "watching field modifications is not supported";
131: throw new NotImplementedException(msg);
132: }
133: break;
134:
135: default:
136:
137: }
138:
139: EventRequest eventReq = new EventRequest(eventKind, suspendPolicy);
140: IEventFilter filter = null;
141: ReferenceTypeId refId;
142: for (int i = 0; i < modifiers; i++)
143: {
144: byte modKind = bb.get();
145: switch (modKind)
146: {
147: case JdwpConstants.ModKind.COUNT:
148: filter = new CountFilter(bb.getInt());
149: break;
150: case JdwpConstants.ModKind.CONDITIONAL:
151: filter = new ConditionalFilter(idMan.readObjectId(bb));
152: break;
153: case JdwpConstants.ModKind.THREAD_ONLY:
154: filter = new ThreadOnlyFilter((ThreadId) idMan.readObjectId(bb));
155: break;
156: case JdwpConstants.ModKind.CLASS_ONLY:
157: filter = new ClassOnlyFilter(idMan.readReferenceTypeId(bb));
158: break;
159: case JdwpConstants.ModKind.CLASS_MATCH:
160: filter = new ClassMatchFilter(JdwpString.readString(bb));
161: break;
162: case JdwpConstants.ModKind.CLASS_EXCLUDE:
163: filter = new ClassExcludeFilter(JdwpString.readString(bb));
164: break;
165: case JdwpConstants.ModKind.LOCATION_ONLY:
166: filter = new LocationOnlyFilter(new Location(bb));
167: break;
168: case JdwpConstants.ModKind.EXCEPTION_ONLY:
169: long id = bb.getLong();
170: if (id == 0)
171: refId = null;
172: else
173: refId = idMan.getReferenceType(id);
174: boolean caught = (bb.get() == 0) ? false : true;
175: boolean unCaught = (bb.get() == 0) ? false : true;
176: filter = new ExceptionOnlyFilter(refId, caught, unCaught);
177: break;
178: case JdwpConstants.ModKind.FIELD_ONLY:
179: refId = idMan.readReferenceTypeId(bb);
180: ReferenceTypeId fieldId = idMan.readReferenceTypeId(bb);
181: filter = new FieldOnlyFilter(refId, fieldId);
182: break;
183: case JdwpConstants.ModKind.STEP:
184: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
185: int size = bb.getInt();
186: int depth = bb.getInt();
187: filter = new StepFilter(tid, size, depth);
188: break;
189: case JdwpConstants.ModKind.INSTANCE_ONLY:
190: ObjectId oid = idMan.readObjectId(bb);
191: filter = new InstanceOnlyFilter(oid);
192: break;
193: default:
194: throw new NotImplementedException("modKind " + modKind
195: + " is not implemented.");
196: }
197: eventReq.addFilter(filter);
198: }
199:
200: EventManager.getDefault().requestEvent(eventReq);
201: os.writeInt(eventReq.getId());
202:
203: }
204:
205: private void executeClear(ByteBuffer bb, DataOutputStream os)
206: throws JdwpException, IOException
207: {
208: byte eventKind = bb.get();
209: int requestId = bb.getInt();
210: EventManager.getDefault().deleteRequest(eventKind, requestId);
211: }
212:
213: private void executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os)
214: throws JdwpException, IOException
215: {
216: byte eventKind = bb.get ();
217: EventManager.getDefault().clearRequests (eventKind);
218: }
219:
220: }