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;
}
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);
}
}
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;
}
Aggregations