Search in sources :

Example 11 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.

the class SuspendedEventTest method testIsInternal.

@Test
public void testIsInternal() throws Throwable {
    final Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(bar, ROOT(STATEMENT)),\n" + "  DEFINE(foo, STATEMENT, \n" + "              STATEMENT(CALL(bar))),\n" + "  STATEMENT(CALL(foo))\n" + ")\n", "internal test code").internal(true).build();
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            DebugStackFrame frame = frameIterator.next();
            assertTrue(frame.isInternal());
            frame = frameIterator.next();
            assertTrue(frame.isInternal());
            frame = frameIterator.next();
            assertTrue(frame.isInternal());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 12 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.

the class SuspensionFilterTest method testSuspendAfterInitialization2.

@Test
public void testSuspendAfterInitialization2() {
    // Suspend after initialization code finishes,
    // but can step into the same code that was executed during initialization, later on.
    Source initSource = Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION)", "<init>").buildLiteral();
    InstrumentationTestLanguage.envConfig = new HashMap<>();
    InstrumentationTestLanguage.envConfig.put("initSource", initSource);
    InstrumentationTestLanguage.envConfig.put("runInitAfterExec", true);
    final Source source = testSource("ROOT(\n" + "  STATEMENT(CONSTANT(42))\n" + ")\n");
    SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().ignoreLanguageContextInitialization(true).build();
    try (DebuggerSession session = startSession()) {
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT(CONSTANT(42))").prepareStepOver(1);
            Assert.assertTrue(event.isLanguageContextInitialized());
            session.suspendNextExecution();
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 1, true, "STATEMENT(EXPRESSION)").prepareContinue();
            Assert.assertTrue(event.isLanguageContextInitialized());
        });
        expectDone();
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 13 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.

the class SuspensionFilterTest method testInternalSteppingChange.

@Test
public void testInternalSteppingChange() throws Exception {
    final Source internSource = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(intern, \n" + "    STATEMENT(EXPRESSION),\n" + "    STATEMENT(CONSTANT(42))\n" + "  ),\n" + "  CALL(intern)\n" + ")\n", "intern").internal(true).build();
    final Source source = testSource("ROOT(\n" + "  LOOP(5,\n" + "    STATEMENT(CALL(intern))\n" + "  )\n" + ")\n");
    SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().includeInternal(true).build();
    try (DebuggerSession session = startSession()) {
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(internSource);
        // we stop in the internal source as the filter does not ignore internal sources now
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(EXPRESSION)");
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(CONSTANT(42))");
            event.prepareContinue();
        });
        expectDone();
        // Ignore internal sources now
        suspensionFilter = SuspensionFilter.newBuilder().includeInternal(false).build();
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CALL(intern))");
            event.prepareStepInto(1);
        });
        // Step into does not go into the internal source:
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CALL(intern))");
            // do not ignore instenal sources again
            session.setSteppingFilter(SuspensionFilter.newBuilder().includeInternal(true).build());
            event.prepareStepInto(1);
        });
        // Stopped in an internal source again
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(EXPRESSION)");
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 14 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.

the class SuspensionFilterTest method testSourceFilter.

@Test
public void testSourceFilter() {
    final Source source1 = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(foo1,\n" + "    STATEMENT(CONSTANT(43))\n" + "  ))\n", "Source1").buildLiteral();
    final Source source2 = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(foo2,\n" + "    STATEMENT(CONSTANT(44))\n" + "  ))\n", "Source2").buildLiteral();
    final Source source3 = testSource("ROOT(\n" + "  CALL(foo1),\n" + "  CALL(foo2),\n" + "  STATEMENT(CALL(foo1)),\n" + "  STATEMENT(CALL(foo2)),\n" + "  STATEMENT(CALL(foo1)),\n" + "  STATEMENT(CALL(foo2)),\n" + "  STATEMENT(CONSTANT(100))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        // Filter out all sections
        SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().sourceIs(s -> false).build();
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(source1);
        expectDone();
        startEval(source2);
        expectDone();
        startEval(source3);
        expectDone();
        Predicate<com.oracle.truffle.api.source.Source> filterSource1 = source -> {
            return source.getName().indexOf("Source1") < 0;
        };
        suspensionFilter = SuspensionFilter.newBuilder().sourceIs(filterSource1).build();
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(source3);
        // Skip foo1 and suspend in foo2:
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CONSTANT(44))");
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, false, "CALL(foo2)");
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(CALL(foo1))");
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT(CALL(foo2))");
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CONSTANT(44))");
            event.prepareStepInto(2);
        });
        // Change the filter to filter Source2 out:
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT(CALL(foo1))");
            Predicate<com.oracle.truffle.api.source.Source> filterSource2 = source -> {
                return source.getName().indexOf("Source2") < 0;
            };
            session.setSteppingFilter(SuspensionFilter.newBuilder().sourceIs(filterSource2).build());
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CONSTANT(43))");
            event.prepareStepOut(1).prepareStepOver(1).prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 8, true, "STATEMENT(CONSTANT(100))");
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) InstrumentationTestLanguage(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) Predicate(java.util.function.Predicate) After(org.junit.After) Source(org.graalvm.polyglot.Source) HashMap(java.util.HashMap) Test(org.junit.Test) Assert(org.junit.Assert) Collections(java.util.Collections) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 15 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.

the class SuspensionFilterTest method testInternalNoSuspend.

@Test
public void testInternalNoSuspend() throws Exception {
    final Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  STATEMENT(EXPRESSION),\n" + "  STATEMENT(CONSTANT(42))\n" + ")\n", "test").internal(true).build();
    // No suspension filter is necessary, internal sources are ignored by default
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        // does not stop in internal source
        expectDone();
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Aggregations

DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)110 Source (org.graalvm.polyglot.Source)103 Test (org.junit.Test)102 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)97 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)49 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)20 DebugValue (com.oracle.truffle.api.debug.DebugValue)16 Debugger (com.oracle.truffle.api.debug.Debugger)14 Context (org.graalvm.polyglot.Context)11 SourceSection (com.oracle.truffle.api.source.SourceSection)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 DebugContext (com.oracle.truffle.api.debug.DebugContext)6 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)6 DebugScope (com.oracle.truffle.api.debug.DebugScope)5 Engine (org.graalvm.polyglot.Engine)5 HashMap (java.util.HashMap)3 Value (org.graalvm.polyglot.Value)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2