Source for gnu.classpath.jdwp.processor.EventRequestCommandSet

   1: /* EventRequestCommandSet.java -- class to implement the EventRequest Command
   2:    Set
   3:    Copyright (C) 2005 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.event.EventManager;
  44: import gnu.classpath.jdwp.event.EventRequest;
  45: import gnu.classpath.jdwp.event.filters.ClassExcludeFilter;
  46: import gnu.classpath.jdwp.event.filters.ClassMatchFilter;
  47: import gnu.classpath.jdwp.event.filters.ClassOnlyFilter;
  48: import gnu.classpath.jdwp.event.filters.ConditionalFilter;
  49: import gnu.classpath.jdwp.event.filters.CountFilter;
  50: import gnu.classpath.jdwp.event.filters.ExceptionOnlyFilter;
  51: import gnu.classpath.jdwp.event.filters.FieldOnlyFilter;
  52: import gnu.classpath.jdwp.event.filters.IEventFilter;
  53: import gnu.classpath.jdwp.event.filters.InstanceOnlyFilter;
  54: import gnu.classpath.jdwp.event.filters.LocationOnlyFilter;
  55: import gnu.classpath.jdwp.event.filters.StepFilter;
  56: import gnu.classpath.jdwp.event.filters.ThreadOnlyFilter;
  57: import gnu.classpath.jdwp.exception.JdwpException;
  58: import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
  59: import gnu.classpath.jdwp.exception.NotImplementedException;
  60: import gnu.classpath.jdwp.id.ObjectId;
  61: import gnu.classpath.jdwp.id.ReferenceTypeId;
  62: import gnu.classpath.jdwp.id.ThreadId;
  63: import gnu.classpath.jdwp.util.JdwpString;
  64: import gnu.classpath.jdwp.util.Location;
  65: 
  66: import java.io.DataOutputStream;
  67: import java.io.IOException;
  68: import java.nio.ByteBuffer;
  69: 
  70: /**
  71:  * A class representing the EventRequest Command Set.
  72:  * 
  73:  * @author Aaron Luchko <aluchko@redhat.com>
  74:  */
  75: public class EventRequestCommandSet
  76:   extends CommandSet
  77: {
  78:   public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
  79:       throws JdwpException
  80:   {
  81:     try
  82:       {
  83:         switch (command)
  84:           {
  85:           case JdwpConstants.CommandSet.EventRequest.SET:
  86:             executeSet(bb, os);
  87:             break;
  88:           case JdwpConstants.CommandSet.EventRequest.CLEAR:
  89:             executeClear(bb, os);
  90:             break;
  91:           case JdwpConstants.CommandSet.EventRequest.CLEAR_ALL_BREAKPOINTS:
  92:             executeClearAllBreakpoints(bb, os);
  93:             break;
  94:           default:
  95:             throw new NotImplementedException("Command " + command + 
  96:               " not found in EventRequest Reference Command Set.");
  97:           }
  98:       }
  99:     catch (IOException ex)
 100:       {
 101:         // The DataOutputStream we're using isn't talking to a socket at all
 102:         // So if we throw an IOException we're in serious trouble
 103:         throw new JdwpInternalErrorException(ex);
 104:       }
 105: 
 106:     return false;
 107:   }
 108: 
 109:   private void executeSet(ByteBuffer bb, DataOutputStream os)
 110:       throws JdwpException, IOException
 111:   {
 112:     byte eventKind = bb.get();
 113:     byte suspendPolicy = bb.get();
 114:     int modifiers = bb.getInt();
 115: 
 116:     EventRequest eventReq = new EventRequest(eventKind, suspendPolicy);
 117:     IEventFilter filter = null;
 118:     ReferenceTypeId refId;
 119:     for (int i = 0; i < modifiers; i++)
 120:       {
 121:         byte modKind = bb.get();
 122:         switch (modKind)
 123:           {
 124:           case JdwpConstants.ModKind.COUNT:
 125:             filter = new CountFilter(bb.getInt());
 126:             break;
 127:           case JdwpConstants.ModKind.CONDITIONAL:
 128:             filter = new ConditionalFilter(idMan.readObjectId(bb));
 129:             break;
 130:           case JdwpConstants.ModKind.THREAD_ONLY:
 131:             filter = new ThreadOnlyFilter((ThreadId) idMan.readObjectId(bb));
 132:             break;
 133:           case JdwpConstants.ModKind.CLASS_ONLY:
 134:             filter = new ClassOnlyFilter(idMan.readReferenceTypeId(bb));
 135:             break;
 136:           case JdwpConstants.ModKind.CLASS_MATCH:
 137:             filter = new ClassMatchFilter(JdwpString.readString(bb));
 138:             break;
 139:           case JdwpConstants.ModKind.CLASS_EXCLUDE:
 140:             filter = new ClassExcludeFilter(JdwpString.readString(bb));
 141:             break;
 142:           case JdwpConstants.ModKind.LOCATION_ONLY:
 143:             filter = new LocationOnlyFilter(new Location(bb));
 144:             break;
 145:           case JdwpConstants.ModKind.EXCEPTION_ONLY:
 146:             long id = bb.getLong();
 147:             if (id == 0)
 148:               refId = null;
 149:             else
 150:               refId = idMan.getReferenceType(id);
 151:             boolean caught = (bb.get() == 0) ? false : true;
 152:             boolean unCaught = (bb.get() == 0) ? false : true;
 153:             filter = new ExceptionOnlyFilter(refId, caught, unCaught);
 154:             break;
 155:           case JdwpConstants.ModKind.FIELD_ONLY:
 156:             refId = idMan.readReferenceTypeId(bb);
 157:             ReferenceTypeId fieldId = idMan.readReferenceTypeId(bb);
 158:             filter = new FieldOnlyFilter(refId, fieldId);
 159:             break;
 160:           case JdwpConstants.ModKind.STEP:
 161:             ThreadId tid = (ThreadId) idMan.readObjectId(bb);
 162:             int size = bb.getInt();
 163:             int depth = bb.getInt();
 164:             filter = new StepFilter(tid, size, depth);
 165:             break;
 166:           case JdwpConstants.ModKind.INSTANCE_ONLY:
 167:             ObjectId oid = idMan.readObjectId(bb);
 168:             filter = new InstanceOnlyFilter(oid);
 169:             break;
 170:           default:
 171:             throw new NotImplementedException("modKind " + modKind
 172:                                               + " is not implemented.");
 173:           }
 174:         eventReq.addFilter(filter);
 175:       }
 176: 
 177:     EventManager.getDefault().requestEvent(eventReq);
 178:     os.writeInt(eventReq.getId());
 179: 
 180:   }
 181: 
 182:   private void executeClear(ByteBuffer bb, DataOutputStream os)
 183:       throws JdwpException, IOException
 184:   {
 185:     byte eventKind = bb.get();
 186:     int requestId = bb.getInt();
 187:     EventManager.getDefault().deleteRequest(eventKind, requestId);
 188:   }
 189: 
 190:   private void executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os)
 191:       throws JdwpException, IOException
 192:   {
 193:     byte eventKind = bb.get ();
 194:     EventManager.getDefault().clearRequests (eventKind);
 195:   }
 196: 
 197: }