Search in sources :

Example 1 with EventContext

use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.

the class DebuggerSessionSnippets method collectDebuggerNodes.

private List<DebuggerNode> collectDebuggerNodes(DebuggerNode source, SuspendAnchor suspendAnchor) {
    EventContext context = source.getContext();
    List<DebuggerNode> nodes = new ArrayList<>();
    nodes.add(source);
    Iterator<ExecutionEventNode> nodesIterator = context.lookupExecutionEventNodes(allBindings);
    if (SuspendAnchor.BEFORE.equals(suspendAnchor)) {
        // We collect nodes following the source (these nodes remain to be executed)
        boolean after = false;
        while (nodesIterator.hasNext()) {
            DebuggerNode node = (DebuggerNode) nodesIterator.next();
            if (after) {
                if (node.isActiveAt(suspendAnchor)) {
                    nodes.add(node);
                }
            } else {
                after = node == source;
            }
        }
    } else {
        // We collect nodes preceding the source (these nodes remain to be executed)
        while (nodesIterator.hasNext()) {
            DebuggerNode node = (DebuggerNode) nodesIterator.next();
            if (node == source) {
                break;
            }
            if (node.isActiveAt(suspendAnchor)) {
                nodes.add(node);
            }
        }
    }
    return nodes;
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) ArrayList(java.util.ArrayList) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode)

Example 2 with EventContext

use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.

the class InstrumentationUpdateTest method assertExecuted.

private void assertExecuted(Node... children) {
    Iterator<EventContext> executeIterator = executionEvents.iterator();
    for (Node loadedChild : children) {
        Assert.assertTrue(executeIterator.hasNext());
        Assert.assertSame(loadedChild, executeIterator.next().getInstrumentedNode());
    }
    Assert.assertFalse(executeIterator.hasNext());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode)

Example 3 with EventContext

use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.

the class InputFilterTest method assertCleanedUp.

private void assertCleanedUp(String code) {
    // first we capture all root nodes used by the code.
    Set<RootNode> rootNodes = new HashSet<>();
    EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {

        public void onEnter(EventContext c, VirtualFrame frame) {
            addRoot(c);
        }

        @TruffleBoundary
        private void addRoot(EventContext c) {
            rootNodes.add(c.getInstrumentedNode().getRootNode());
        }

        public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
        }

        public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
        }
    });
    execute(code);
    binding.dispose();
    // we execute again to let the instrumentation wrappers be cleaned up
    execute(code);
    for (RootNode root : rootNodes) {
        // all frame slots got removed
        assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
        // no wrappers left
        root.accept(new NodeVisitor() {

            public boolean visit(Node node) {
                if (node instanceof WrapperNode) {
                    throw new AssertionError();
                }
                return true;
            }
        });
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) HashSet(java.util.HashSet)

Example 4 with EventContext

use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.

the class DebuggerExampleTest method testStepOut.

@Test
@SuppressWarnings("hiding")
public void testStepOut() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(2, new Callback() {

        @Override
        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 2);
            debugger.stepOut(new Callback() {

                @Override
                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 6);
                    debugger.stepOver(new Callback() {

                        @Override
                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            throw new AssertionError();
                        }
                    });
                    allStepped.set(true);
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 5 with EventContext

use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.

the class DebuggerExampleTest method testStepInto.

@Test
@SuppressWarnings("hiding")
public void testStepInto() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(7, new Callback() {

        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 7);
            debugger.stepInto(new Callback() {

                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 4);
                    debugger.stepInto(new Callback() {

                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            assertLineAt(haltedAt, 5);
                            debugger.stepInto(new Callback() {

                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                    assertLineAt(haltedAt, 2);
                                    debugger.stepInto(new Callback() {

                                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                                            assertLineAt(haltedAt, 6);
                                            debugger.stepInto(new Callback() {

                                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                                    throw new AssertionError();
                                                }
                                            });
                                            allStepped.set(true);
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Aggregations

EventContext (com.oracle.truffle.api.instrumentation.EventContext)13 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)5 Test (org.junit.Test)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)4 Callback (com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Source (org.graalvm.polyglot.Source)4 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)3 Node (com.oracle.truffle.api.nodes.Node)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 LoadSourceSectionEvent (com.oracle.truffle.api.instrumentation.LoadSourceSectionEvent)2 LoadSourceSectionListener (com.oracle.truffle.api.instrumentation.LoadSourceSectionListener)2 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 EventBinding (com.oracle.truffle.api.instrumentation.EventBinding)1 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)1