use of com.oracle.truffle.espresso.jdwp.api.JDWPContext in project graal by oracle.
the class RequestedJDWPEvents method registerEvent.
public CommandResult registerEvent(Packet packet, Commands callback) {
ArrayList<Callable<Void>> preFutures = new ArrayList<>();
ArrayList<Callable<Void>> postFutures = new ArrayList<>();
PacketStream input = new PacketStream(packet);
JDWPContext context = controller.getContext();
byte eventKind = input.readByte();
byte suspendPolicy = input.readByte();
int modifiers = input.readInt();
RequestFilter filter = new RequestFilter(packet.id, eventKind, suspendPolicy);
JDWP.LOGGER.fine(() -> "New event request with ID: " + packet.id + " with kind: " + eventKind + " and modifiers: " + modifiers);
for (int i = 0; i < modifiers; i++) {
byte modKind = input.readByte();
JDWP.LOGGER.fine(() -> "Handling modKind: " + modKind);
handleModKind(filter, input, modKind, context);
}
switch(eventKind) {
case SINGLE_STEP:
StepInfo stepInfo = filter.getStepInfo();
Object thread = stepInfo.getGuestThread();
switch(stepInfo.getDepth()) {
case SteppingConstants.INTO:
callback.stepInto(thread, filter);
break;
case SteppingConstants.OVER:
callback.stepOver(thread, filter);
break;
case SteppingConstants.OUT:
callback.stepOut(thread, filter);
break;
}
break;
case METHOD_ENTRY:
case METHOD_EXIT:
case METHOD_EXIT_WITH_RETURN_VALUE:
MethodBreakpointInfo methodInfo = new MethodBreakpointInfo(filter);
methodInfo.addSuspendPolicy(suspendPolicy);
eventListener.addBreakpointRequest(filter.getRequestId(), methodInfo);
for (KlassRef klass : filter.getKlassRefPatterns()) {
for (MethodRef method : klass.getDeclaredMethodRefs()) {
method.addMethodHook(methodInfo);
methodInfo.addMethod(method);
}
}
filter.addBreakpointInfo(methodInfo);
break;
case BREAKPOINT:
BreakpointInfo info = filter.getBreakpointInfo();
info.addSuspendPolicy(suspendPolicy);
eventListener.addBreakpointRequest(filter.getRequestId(), info);
postFutures.add(callback.createLineBreakpointCommand(info));
break;
case EXCEPTION:
info = filter.getBreakpointInfo();
if (info == null) {
// no filtering then, so setup a report all info
info = new ExceptionBreakpointInfo(filter, null, true, true);
}
info.addSuspendPolicy(suspendPolicy);
eventListener.addBreakpointRequest(filter.getRequestId(), info);
preFutures.add(callback.createExceptionBreakpoint(info));
JDWP.LOGGER.fine(() -> "Submitting new exception breakpoint");
break;
case CLASS_PREPARE:
eventListener.addClassPrepareRequest(new ClassPrepareRequest(filter));
JDWP.LOGGER.fine(() -> "Class prepare request received");
break;
case FIELD_ACCESS:
FieldBreakpointInfo fieldBreakpointInfo = (FieldBreakpointInfo) filter.getBreakpointInfo();
fieldBreakpointInfo.addSuspendPolicy(suspendPolicy);
fieldBreakpointInfo.setAccessBreakpoint();
fieldBreakpointInfo.getField().addFieldBreakpointInfo(fieldBreakpointInfo);
String location = fieldBreakpointInfo.getKlass().getNameAsString() + "." + fieldBreakpointInfo.getField().getNameAsString();
JDWP.LOGGER.fine(() -> "Submitting field access breakpoint: " + location);
break;
case FIELD_MODIFICATION:
fieldBreakpointInfo = (FieldBreakpointInfo) filter.getBreakpointInfo();
fieldBreakpointInfo.addSuspendPolicy(suspendPolicy);
fieldBreakpointInfo.setModificationBreakpoint();
fieldBreakpointInfo.getField().addFieldBreakpointInfo(fieldBreakpointInfo);
location = fieldBreakpointInfo.getKlass().getNameAsString() + "." + fieldBreakpointInfo.getField().getNameAsString();
JDWP.LOGGER.fine(() -> "Submitting field modification breakpoint: " + location);
break;
case THREAD_START:
eventListener.addThreadStartedRequestId(packet.id, suspendPolicy);
break;
case THREAD_DEATH:
eventListener.addThreadDiedRequestId(packet.id, suspendPolicy);
break;
case CLASS_UNLOAD:
eventListener.addClassUnloadRequestId(packet.id);
break;
case // no debuggers should ask for this event
VM_START:
eventListener.addVMStartRequest(packet.id);
break;
case VM_DEATH:
eventListener.addVMDeathRequest(packet.id, suspendPolicy);
break;
case MONITOR_CONTENDED_ENTER:
eventListener.addMonitorContendedEnterRequest(packet.id, filter);
break;
case MONITOR_CONTENDED_ENTERED:
eventListener.addMonitorContendedEnteredRequest(packet.id, filter);
break;
case MONITOR_WAIT:
eventListener.addMonitorWaitRequest(packet.id, filter);
break;
case MONITOR_WAITED:
eventListener.addMonitorWaitedRequest(packet.id, filter);
break;
default:
JDWP.LOGGER.fine(() -> "unhandled event kind " + eventKind);
break;
}
// register the request filter for this event
controller.getEventFilters().addFilter(filter);
return new CommandResult(toReply(packet), preFutures, postFutures);
}
Aggregations