com.sun.jdi.event.StepEvent Java Examples

The following examples show how to use com.sun.jdi.event.StepEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventHub.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the observable object for step events.
 * @return      the observable object for step events
 */
@Override
public Observable<DebugEvent> stepEvents() {
    return this.events().filter(debugEvent -> debugEvent.event instanceof StepEvent);
}
 
Example #2
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Does a single execution step of the concrete state.
 * 
 * @param doStepInto if {@code true} and the current bytecode is an INVOKEX bytecode,
 *        steps into the invoked method; if {@code false} and the current bytecode is 
 *        an INVOKEX bytecode, steps over.
 * @throws GuidanceException 
 */
private void doStep(boolean doStepInto) throws GuidanceException {
    final int stepDepth = doStepInto ? StepRequest.STEP_INTO : StepRequest.STEP_OVER;

    final ThreadReference thread = this.methodEntryEvent.thread();
    final EventRequestManager mgr = this.vm.eventRequestManager();
    final StepRequest sr = mgr.createStepRequest(thread, StepRequest.STEP_MIN, stepDepth);
    sr.enable();

    //if we are at an ILOAD bytecode followed by an XALOAD, 
    //we store the value from the variable because it is used
    //as XALOAD index
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    final byte currentOpcode = bc[currentCodeIndex];
    if (currentOpcode == OP_ILOAD || 
        (OP_ILOAD_0 <= currentOpcode && currentOpcode <= OP_ILOAD_3)) {
        final boolean wide = (this.previousCodeIndex >= 0 && bc[this.previousCodeIndex] == OP_WIDE);
        final int nextCodeIndex; 
        if (currentOpcode == OP_ILOAD) {
            nextCodeIndex = currentCodeIndex + (wide ? XLOADSTORE_IMMEDIATE_WIDE_OFFSET : XLOADSTORE_IMMEDIATE_OFFSET);
        } else {
            nextCodeIndex = currentCodeIndex + XLOADSTORE_IMPLICIT_OFFSET;
        }
        final byte opcodeNext = bc[nextCodeIndex];
        if (OP_IALOAD <= opcodeNext && opcodeNext <= OP_SALOAD) {
            //determines the index of the local variable
            final int localVariableIndex;
            if (currentOpcode == OP_ILOAD_0) {
                localVariableIndex = 0;
            } else if (currentOpcode == OP_ILOAD_1) {
                localVariableIndex = 1;
            } else if (currentOpcode == OP_ILOAD_2) {
                localVariableIndex = 2;
            } else if (currentOpcode == OP_ILOAD_3) {
                localVariableIndex = 3;
            } else {
                localVariableIndex = (wide ? byteCat(bc[currentCodeIndex + 1], bc[currentCodeIndex + 2]) : asUnsignedByte(bc[currentCodeIndex + 1]));
            }
            this.xaloadIndex = readLocalVariable(localVariableIndex);
        } else {
            this.xaloadIndex = null;
        }
    } else if (OP_IALOAD <= currentOpcode && currentOpcode <= OP_SALOAD) {
        //does nothing
    } else {
        this.xaloadIndex = null;
    }
    if (isInvoke(currentOpcode) || isReturn(currentOpcode)) {
        //no valid previous code index
        this.previousCodeIndex = -1;
    } else {
        this.previousCodeIndex = currentCodeIndex;
    }
    this.vm.resume();
    final EventQueue queue = this.vm.eventQueue();

    boolean stepFound = false;
    while (!stepFound) {
        try {
            final EventSet eventSet = queue.remove();
            final EventIterator it = eventSet.eventIterator();
            while (!stepFound && it.hasNext()) {
                final Event event = it.nextEvent();

                if (event instanceof StepEvent) {
                    this.currentStepEvent = (StepEvent) event;
                    stepFound = true;
                }
            }
            if (!stepFound) {
                eventSet.resume();
            }
        } catch (InterruptedException | VMDisconnectedException e) {
            throw new GuidanceException(e);
        }
    }

    sr.disable();
}