Search in sources :

Example 6 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class RequestedJDWPEvents method handleModKind.

private void handleModKind(RequestFilter filter, PacketStream input, byte modKind, JDWPContext context) {
    switch(modKind) {
        case 1:
            int count = input.readInt();
            JDWP.LOGGER.fine(() -> "adding count limit: " + count + " to filter");
            filter.addEventCount(count);
            break;
        case 2:
            JDWP.LOGGER.fine(() -> "unhandled modKind 2");
            break;
        case // limit to specific thread
        3:
            long threadId = input.readLong();
            Object thread = ids.fromId((int) threadId);
            filter.addThread(thread);
            JDWP.LOGGER.fine(() -> "limiting to thread: " + context.getThreadName(thread));
            break;
        case 4:
            long refTypeId = input.readLong();
            final KlassRef finalKlass = (KlassRef) ids.fromId((int) refTypeId);
            filter.addRefTypeLimit(finalKlass);
            JDWP.LOGGER.fine(() -> "RefType limit: " + finalKlass);
            break;
        case // class positive pattern
        5:
            String classPattern = Pattern.quote(input.readString()).replace("*", "\\E.*\\Q");
            try {
                Pattern pattern = Pattern.compile(classPattern);
                filter.addPositivePattern(pattern);
                JDWP.LOGGER.fine(() -> "adding positive refType pattern: " + pattern.pattern());
            } catch (PatternSyntaxException ex) {
                // wrong input pattern
                throw new RuntimeException("should not reach here");
            }
            break;
        case 6:
            classPattern = Pattern.quote(input.readString()).replace("*", "\\E.*\\Q");
            try {
                Pattern pattern = Pattern.compile(classPattern);
                filter.addExcludePattern(pattern);
                JDWP.LOGGER.fine(() -> "adding negative refType pattern: " + pattern.pattern());
            } catch (PatternSyntaxException ex) {
                // wrong input pattern
                throw new RuntimeException("should not reach here");
            }
            break;
        case // location-specific
        7:
            byte typeTag = input.readByte();
            long classId = input.readLong();
            long methodId = input.readLong();
            long bci = input.readLong();
            final KlassRef finalKlass2 = (KlassRef) ids.fromId((int) classId);
            String slashName = finalKlass2.getTypeAsString();
            MethodRef method = (MethodRef) ids.fromId((int) methodId);
            int line = method.bciToLineNumber((int) bci);
            LineBreakpointInfo info = new LineBreakpointInfo(filter, typeTag, classId, methodId, bci, slashName, line);
            filter.addBreakpointInfo(info);
            JDWP.LOGGER.fine(() -> "Adding breakpoint info for location: " + finalKlass2.getNameAsString() + "." + method.getNameAsString() + "." + line);
            break;
        case 8:
            refTypeId = input.readLong();
            KlassRef klass = null;
            if (refTypeId != 0) {
                klass = (KlassRef) ids.fromId((int) refTypeId);
            }
            boolean caught = input.readBoolean();
            boolean unCaught = input.readBoolean();
            ExceptionBreakpointInfo exceptionBreakpointInfo = new ExceptionBreakpointInfo(filter, klass, caught, unCaught);
            filter.addBreakpointInfo(exceptionBreakpointInfo);
            JDWP.LOGGER.fine(() -> "adding exception filter: caught=" + caught + ", uncaught=" + unCaught);
            break;
        case // limit to specific field
        9:
            refTypeId = input.readLong();
            long fieldId = input.readLong();
            klass = (KlassRef) ids.fromId((int) refTypeId);
            FieldRef field = (FieldRef) ids.fromId((int) fieldId);
            FieldBreakpointInfo fieldBreakpointInfo = new FieldBreakpointInfo(filter, klass, field);
            filter.addBreakpointInfo(fieldBreakpointInfo);
            JDWP.LOGGER.fine(() -> "limiting to field: " + field.getNameAsString());
            break;
        case 10:
            threadId = input.readLong();
            thread = ids.fromId((int) threadId);
            int size = input.readInt();
            int depth = input.readInt();
            StepInfo stepInfo = new StepInfo(size, depth, thread);
            filter.setStepInfo(stepInfo);
            JDWP.LOGGER.fine(() -> "Step command: size= " + size + ", depth=" + depth);
            break;
        case 11:
            long thisId = input.readLong();
            JDWP.LOGGER.fine(() -> "adding instance filter for object ID: " + thisId);
            filter.addThisFilterId(thisId);
            break;
        case 12:
            JDWP.LOGGER.fine(() -> "unhandled modKind 12");
            break;
        default:
            break;
    }
}
Also used : Pattern(java.util.regex.Pattern) FieldRef(com.oracle.truffle.espresso.jdwp.api.FieldRef) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 7 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef 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);
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) JDWPContext(com.oracle.truffle.espresso.jdwp.api.JDWPContext) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Example 8 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class DebuggerController method submitMethodEntryBreakpoint.

public void submitMethodEntryBreakpoint(DebuggerCommand debuggerCommand) {
    // method entry breakpoints are limited per class, so we must
    // install a first line breakpoint into each method in the class
    KlassRef[] klasses = debuggerCommand.getRequestFilter().getKlassRefPatterns();
    List<Breakpoint> breakpoints = new ArrayList<>();
    for (KlassRef klass : klasses) {
        for (MethodRef method : klass.getDeclaredMethodRefs()) {
            int line = method.getFirstLine();
            Breakpoint bp;
            if (line != -1) {
                bp = Breakpoint.newBuilder(method.getSource()).lineIs(line).build();
            } else {
                bp = Breakpoint.newBuilder(method.getSource().createUnavailableSection()).build();
            }
            breakpoints.add(bp);
        }
    }
    BreakpointInfo breakpointInfo = debuggerCommand.getBreakpointInfo();
    for (Breakpoint breakpoint : breakpoints) {
        mapBreakpoint(breakpoint, breakpointInfo);
        debuggerSession.install(breakpoint);
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) ArrayList(java.util.ArrayList) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Example 9 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class DebuggerController method doStepOut.

private void doStepOut(SuspendedInfo susp) {
    RootNode callerRoot = susp.getCallerRootNode();
    int stepOutBCI = context.getNextBCI(callerRoot, susp.getCallerFrame());
    SteppingInfo steppingInfo = commandRequestIds.get(susp.getThread());
    if (steppingInfo != null && stepOutBCI != -1) {
        // record the location that we'll land on after the step out completes
        MethodRef method = context.getMethodFromRootNode(callerRoot);
        if (method != null) {
            KlassRef klass = method.getDeclaringKlassRef();
            steppingInfo.setStepOutBCI(context.getIds().getIdAsLong(klass), context.getIds().getIdAsLong(method), stepOutBCI);
        }
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Aggregations

KlassRef (com.oracle.truffle.espresso.jdwp.api.KlassRef)9 MethodRef (com.oracle.truffle.espresso.jdwp.api.MethodRef)6 ArrayList (java.util.ArrayList)4 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)2 CallFrame (com.oracle.truffle.espresso.jdwp.api.CallFrame)2 CallTarget (com.oracle.truffle.api.CallTarget)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1 Node (com.oracle.truffle.api.nodes.Node)1 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 FieldRef (com.oracle.truffle.espresso.jdwp.api.FieldRef)1 JDWPContext (com.oracle.truffle.espresso.jdwp.api.JDWPContext)1 MonitorStackInfo (com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo)1 RedefineInfo (com.oracle.truffle.espresso.jdwp.api.RedefineInfo)1