Search in sources :

Example 1 with MethodBreakpointInfo

use of com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo in project graal by oracle.

the class VMEventListenerImpl method onMethodReturn.

@Override
@TruffleBoundary
public boolean onMethodReturn(MethodRef method, Object returnValue) {
    boolean active = false;
    for (MethodHook hook : method.getMethodHooks()) {
        if (hook.onMethodExit(method, returnValue)) {
            // OK, tell the Debug API to suspend the thread now
            debuggerController.prepareMethodBreakpoint(new MethodBreakpointEvent((MethodBreakpointInfo) hook, returnValue));
            debuggerController.suspend(context.asGuestThread(Thread.currentThread()));
            active = true;
            switch(hook.getKind()) {
                case ONE_TIME:
                    if (hook.hasFired()) {
                        method.removedMethodHook(hook);
                    }
                    break;
                case INDEFINITE:
                    // leave the hook active
                    break;
            }
        }
    }
    return active;
}
Also used : MethodBreakpointEvent(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent) MethodBreakpointInfo(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with MethodBreakpointInfo

use of com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo in project graal by oracle.

the class VMEventListenerImpl method methodBreakpointHit.

@Override
public void methodBreakpointHit(MethodBreakpointEvent methodEvent, Object currentThread, CallFrame frame) {
    if (connection == null) {
        return;
    }
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    MethodBreakpointInfo info = methodEvent.getInfo();
    stream.writeByte(info.getSuspendPolicy());
    // # events in reply
    stream.writeInt(1);
    stream.writeByte(info.getEventKind());
    stream.writeInt(info.getRequestId());
    long threadId = ids.getIdAsLong(currentThread);
    stream.writeLong(threadId);
    // location
    stream.writeByte(frame.getTypeTag());
    stream.writeLong(frame.getClassId());
    stream.writeLong(frame.getMethodId());
    stream.writeLong(frame.getCodeIndex());
    // return value if requested
    if (info.getEventKind() == RequestedJDWPEvents.METHOD_EXIT_WITH_RETURN_VALUE) {
        Object returnValue = methodEvent.getReturnValue();
        byte tag = context.getTag(returnValue);
        JDWP.writeValue(tag, returnValue, stream, true, context);
    }
    if (holdEvents) {
        heldEvents.add(stream);
    } else {
        connection.queuePacket(stream);
    }
}
Also used : PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream) MethodBreakpointInfo(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo)

Example 3 with MethodBreakpointInfo

use of com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo in project graal by oracle.

the class VMEventListenerImpl method onMethodEntry.

@Override
@TruffleBoundary
public boolean onMethodEntry(MethodRef method, Object scope) {
    boolean active = false;
    // collect variable information from scope
    List<MethodVariable> variables = new ArrayList<>(1);
    try {
        if (UNCACHED.hasMembers(scope)) {
            Object identifiers = UNCACHED.getMembers(scope);
            if (UNCACHED.hasArrayElements(identifiers)) {
                long size = UNCACHED.getArraySize(identifiers);
                for (long i = 0; i < size; i++) {
                    String identifier = (String) UNCACHED.readArrayElement(identifiers, i);
                    Object value = UNCACHED.readMember(scope, identifier);
                    variables.add(new MethodVariable(identifier, value));
                }
            }
        }
    } catch (UnsupportedMessageException | InvalidArrayIndexException | UnknownIdentifierException e) {
    // not able to fetch locals, so leave variables list empty
    }
    for (MethodHook hook : method.getMethodHooks()) {
        // pass on the variables to the method entry hook
        if (hook.onMethodEnter(method, variables.toArray(new MethodVariable[variables.size()]))) {
            // OK, tell the Debug API to suspend the thread now
            debuggerController.prepareMethodBreakpoint(new MethodBreakpointEvent((MethodBreakpointInfo) hook, null));
            debuggerController.suspend(context.asGuestThread(Thread.currentThread()));
            active = true;
            switch(hook.getKind()) {
                case ONE_TIME:
                    if (hook.hasFired()) {
                        method.removedMethodHook(hook);
                    }
                    break;
                case INDEFINITE:
                    // leave the hook active
                    break;
            }
        }
    }
    return active;
}
Also used : MethodBreakpointEvent(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent) ArrayList(java.util.ArrayList) MethodBreakpointInfo(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

MethodBreakpointInfo (com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 MethodBreakpointEvent (com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent)2 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 PacketStream (com.oracle.truffle.espresso.jdwp.impl.PacketStream)1 ArrayList (java.util.ArrayList)1