Frames | No Frames |
1: /* StackFrameCommandSet.java -- class to implement the StackFrame Command Set 2: Copyright (C) 2005 Free Software Foundation 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 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.VMFrame; 44: import gnu.classpath.jdwp.VMVirtualMachine; 45: import gnu.classpath.jdwp.exception.JdwpException; 46: import gnu.classpath.jdwp.exception.JdwpInternalErrorException; 47: import gnu.classpath.jdwp.exception.NotImplementedException; 48: import gnu.classpath.jdwp.id.ObjectId; 49: import gnu.classpath.jdwp.util.Value; 50: 51: import java.io.DataOutputStream; 52: import java.io.IOException; 53: import java.nio.ByteBuffer; 54: 55: /** 56: * A class representing the StackFrame Command Set. 57: * 58: * @author Aaron Luchko <aluchko@redhat.com> 59: */ 60: public class StackFrameCommandSet 61: extends CommandSet 62: { 63: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) 64: throws JdwpException 65: { 66: boolean keepRunning = true; 67: try 68: { 69: switch (command) 70: { 71: case JdwpConstants.CommandSet.StackFrame.GET_VALUES: 72: executeGetValues(bb, os); 73: break; 74: case JdwpConstants.CommandSet.StackFrame.SET_VALUES: 75: executeSetValues(bb, os); 76: break; 77: case JdwpConstants.CommandSet.StackFrame.THIS_OBJECT: 78: executeThisObject(bb, os); 79: break; 80: case JdwpConstants.CommandSet.StackFrame.POP_FRAMES: 81: executePopFrames(bb, os); 82: break; 83: default: 84: throw new NotImplementedException("Command " + command + 85: " not found in Stack Frame Command Set."); 86: } 87: } 88: catch (IOException ex) 89: { 90: // The DataOutputStream we're using isn't talking to a socket at all 91: // So if we throw an IOException we're in serious trouble 92: throw new JdwpInternalErrorException(ex); 93: } 94: 95: return false; 96: } 97: 98: private void executeGetValues(ByteBuffer bb, DataOutputStream os) 99: throws JdwpException, IOException 100: { 101: ObjectId tId = idMan.readObjectId(bb); 102: Thread thread = (Thread) tId.getObject(); 103: 104: // Although Frames look like other ids they are not. First they are not 105: // ObjectIds since they don't exist in the users code. Storing them as an 106: // ObjectId would mean they could be garbage collected since no one else 107: // has a reference to them. Furthermore they are not ReferenceTypeIds since 108: // these are held permanently and we want these to be held only as long as 109: // the Thread is suspended. 110: VMFrame frame = VMVirtualMachine.getFrame(thread, bb); 111: int slots = bb.getInt(); 112: os.writeInt(slots); // Looks pointless but this is the protocol 113: for (int i = 0; i < slots; i++) 114: { 115: int slot = bb.getInt(); 116: byte sig = bb.get(); 117: Object val = frame.getValue(slot); 118: Value.writeTaggedValue(os, val); 119: } 120: } 121: 122: private void executeSetValues(ByteBuffer bb, DataOutputStream os) 123: throws JdwpException, IOException 124: { 125: ObjectId tId = idMan.readObjectId(bb); 126: Thread thread = (Thread) tId.getObject(); 127: 128: VMFrame frame = VMVirtualMachine.getFrame(thread, bb); 129: 130: int slots = bb.getInt(); 131: for (int i = 0; i < slots; i++) 132: { 133: int slot = bb.getInt(); 134: Object value = Value.getObj(bb); 135: frame.setValue(slot, value); 136: } 137: } 138: 139: private void executeThisObject(ByteBuffer bb, DataOutputStream os) 140: throws JdwpException, IOException 141: { 142: ObjectId tId = idMan.readObjectId(bb); 143: Thread thread = (Thread) tId.getObject(); 144: 145: VMFrame frame = VMVirtualMachine.getFrame(thread, bb); 146: 147: Object thisObject = frame.getObject(); 148: Value.writeTaggedValue(os, thisObject); 149: } 150: 151: private void executePopFrames(ByteBuffer bb, DataOutputStream os) 152: throws JdwpException 153: { 154: // This command is optional, determined by VirtualMachines CapabilitiesNew 155: // so we'll leave it till later to implement 156: throw new NotImplementedException("Command PopFrames not implemented."); 157: } 158: }