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

Following code examples demonstrate how to use org.apache.harmony.jpda.tests.framework.jdwp.EventPacketfrom 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.EventPacketand various code implementation of this class.

    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 testFieldModifyEvent() {

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

        String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/FieldDebuggee;";
        ReplyPacket reply = debuggeeWrapper.vmMirror.setFieldModification(classSignature, JDWPConstants.TypeTag.CLASS, "testIntField");
        checkReplyPacket(reply, "Set FIELD_MODIFICATION event");
        
        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

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

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

        TaggedObject modifiedField =((ParsedEvent.Event_FIELD_MODIFICATION)parsedEvents[0]).getObject();

        long typeID = getObjectReferenceType(modifiedField.objectID);
        String returnedExceptionSignature = getClassSignature(typeID);
        assertString("Invalid class signature,",
                classSignature, returnedExceptionSignature);

        logWriter.println("FieldModificationTest done");
    } 

    public void testFieldAccessEvent() {

        logWriter.println("ExceptionTest started");

        logWriter.println("=> Check capability: canWatchFieldAccess");
        debuggeeWrapper.vmMirror.capabilities();
        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldAccess;
        if (!isCapability) {
            logWriter.println("##WARNING: this VM doesn't possess capability: canWatchFieldAccess");
            return;
        }

        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/FieldDebuggee;";
        ReplyPacket reply = debuggeeWrapper.vmMirror.setFieldAccess(classSignature, JDWPConstants.TypeTag.CLASS, "testIntField");
        checkReplyPacket(reply, "Set FIELD_ACCESS event");

        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

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

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

        long eventThreadID = ((EventThread) parsedEvents[0]).getThreadID();
        checkThreadState(eventThreadID, JDWPConstants.ThreadStatus.RUNNING,
                JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED);

        TaggedObject accessedField =((ParsedEvent.Event_FIELD_ACCESS)parsedEvents[0]).getObject();

        long typeID = getObjectReferenceType(accessedField.objectID);
        String returnedExceptionSignature = getClassSignature(typeID);
        assertString("Invalid class signature,",
                classSignature, returnedExceptionSignature);

        logWriter.println("FieldAccessTest done");
    } 

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

        debuggeeWrapper.vmMirror.setThreadStart();

        logWriter.println("send HoldEvents");
        CommandPacket packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.HoldEventsCommand);

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

        logWriter.println("allow to start thread");
        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

        try {
            EventPacket event = debuggeeWrapper.vmMirror.receiveEvent(settings.getTimeout());
            logWriter.printError("unexpected event received: " + event);
            fail("unexpected event received");
        } catch (TimeoutException e) {
            logWriter.println("no events were received");
        } catch (Exception e) {
            throw new TestErrorException(e);
        }

        logWriter.println("send ReleaseEvents");
        packet = new CommandPacket(
                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
                JDWPCommands.VirtualMachineCommandSet.ReleaseEventsCommand);
        debuggeeWrapper.vmMirror.performCommand(packet);

        EventPacket event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.THREAD_START);
        logWriter.println("expected event received: " + event);
        debuggeeWrapper.vmMirror.resume();
    } 

    public Result testBR01() {
        System.out.println(System.getProperty("java.path"));
        ReplyPacket reply = debuggeeWrapper.vmMirror.setClassPrepared(DEBUGGEE_CLASS_NAME);
        debuggeeWrapper.vmMirror.resume();
        EventPacket event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.CLASS_PREPARE);
        
        String method = "main";
        
        long debuggeeClassId = debuggeeWrapper.vmMirror.getClassID(DEBUGGEE_CLASS_SIG);
        long methodId = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassId, method);
        reply = debuggeeWrapper.vmMirror.getLineTable(debuggeeClassId, methodId);
        long start = reply.getNextValueAsLong();
        
        Breakpoint breakpoint = new Breakpoint(DEBUGGEE_CLASS_SIG, method, (int)start);        
        reply = debuggeeWrapper.vmMirror.setBreakpoint(JDWPConstants.TypeTag.CLASS, breakpoint);
        if (reply.getErrorCode() != JDWPConstants.Error.NONE) {
            return failed("A breakpoint couldn't be set.");
        }

        int breakpointLine = debuggeeWrapper.vmMirror.getLineNumber(debuggeeClassId, methodId, start); 
        logWriter.println("Breakpoint is set in a '" + method + "' method at line " + breakpointLine);
        logWriter.println("Resume debuggee VM");
        debuggeeWrapper.vmMirror.resume();
        event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.BREAKPOINT);

        long threadID = event.getNextValueAsThreadID();
        Location location = event.getNextValueAsLocation();
        String methodStopped = debuggeeWrapper.vmMirror.getMethodName(location.classID, location.methodID);
        int lineStopped = debuggeeWrapper.vmMirror.getLineNumber(debuggeeClassId, location.methodID, location.index); 
        logWriter.println("Stopped at breakpoint in a method '" + methodStopped + "' at line " + lineStopped);
        logWriter.print("Check whether breakpoint was set at the expected location...");
        if (location.methodID != methodId || lineStopped != breakpointLine) {
            return failed("Expected to stop in a method '" + method + "' at line " + breakpointLine + " instead of method '" + methodStopped + "', line " + lineStopped);
        }
        
        logWriter.print("OK");

        showStaticFields = true;
        showConstants = true;
        printStackFrames(threadID, true , false );
        
        logWriter.println("Resume VM");
        debuggeeWrapper.vmMirror.resume();  
        
        return passed();
    } 

    public Result testBR02() {
        ReplyPacket reply = debuggeeWrapper.vmMirror.setClassPrepared(DEBUGGEE_CLASS_NAME);
        debuggeeWrapper.vmMirror.resume();
        EventPacket event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.CLASS_PREPARE);
        
        String method = "run";
        
        long debuggeeClassId = debuggeeWrapper.vmMirror.getClassID(DEBUGGEE_CLASS_SIG);
        long methodId = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassId, method);
        
        Breakpoint breakpoint = new Breakpoint(DEBUGGEE_CLASS_SIG, method, (int)debuggeeWrapper.vmMirror.getLineCodeIndex(debuggeeClassId, methodId, breakpointLine));        
        reply = debuggeeWrapper.vmMirror.setBreakpoint(JDWPConstants.TypeTag.CLASS, breakpoint);
        if (reply.getErrorCode() != JDWPConstants.Error.NONE) {
            return failed("A breakpoint couldn't be set.");
        }

        logWriter.println("Breakpoint is set in a '" + method + "' method at line " + breakpointLine);
        logWriter.println("Resume debuggee VM");
        debuggeeWrapper.vmMirror.resume();
        event = debuggeeWrapper.vmMirror.receiveCertainEvent(JDWPConstants.EventKind.BREAKPOINT);

        long threadID = event.getNextValueAsThreadID();
        Location location = event.getNextValueAsLocation();
        String methodStopped = debuggeeWrapper.vmMirror.getMethodName(location.classID, location.methodID);
        int lineStopped = debuggeeWrapper.vmMirror.getLineNumber(debuggeeClassId, location.methodID, location.index);
        logWriter.println("Stopped at breakpoint in a method '" + methodStopped + "' at line " + lineStopped);
        logWriter.print("Check whether breakpoint was set at the expected location...");
        if (location.methodID != methodId || lineStopped != breakpointLine) {
            return failed("Expected to stop in a method '" + method + "' at line " + breakpointLine + " instead of method '" + methodStopped + "', line " + lineStopped);
        }
        logWriter.print("OK");
        
        showConstants = true;
        showStaticFields = true;
        printStackFrames(threadID, true , false );
        
        logWriter.println("Resume debuggee VM");
        debuggeeWrapper.vmMirror.resume();        
        
        return passed();
    } 

Advertisement
Javadoc
This class represents JDWP event packet, which is special kind of command packet.
Advertisement