Search in sources :

Example 11 with SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 SuspendedEvent

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

the class TimeBoxingTest method testTimeBoxing.

@Test
public void testTimeBoxing() throws Exception {
    final Context context = Context.create();
    Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(LOOP(infinity,STATEMENT))", "NotEnoughTime").buildLiteral();
    new Timer().schedule(new TimerTask() {

        @Override
        public void run() {
            Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
            debugger.startSession(new SuspendedCallback() {

                public void onSuspend(SuspendedEvent event) {
                    event.prepareKill();
                }
            }).suspendNextExecution();
        }
    }, 1000);
    try {
        // throws KillException, wrapped by PolyglotException
        context.eval(source);
        Assert.fail();
    } catch (PolyglotException pex) {
        Assert.assertEquals("com.oracle.truffle.api.debug.KillException", pex.getMessage());
    }
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) Timer(java.util.Timer) TimerTask(java.util.TimerTask) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) PolyglotException(org.graalvm.polyglot.PolyglotException) Source(org.graalvm.polyglot.Source) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Aggregations

SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)100 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)97 Source (org.graalvm.polyglot.Source)95 Test (org.junit.Test)93 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)45 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)19 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 Debugger (com.oracle.truffle.api.debug.Debugger)11 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)9 Context (org.graalvm.polyglot.Context)9 SourceSection (com.oracle.truffle.api.source.SourceSection)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 DebugScope (com.oracle.truffle.api.debug.DebugScope)5 HashMap (java.util.HashMap)3 DebugContext (com.oracle.truffle.api.debug.DebugContext)2 Map (java.util.Map)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2