1 /* EventRequestCommandSet.java -- class to implement the EventRequest Command 2 Set 3 Copyright (C) 2005, 2007 Free Software Foundation 4 5 This file is part of GNU Classpath. 6 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) 10 any later version. 11 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. 16 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 20 02110-1301 USA. 21 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 25 combination. 26 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. */ 38 39 40 package gnu.classpath.jdwp.processor; 41 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; 66 67 import java.io.DataOutputStream; 68 import java.io.IOException; 69 import java.nio.ByteBuffer; 70 71 /** 72 * A class representing the EventRequest Command Set. 73 * 74 * @author Aaron Luchko <aluchko@redhat.com> 75 */ 76 public class EventRequestCommandSet 77 extends CommandSet 78 { runCommand(ByteBuffer bb, DataOutputStream os, byte command)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 // 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); 105 } 106 107 return false; 108 } 109 executeSet(ByteBuffer bb, DataOutputStream os)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 // okay 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 executeClear(ByteBuffer bb, DataOutputStream os)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 executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os)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 } 221