Search in sources :

Example 1 with MethodBreakpointEvent

use of com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent 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 MethodBreakpointEvent

use of com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent 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

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 MethodBreakpointEvent (com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent)2 MethodBreakpointInfo (com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo)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 ArrayList (java.util.ArrayList)1