Java Code Examples for org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket

Following code examples demonstrate how to use org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacketfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacketand various code implementation of this class.

    public void testName001() {
        logWriter.println("wait for SGNL_READY");
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        CommandPacket packet;
        long threadID = debuggeeWrapper.vmMirror.getThreadID(NameDebuggee.TESTED_THREAD);

        long groupID;
        String groupName;

        packet = new CommandPacket(
                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
                JDWPCommands.ThreadReferenceCommandSet.ThreadGroupCommand);
        packet.setNextValueAsThreadID(threadID);

        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "ThreadReference::ThreadGroup command");

        groupID = reply.getNextValueAsThreadGroupID();
        groupName = debuggeeWrapper.vmMirror.getThreadGroupName(groupID);

        logWriter.println("\tthreadID=" + threadID
                    + "; threadName=" + NameDebuggee.TESTED_THREAD
                    + "; groupID=" + groupID
                    + "; groupName=" + groupName);

        assertString("ThreadReference::ThreadGroup command returned invalid group name,",
                NameDebuggee.CHILD_GROUP, groupName);

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 


    public Result testLA02() {
        ReplyPacket reply = debuggeeWrapper.vmMirror.setClassPrepared(DEBUGGEE_CLASS_NAME);
        debuggeeWrapper.vmMirror.resume();
        EventPacket event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.CLASS_PREPARE);        
        
        logWriter.println("Resume debuggee VM");
        debuggeeWrapper.resume();

        return passed();
    } 

    public void testMethodEntry() {
        logWriter.println("testMethodEntry started");

        String methodEntryClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.MethodEntryDebuggee"; 

        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        ReplyPacket reply = debuggeeWrapper.vmMirror.setMethodEntry(methodEntryClassNameRegexp);
        checkReplyPacket(reply, "Set METHOD_ENTRY event");

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

        CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);

        assertEquals("Invalid number of events,", 1, parsedEvents.length);
        assertEquals("Invalid event kind,",
                JDWPConstants.EventKind.METHOD_ENTRY,
                parsedEvents[0].getEventKind(),
                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.METHOD_ENTRY),
                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));

        logWriter.println("MethodEntryTest done");
    } 

    public void testMethodExit() {
        logWriter.println("testMethodExit started");

        String methodExitClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.MethodEntryDebuggee"; 

        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        ReplyPacket reply = debuggeeWrapper.vmMirror.setMethodExit(methodExitClassNameRegexp);
        checkReplyPacket(reply, "Set METHOD_EXIT event");

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
        
        CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);

        assertEquals("Invalid number of events,", 1, parsedEvents.length);
        assertEquals("Invalid event kind,",
                JDWPConstants.EventKind.METHOD_EXIT,
                parsedEvents[0].getEventKind(),
                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.METHOD_EXIT),
                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));

        logWriter.println("MethodExitTest done");
    } 

    public void testLineTableTest001() throws UnsupportedEncodingException {
        logWriter.println("testLineTableTest001 started");
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        long classID = getClassIDBySignature("L"+getDebuggeeClassName().replace('.', '/')+";");

        MethodInfo[] methodsInfo = jdwpGetMethodsInfo(classID);
        assertFalse("Invalid number of methods: 0", methodsInfo.length == 0);

        for (int i = 0; i < methodsInfo.length; i++) {
            logWriter.println(methodsInfo[i].toString());

            ReplyPacket reply = getLineTable(classID, methodsInfo[i].getMethodID());

            long start = reply.getNextValueAsLong();
            logWriter.println("start = " + start);
            long end = reply.getNextValueAsLong();
            logWriter.println("end = " + end);

            int lines = reply.getNextValueAsInt();
            logWriter.println("lines = "+lines);

            for (int j = 0; j < lines; j++) {
                long lineCodeIndex = reply.getNextValueAsLong();
                logWriter.println("lineCodeIndex = "+lineCodeIndex);
                int lineNumber = reply.getNextValueAsInt();
                logWriter.println("lineNumber = "+lineNumber);
            }
        }

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 

    public void testThisObject() {
        logWriter.println("testThisObject started");

        EventContext context = stopInProxyMethod();

        Value proxyObjectValue = getExpectedProxyObjectValue();

        logWriter.println("==> Send StackFrame::ThisObject command...");
        CommandPacket packet = new CommandPacket(
                JDWPCommands.StackFrameCommandSet.CommandSetID,
                JDWPCommands.StackFrameCommandSet.ThisObjectCommand);
        packet.setNextValueAsThreadID(context.getThreadId());
        packet.setNextValueAsLong(context.getFrameId());
        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "StackFrame.ThisObject");
        TaggedObject taggedObject = reply.getNextValueAsTaggedObject();
        assertAllDataRead(reply);

        assertEquals("Unexpected object id", proxyObjectValue.getLongValue(),
                taggedObject.objectID);
        assertEquals("Unexpected object tag", proxyObjectValue.getTag(),
                taggedObject.tag);

        resumeDebuggee();

        logWriter.println("testThisObject finished");
    } 

    public void testVersion001() {

        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        CommandPacket packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.VersionCommand);

        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);

        String description = reply.getNextValueAsString();
        int    jdwpMajor   = reply.getNextValueAsInt();
        int    jdwpMinor   = reply.getNextValueAsInt();
        String vmVersion   = reply.getNextValueAsString();
        String vmName      = reply.getNextValueAsString();

        logWriter.println("description\t= " + description);
        logWriter.println("jdwpMajor\t= " + jdwpMajor);
        logWriter.println("jdwpMinor\t= " + jdwpMinor);
        logWriter.println("vmVersion\t= " + vmVersion);
        logWriter.println("vmName\t\t= " + vmName);

        if (!(description.length() > 0)) {
            printErrorAndFail("description.length = 0");
        }

        if (!(vmVersion.length() > 0)) {
            printErrorAndFail("vmVersion.length = 0");
        }

        if (!(vmName.length() > 0)) {
            printErrorAndFail("vmName.length = 0");
        }

        logWriter.println("CHECK PASSED");

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 

    public void testIsObsoleteTest001() throws UnsupportedEncodingException {
        logWriter.println("testObsoleteTest001 started");
        
        logWriter.println("=> Check, can VM redefine classes");
        debuggeeWrapper.vmMirror.capabilities();
        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canRedefineClasses;
        if (!isCapability) {
            logWriter.println("##WARNING: this VM can't redefine classes");
            return;
        }
        
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        long classID = getClassIDBySignature("L"+getDebuggeeClassName().replace('.', '/')+";");

        MethodInfo[] methodsInfo = jdwpGetMethodsInfo(classID);
        assertFalse("Invalid number of methods", methodsInfo.length == 0);

        for (int i = 0; i < methodsInfo.length; i++) {
            logWriter.println(methodsInfo[i].toString());

            CommandPacket packet = new CommandPacket(
                    JDWPCommands.MethodCommandSet.CommandSetID,
                    JDWPCommands.MethodCommandSet.IsObsoleteCommand);
            packet.setNextValueAsClassID(classID);
            packet.setNextValueAsMethodID(methodsInfo[i].getMethodID());
            ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
            checkReplyPacket(reply, "Method::IsObsolete command");

            boolean isObsolete = reply.getNextValueAsBoolean();
            logWriter.println("isObsolete=" + isObsolete);
        }

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 

    public void testBytecodesTest001() throws UnsupportedEncodingException {
        logWriter.println("testBytecodesTest001 started");
        
        logWriter.println("=> Check capability: canGetBytecodes");
        debuggeeWrapper.vmMirror.capabilities();
        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetBytecodes;
        if (!isCapability) {
            logWriter.println("##WARNING: this VM doesn't possess capability: canGetBytecodes");
            return;
        }
        
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        long classID = getClassIDBySignature("L"+getDebuggeeClassName().replace('.', '/')+";");

        MethodInfo[] methodsInfo = jdwpGetMethodsInfo(classID);
        assertFalse("Invalid number of methods", methodsInfo.length == 0);

        for (int i = 0; i < methodsInfo.length; i++) {
            logWriter.println(methodsInfo[i].toString());
           
            CommandPacket packet = new CommandPacket(
                    JDWPCommands.MethodCommandSet.CommandSetID,
                    JDWPCommands.MethodCommandSet.BytecodesCommand);
            packet.setNextValueAsClassID(classID);
            packet.setNextValueAsMethodID(methodsInfo[i].getMethodID());
            ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
            checkReplyPacket(reply, "Method::Bytecodes command");

            int bytes = reply.getNextValueAsInt();
            logWriter.println("bytes = " + bytes);
            
            byte[] bytecode = new byte[bytes];
            for (int j = 0; j < bytes; j++) {
                bytecode[j] = reply.getNextValueAsByte();
            }

            logWriter.println("Bytecode=" + new String(bytecode));
        }

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 

    public void testCreateString001() {
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        CommandPacket packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.CreateStringCommand);
        packet.setNextValueAsString(CHECKED_STRING);
        logWriter.println("\tcreate string: " + CHECKED_STRING);

        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "VirtualMachine::CreateString command");

        long stringID = reply.getNextValueAsStringID();

        packet = new CommandPacket(
                JDWPCommands.StringReferenceCommandSet.CommandSetID,
                JDWPCommands.StringReferenceCommandSet.ValueCommand);
        packet.setNextValueAsObjectID(stringID);
        logWriter.println("\trequest string value");

        reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "StringReference::Value command");

        String value = reply.getNextValueAsString();
        logWriter.println("\tgot string value: " + value);

        assertString("StringReference::Value command returned invalid string value,", CHECKED_STRING, value);

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    } 

    protected void checkInvokeReply(ReplyPacket reply) {
        Value invokeResult = reply.getNextValueAsValue();
        assertNull("Expect null result value for 'void'", invokeResult);

        TaggedObject invokeException = reply.getNextValueAsTaggedObject();
        assertEquals("Invalid exception object id", 0, invokeException.objectID);
        assertAllDataRead(reply);

    } 

    public void testSetBreakpointEvent() {
        logWriter.println("testSetBreakpointEvent started");
        
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        Breakpoint breakpoint = new Breakpoint("Lorg/apache/harmony/jpda/tests/jdwp/Events/BreakpointDebuggee;", "breakpointTest", 1);
        ReplyPacket reply;
        reply = debuggeeWrapper.vmMirror.setBreakpoint(JDWPConstants.TypeTag.CLASS, breakpoint);
        checkReplyPacket(reply, "Set BREAKPOINT event");

        logWriter.println("starting thread");

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

        CommandPacket event = null;
        event = debuggeeWrapper.vmMirror.receiveEvent();
        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);

        assertEquals("Invalid number of events,", 1, parsedEvents.length);
        assertEquals("Invalid event kind,",
                JDWPConstants.EventKind.BREAKPOINT,
                parsedEvents[0].getEventKind(),
                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.BREAKPOINT),
                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));
        
        logWriter.println("BreakpointTest done");
    } 

    public void testIDSizes001() {

        CommandPacket packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.IDSizesCommand);

        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "VirtualMachine::IDSizes command");

        int fieldIDSize = reply.getNextValueAsInt();
        int methodIDSize = reply.getNextValueAsInt();
        int objectIDSize = reply.getNextValueAsInt();
        int referenceTypeIDSize = reply.getNextValueAsInt();
        int frameIDSize = reply.getNextValueAsInt();
        logWriter.println("fieldIDSize = " + fieldIDSize);
        logWriter.println("methodIDSize = " + methodIDSize);
        logWriter.println("objectIDSize = " + objectIDSize);
        logWriter.println("referenceTypeIDSize = " + referenceTypeIDSize);
        logWriter.println("frameIDSize = " + frameIDSize);

        assertTrue("Invalid fieldIDSize: " + fieldIDSize, fieldIDSize > 0);
        assertTrue("Invalid methodIDSize: " + methodIDSize, methodIDSize > 0);
        assertTrue("Invalid objectIDSize: " + objectIDSize, objectIDSize > 0);
        assertTrue("Invalid referenceTypeIDSize: " + referenceTypeIDSize, referenceTypeIDSize > 0);
        assertTrue("Invalid frameIDSize: " + frameIDSize, frameIDSize > 0);

        debuggeeWrapper.resume();
    } 

    public void testDebugger002() {
        logWriter.println("***> OnthrowLaunchDebugger001 started");
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
                
        logWriter.println("**> Send VirtualMachine::Version command");
        CommandPacket packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.VersionCommand);
        
        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        logWriter.println("**> Check reply on Version command");
        if (!checkReplyPacketWithoutFail(reply, "VirtualMachine::Version command")) {
            testSynchronizer.sendMessage("FAIL");
            fail("error durign performing VirtualMachine::Version command");
        }
        testSynchronizer.sendMessage("OK");
        
        logWriter.println("**> Send SIGNAL_CONTINUE");
        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
        testSynchronizer.sendMessage("END");
        logWriter.println("***> OnthrowLaunchDebugger001 finished");
    } 

    protected void checkInvokeReply(ReplyPacket reply) {
        TaggedObject invokeNewObject = reply.getNextValueAsTaggedObject();
        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeNewObject.tag);
        assertFalse("Invalid exception object id", invokeNewObject.objectID == 0);

        TaggedObject invokeException = reply.getNextValueAsTaggedObject();
        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeException.tag);
        assertEquals("Invalid exception object id", 0, invokeException.objectID);

        assertAllDataRead(reply);

    } 

    public void testClassPrepareEvent() {
        logWriter.println("testClassPrepareEvent started");

        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        String class2prepareRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.Class2Prepare"; 
        String class2prepareSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/Class2Prepare;"; 
        
        ReplyPacket reply = debuggeeWrapper.vmMirror.setClassPrepared(class2prepareRegexp);
        checkReplyPacket(reply, "Set CLASS_PREPARE event");
        
        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
        
        CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
        
        assertEquals("Invalid number of events,", 1, parsedEvents.length);
        assertEquals("Invalid event kind,", JDWPConstants.EventKind.CLASS_PREPARE, parsedEvents[0].getEventKind()
                , JDWPConstants.EventKind.getName(JDWPConstants.EventKind.CLASS_PREPARE)
                , JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));
        assertEquals("Invalid signature of prepared class,", class2prepareSignature
                , ((ParsedEvent.Event_CLASS_PREPARE)parsedEvents[0]).getSignature());
        
    } 

Advertisement
Javadoc
This class represents JDWP reply packet.
Advertisement