Search in sources :

Example 66 with SuspendedEvent

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

the class SuspendedEventTest method testStackFrames.

@Test
public void testStackFrames() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + "  DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(VARIABLE(root0, 43)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT(VARIABLE(root0, 43))").prepareStepOver(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next());
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT(CALL(foo))", "root0", "43").prepareStepInto(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(CALL(bar))", "foo0", "42").prepareStepInto(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "foo0", "42");
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT", "bar0", "41", "bar1", "40").prepareContinue();
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "bar0", "41", "bar1", "40");
            checkStack(frameIterator.next(), "foo0", "42");
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        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 67 with SuspendedEvent

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

the class SuspendedEventTest method testReturnValue.

@Test
public void testReturnValue() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, STATEMENT(CONSTANT(42))), \n" + "  DEFINE(foo, CALL(bar)), \n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(CALL(foo))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT(CONSTANT(42))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, false, "CALL(bar)").prepareStepInto(1);
            assertEquals("42", event.getReturnValue().as(String.class));
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, false, "CALL(foo)").prepareContinue();
            assertEquals("42", event.getReturnValue().as(String.class));
        });
        expectDone();
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 68 with SuspendedEvent

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

the class SuspendedEventTest method testOtherThreadAccess.

@Test
public void testOtherThreadAccess() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + "  DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(VARIABLE(root0, 43)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        final Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            run(() -> event.getBreakpointConditionException(breakpoint));
            run(() -> event.getSession());
            run(() -> event.getSourceSection());
            run(() -> event.getBreakpoints());
            run(() -> event.getSuspendAnchor());
            run(() -> event.toString());
            run(() -> {
                event.prepareStepInto(1);
                return null;
            });
            run(() -> {
                event.prepareStepOut(1);
                return null;
            });
            run(() -> {
                event.prepareStepOver(1);
                return null;
            });
            run(() -> {
                event.prepareContinue();
                return null;
            });
            run(() -> {
                event.prepareKill();
                return null;
            });
            runExpectIllegalState(() -> event.getStackFrames());
            runExpectIllegalState(() -> event.getTopStackFrame());
            runExpectIllegalState(() -> event.getReturnValue());
            for (DebugStackFrame frame : event.getStackFrames()) {
                for (DebugValue value : frame) {
                    runExpectIllegalState(() -> value.as(String.class));
                    runExpectIllegalState(() -> {
                        value.set(null);
                        return null;
                    });
                    // Name is known
                    value.getName();
                    runExpectIllegalState(() -> value.isReadable());
                    runExpectIllegalState(() -> value.isWritable());
                }
                run(() -> frame.getName());
                run(() -> frame.getSourceSection());
                run(() -> frame.isInternal());
                run(() -> frame.toString());
                runExpectIllegalState(() -> frame.getScope().getDeclaredValue(""));
                runExpectIllegalState(() -> frame.getScope().getDeclaredValues().iterator());
                runExpectIllegalState(() -> frame.eval(""));
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 69 with SuspendedEvent

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

the class SuspensionFilterTest method testSuspendInInitialization.

@Test
public void testSuspendInInitialization() {
    Source initSource = Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION)", "<init>").buildLiteral();
    InstrumentationTestLanguage.envConfig = Collections.singletonMap("initSource", initSource);
    final Source source = testSource("ROOT(\n" + "  DEFINE(foo, \n" + "    STATEMENT(CONSTANT(42))\n" + "  ), \n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().build();
    // Empty filter does not filter anything
    try (DebuggerSession session = startSession()) {
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 1, true, "STATEMENT(EXPRESSION)").prepareContinue();
            Assert.assertFalse(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 70 with SuspendedEvent

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

the class SuspensionFilterTest method testSuspendAfterInitialization.

@Test
public void testSuspendAfterInitialization() {
    Source initSource = Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION)", "<init>").buildLiteral();
    InstrumentationTestLanguage.envConfig = Collections.singletonMap("initSource", initSource);
    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))").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)

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