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 14.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.Method; 27 28 import java.util.Arrays; 29 30 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 32 import org.apache.harmony.jpda.tests.framework.jdwp.Method; 33 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37 38 /** 39 * JDWP Unit test for Method.Bytecodes command. 40 */ 41 public class BytecodesTest extends JDWPMethodTestCase { 42 /** 43 * This testcase exercises Method.Bytecodes command. 44 * <BR>It runs MethodDebuggee. Gets methods with ReferenceType.Methods command, 45 * prints it's bytecodes received with Method.Bytecodes command. 46 */ 47 public void testBytecodesTest001() { 48 logWriter.println("testBytecodesTest001 started"); 49 50 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 51 52 long classID = getClassIDBySignature("L"+getDebuggeeClassName().replace('.', '/')+";"); 53 54 Method[] methodsInfo = debuggeeWrapper.vmMirror.getMethods(classID); 55 assertFalse("Invalid number of methods", methodsInfo.length == 0); 56 57 for (int i = 0; i < methodsInfo.length; i++) { 58 logWriter.println(methodsInfo[i].toString()); 59 60 // get variable table for this class 61 CommandPacket packet = new CommandPacket( 62 JDWPCommands.MethodCommandSet.CommandSetID, 63 JDWPCommands.MethodCommandSet.BytecodesCommand); 64 packet.setNextValueAsClassID(classID); 65 packet.setNextValueAsMethodID(methodsInfo[i].getMethodID()); 66 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 67 checkReplyPacket(reply, "Method::Bytecodes command"); 68 69 int bytes = reply.getNextValueAsInt(); 70 logWriter.println("bytes = " + bytes); 71 72 byte[] bytecode = new byte[bytes]; 73 for (int j = 0; j < bytes; j++) { 74 bytecode[j] = reply.getNextValueAsByte(); 75 } 76 77 logWriter.println("Bytecode=" + Arrays.toString(bytecode)); 78 } 79 80 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 81 } 82 } 83