001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anton V. Karnachuk
021: * @version $Revision: 1.3 $
022: */
023:
024: /**
025: * Created on 16.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.StackFrame;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.Location;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033:
034: public class JDWPStackFrameTestCase extends JDWPSyncTestCase {
035:
036: public class FrameInfo {
037: long frameID;
038: Location location;
039:
040: public FrameInfo(long frameID, Location location) {
041: super ();
042: this .frameID = frameID;
043: this .location = location;
044: }
045:
046: /**
047: * @return Returns the frameID.
048: */
049: public long getFrameID() {
050: return frameID;
051: }
052:
053: /**
054: * @return Returns the location.
055: */
056: public Location getLocation() {
057: return location;
058: }
059: }
060:
061: public class VarInfo {
062: int slot;
063: String signature, name;
064:
065: public VarInfo(String name, int slot, String signature) {
066: this .slot = slot;
067: this .signature = signature;
068: this .name = name;
069: }
070:
071: public int getSlot() {
072: return slot;
073: }
074:
075: public String getSignature() {
076: return signature;
077: }
078:
079: public String getName() {
080: return name;
081: }
082:
083: }
084:
085: protected String getDebuggeeClassName() {
086: return StackTraceDebuggee.class.getName();
087: }
088:
089: protected int jdwpGetFrameCount(long threadID) {
090: CommandPacket packet = new CommandPacket(
091: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
092: JDWPCommands.ThreadReferenceCommandSet.FrameCountCommand);
093: packet.setNextValueAsThreadID(threadID);
094:
095: ReplyPacket reply = debuggeeWrapper.vmMirror
096: .performCommand(packet);
097: checkReplyPacket(reply, "ThreadReference::FrameCount command");
098:
099: int frameCount = reply.getNextValueAsInt();
100: return frameCount;
101: }
102:
103: protected FrameInfo[] jdwpGetFrames(long threadID, int startFrame,
104: int length) {
105: CommandPacket packet = new CommandPacket(
106: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
107: JDWPCommands.ThreadReferenceCommandSet.FramesCommand);
108: packet.setNextValueAsThreadID(threadID);
109: packet.setNextValueAsInt(startFrame);
110: packet.setNextValueAsInt(length);
111:
112: ReplyPacket reply = debuggeeWrapper.vmMirror
113: .performCommand(packet);
114: checkReplyPacket(reply,
115: "ThreadReference::FramesCommand command");
116:
117: int frames = reply.getNextValueAsInt();
118: FrameInfo[] frameInfos = new FrameInfo[frames];
119: for (int i = 0; i < frames; i++) {
120: long frameID = reply.getNextValueAsLong();
121: Location location = reply.getNextValueAsLocation();
122: frameInfos[i] = new FrameInfo(frameID, location);
123: }
124: return frameInfos;
125: }
126:
127: protected VarInfo[] jdwpGetVariableTable(long classID, long methodID) {
128: CommandPacket packet = new CommandPacket(
129: JDWPCommands.MethodCommandSet.CommandSetID,
130: JDWPCommands.MethodCommandSet.VariableTableCommand);
131: packet.setNextValueAsClassID(classID);
132: packet.setNextValueAsMethodID(methodID);
133:
134: ReplyPacket reply = debuggeeWrapper.vmMirror
135: .performCommand(packet);
136: checkReplyPacket(reply, "Method::VariableTable command");
137:
138: reply.getNextValueAsInt();
139: int varNumber = reply.getNextValueAsInt();
140:
141: VarInfo[] varInfos = new VarInfo[varNumber];
142: for (int i = 0; i < varNumber; i++) {
143: reply.getNextValueAsLong();
144: String name = reply.getNextValueAsString();
145: String sign = reply.getNextValueAsString();
146: reply.getNextValueAsInt();
147:
148: int slot = reply.getNextValueAsInt();
149: varInfos[i] = new VarInfo(name, slot, sign);
150: }
151: return varInfos;
152: }
153:
154: protected long[] jdwpGetAllThreads() {
155: CommandPacket packet = new CommandPacket(
156: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
157: JDWPCommands.VirtualMachineCommandSet.AllThreadsCommand);
158:
159: ReplyPacket reply = debuggeeWrapper.vmMirror
160: .performCommand(packet);
161: checkReplyPacket(reply, "VirtualMachine::AllThreads command");
162:
163: int frames = reply.getNextValueAsInt();
164:
165: long[] frameIDs = new long[frames];
166: for (int i = 0; i < frames; i++) {
167: frameIDs[i] = reply.getNextValueAsLong();
168: }
169:
170: return frameIDs;
171: }
172:
173: protected String jdwpGetThreadName(long threadID) {
174: CommandPacket packet = new CommandPacket(
175: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
176: JDWPCommands.ThreadReferenceCommandSet.NameCommand);
177: packet.setNextValueAsThreadID(threadID);
178:
179: ReplyPacket reply = debuggeeWrapper.vmMirror
180: .performCommand(packet);
181: checkReplyPacket(reply, "ThreadReference::Name command");
182:
183: String name = reply.getNextValueAsString();
184: return name;
185: }
186:
187: protected void jdwpSuspendThread(long threadID) {
188: CommandPacket packet = new CommandPacket(
189: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
190: JDWPCommands.ThreadReferenceCommandSet.SuspendCommand);
191: packet.setNextValueAsThreadID(threadID);
192:
193: ReplyPacket reply = debuggeeWrapper.vmMirror
194: .performCommand(packet);
195: checkReplyPacket(reply, "ThreadReference::Suspend command");
196: }
197:
198: protected void jdwpResumeThread(long threadID) {
199: CommandPacket packet = new CommandPacket(
200: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
201: JDWPCommands.ThreadReferenceCommandSet.ResumeCommand);
202: packet.setNextValueAsThreadID(threadID);
203:
204: ReplyPacket reply = debuggeeWrapper.vmMirror
205: .performCommand(packet);
206: checkReplyPacket(reply, "ThreadReference::Resume command");
207: }
208:
209: protected void jdwpPopFrames(long threadID, long frameID) {
210: CommandPacket popFramesCommand = new CommandPacket(
211: JDWPCommands.StackFrameCommandSet.CommandSetID,
212: JDWPCommands.StackFrameCommandSet.PopFramesCommand);
213: popFramesCommand.setNextValueAsThreadID(threadID);
214: popFramesCommand.setNextValueAsFrameID(frameID);
215:
216: ReplyPacket reply = debuggeeWrapper.vmMirror
217: .performCommand(popFramesCommand);
218: checkReplyPacket(reply, "StackFrame::PopFramesCommand command");
219: }
220:
221: }
|