1 /* EventRequestCommandSet.java -- class to implement the EventRequest Command
3 Copyright (C) 2005, 2007 Free Software Foundation
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
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.processor;
42 import gnu.classpath.jdwp.JdwpConstants;
43 import gnu.classpath.jdwp.VMVirtualMachine;
44 import gnu.classpath.jdwp.event.EventManager;
45 import gnu.classpath.jdwp.event.EventRequest;
46 import gnu.classpath.jdwp.event.filters.ClassExcludeFilter;
47 import gnu.classpath.jdwp.event.filters.ClassMatchFilter;
48 import gnu.classpath.jdwp.event.filters.ClassOnlyFilter;
49 import gnu.classpath.jdwp.event.filters.ConditionalFilter;
50 import gnu.classpath.jdwp.event.filters.CountFilter;
51 import gnu.classpath.jdwp.event.filters.ExceptionOnlyFilter;
52 import gnu.classpath.jdwp.event.filters.FieldOnlyFilter;
53 import gnu.classpath.jdwp.event.filters.IEventFilter;
54 import gnu.classpath.jdwp.event.filters.InstanceOnlyFilter;
55 import gnu.classpath.jdwp.event.filters.LocationOnlyFilter;
56 import gnu.classpath.jdwp.event.filters.StepFilter;
57 import gnu.classpath.jdwp.event.filters.ThreadOnlyFilter;
58 import gnu.classpath.jdwp.exception.JdwpException;
59 import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
60 import gnu.classpath.jdwp.exception.NotImplementedException;
61 import gnu.classpath.jdwp.id.ObjectId;
62 import gnu.classpath.jdwp.id.ReferenceTypeId;
63 import gnu.classpath.jdwp.id.ThreadId;
64 import gnu.classpath.jdwp.util.JdwpString;
65 import gnu.classpath.jdwp.util.Location;
67 import java.io.DataOutputStream;
68 import java.io.IOException;
69 import java.nio.ByteBuffer;
72 * A class representing the EventRequest Command Set.
74 * @author Aaron Luchko <aluchko@redhat.com>
76 public class EventRequestCommandSet
79 public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
86 case JdwpConstants.CommandSet.EventRequest.SET:
89 case JdwpConstants.CommandSet.EventRequest.CLEAR:
92 case JdwpConstants.CommandSet.EventRequest.CLEAR_ALL_BREAKPOINTS:
93 executeClearAllBreakpoints(bb, os);
96 throw new NotImplementedException("Command " + command +
97 " not found in EventRequest Reference Command Set.");
100 catch (IOException ex)
102 // The DataOutputStream we're using isn't talking to a socket at all
103 // So if we throw an IOException we're in serious trouble
104 throw new JdwpInternalErrorException(ex);
110 private void executeSet(ByteBuffer bb, DataOutputStream os)
111 throws JdwpException, IOException
113 byte eventKind = bb.get();
114 byte suspendPolicy = bb.get();
115 int modifiers = bb.getInt();
119 case JdwpConstants.EventKind.FIELD_ACCESS:
120 if (!VMVirtualMachine.canWatchFieldAccess)
122 String msg = "watching field accesses is not supported";
123 throw new NotImplementedException(msg);
127 case JdwpConstants.EventKind.FIELD_MODIFICATION:
128 if (!VMVirtualMachine.canWatchFieldModification)
130 String msg = "watching field modifications is not supported";
131 throw new NotImplementedException(msg);
139 EventRequest eventReq = new EventRequest(eventKind, suspendPolicy);
140 IEventFilter filter = null;
141 ReferenceTypeId refId;
142 for (int i = 0; i < modifiers; i++)
144 byte modKind = bb.get();
147 case JdwpConstants.ModKind.COUNT:
148 filter = new CountFilter(bb.getInt());
150 case JdwpConstants.ModKind.CONDITIONAL:
151 filter = new ConditionalFilter(idMan.readObjectId(bb));
153 case JdwpConstants.ModKind.THREAD_ONLY:
154 filter = new ThreadOnlyFilter((ThreadId) idMan.readObjectId(bb));
156 case JdwpConstants.ModKind.CLASS_ONLY:
157 filter = new ClassOnlyFilter(idMan.readReferenceTypeId(bb));
159 case JdwpConstants.ModKind.CLASS_MATCH:
160 filter = new ClassMatchFilter(JdwpString.readString(bb));
162 case JdwpConstants.ModKind.CLASS_EXCLUDE:
163 filter = new ClassExcludeFilter(JdwpString.readString(bb));
165 case JdwpConstants.ModKind.LOCATION_ONLY:
166 filter = new LocationOnlyFilter(new Location(bb));
168 case JdwpConstants.ModKind.EXCEPTION_ONLY:
169 long id = bb.getLong();
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);
178 case JdwpConstants.ModKind.FIELD_ONLY:
179 refId = idMan.readReferenceTypeId(bb);
180 ReferenceTypeId fieldId = idMan.readReferenceTypeId(bb);
181 filter = new FieldOnlyFilter(refId, fieldId);
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);
189 case JdwpConstants.ModKind.INSTANCE_ONLY:
190 ObjectId oid = idMan.readObjectId(bb);
191 filter = new InstanceOnlyFilter(oid);
194 throw new NotImplementedException("modKind " + modKind
195 + " is not implemented.");
197 eventReq.addFilter(filter);
200 EventManager.getDefault().requestEvent(eventReq);
201 os.writeInt(eventReq.getId());
205 private void executeClear(ByteBuffer bb, DataOutputStream os)
206 throws JdwpException, IOException
208 byte eventKind = bb.get();
209 int requestId = bb.getInt();
210 EventManager.getDefault().deleteRequest(eventKind, requestId);
213 private void executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os)
214 throws JdwpException, IOException
216 byte eventKind = bb.get ();
217 EventManager.getDefault().clearRequests (eventKind);