1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Anton V. Karnachuk 21 */ 22 23 /** 24 * Created on 16.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.StackFrame; 27 28 import java.util.List; 29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 30 import org.apache.harmony.jpda.tests.framework.jdwp.Frame; 31 import org.apache.harmony.jpda.tests.framework.jdwp.Frame.Variable; 32 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 33 import org.apache.harmony.jpda.tests.framework.jdwp.Location; 34 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 35 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 36 37 38 public class JDWPStackFrameTestCase extends JDWPSyncTestCase { 39 40 public class FrameInfo { 41 long frameID; 42 Location location; 43 FrameInfo(long frameID, Location location)44 public FrameInfo(long frameID, Location location) { 45 super(); 46 this.frameID = frameID; 47 this.location = location; 48 } 49 50 /** 51 * @return Returns the frameID. 52 */ getFrameID()53 public long getFrameID() { 54 return frameID; 55 } 56 /** 57 * @return Returns the location. 58 */ getLocation()59 public Location getLocation() { 60 return location; 61 } 62 } 63 64 @Override getDebuggeeClassName()65 protected String getDebuggeeClassName() { 66 return StackTraceDebuggee.class.getName(); 67 } 68 jdwpGetFrameCount(long threadID)69 protected int jdwpGetFrameCount(long threadID) { 70 CommandPacket packet = new CommandPacket( 71 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 72 JDWPCommands.ThreadReferenceCommandSet.FrameCountCommand); 73 packet.setNextValueAsThreadID(threadID); 74 75 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 76 checkReplyPacket(reply, "ThreadReference::FrameCount command"); 77 78 int frameCount = reply.getNextValueAsInt(); 79 return frameCount; 80 } 81 jdwpGetFrames(long threadID, int startFrame, int length)82 protected FrameInfo[] jdwpGetFrames(long threadID, int startFrame, int length) { 83 CommandPacket packet = new CommandPacket( 84 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 85 JDWPCommands.ThreadReferenceCommandSet.FramesCommand); 86 packet.setNextValueAsThreadID(threadID); 87 packet.setNextValueAsInt(startFrame); 88 packet.setNextValueAsInt(length); 89 90 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 91 checkReplyPacket(reply, "ThreadReference::FramesCommand command"); 92 93 int frames = reply.getNextValueAsInt(); 94 FrameInfo[] frameInfos = new FrameInfo[frames]; 95 for (int i = 0; i < frames; i++) { 96 long frameID = reply.getNextValueAsLong(); 97 Location location = reply.getNextValueAsLocation(); 98 frameInfos[i] = new FrameInfo(frameID, location); 99 } 100 return frameInfos; 101 } 102 jdwpGetVariableTable(long classID, long methodID)103 protected Frame.Variable[] jdwpGetVariableTable(long classID, long methodID) { 104 List<Variable> variables = debuggeeWrapper.vmMirror.getVariableTable(classID, methodID); 105 if (variables == null) { 106 // We failed to collect variable table 107 fail("No variable table"); 108 } 109 Frame.Variable[] varInfos = new Frame.Variable[variables.size()]; 110 varInfos = variables.toArray(varInfos); 111 return varInfos; 112 } 113 jdwpGetAllThreads()114 protected long[] jdwpGetAllThreads() { 115 CommandPacket packet = new CommandPacket( 116 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 117 JDWPCommands.VirtualMachineCommandSet.AllThreadsCommand); 118 119 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 120 checkReplyPacket(reply, "VirtualMachine::AllThreads command"); 121 122 int frames = reply.getNextValueAsInt(); 123 124 long[] frameIDs = new long[frames]; 125 for (int i = 0; i < frames; i++) { 126 frameIDs[i] = reply.getNextValueAsLong(); 127 } 128 129 return frameIDs; 130 } 131 jdwpGetThreadName(long threadID)132 protected String jdwpGetThreadName(long threadID) { 133 CommandPacket packet = new CommandPacket( 134 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 135 JDWPCommands.ThreadReferenceCommandSet.NameCommand); 136 packet.setNextValueAsThreadID(threadID); 137 138 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 139 checkReplyPacket(reply, "ThreadReference::Name command"); 140 141 String name= reply.getNextValueAsString(); 142 return name; 143 } 144 jdwpSuspendThread(long threadID)145 protected void jdwpSuspendThread(long threadID) { 146 CommandPacket packet = new CommandPacket( 147 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 148 JDWPCommands.ThreadReferenceCommandSet.SuspendCommand); 149 packet.setNextValueAsThreadID(threadID); 150 151 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 152 checkReplyPacket(reply, "ThreadReference::Suspend command"); 153 } 154 jdwpResumeThread(long threadID)155 protected void jdwpResumeThread(long threadID) { 156 CommandPacket packet = new CommandPacket( 157 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 158 JDWPCommands.ThreadReferenceCommandSet.ResumeCommand); 159 packet.setNextValueAsThreadID(threadID); 160 161 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 162 checkReplyPacket(reply, "ThreadReference::Resume command"); 163 } 164 jdwpPopFrames(long threadID, long frameID)165 protected void jdwpPopFrames(long threadID, long frameID) { 166 CommandPacket popFramesCommand = new CommandPacket( 167 JDWPCommands.StackFrameCommandSet.CommandSetID, 168 JDWPCommands.StackFrameCommandSet.PopFramesCommand); 169 popFramesCommand.setNextValueAsThreadID(threadID); 170 popFramesCommand.setNextValueAsFrameID(frameID); 171 172 ReplyPacket reply = debuggeeWrapper.vmMirror 173 .performCommand(popFramesCommand); 174 checkReplyPacket(reply, "StackFrame::PopFramesCommand command"); 175 } 176 177 } 178