Search in sources :

Example 61 with SuspendedEvent

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

the class StepTest method testStepBadArgStepInto.

@Test
public void testStepBadArgStepInto() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            try {
                checkState(event, 2, true, "STATEMENT").prepareStepInto(0);
                fail("Exception expected");
            } catch (IllegalArgumentException e) {
                Assert.assertEquals("Step count must be > 0", e.getMessage());
            }
        });
        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 62 with SuspendedEvent

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

the class StepTest method testCallLoopStepOut.

@Test
public void testCallLoopStepOut() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, false, "CALL(foo)").prepareContinue();
        });
        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 63 with SuspendedEvent

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

the class StepTest method testExpressionStep.

@Test
public void testExpressionStep() {
    final Source source = testSource("ROOT(\n" + "  DEFINE(inner1, ROOT(\n" + "    STATEMENT,\n" + "    EXPRESSION,\n" + "    EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))\n" + "  )),\n" + "  DEFINE(inner2, ROOT(\n" + "    EXPRESSION,\n" + "    CALL(inner2_1),\n" + "    EXPRESSION(CALL(inner2_1))\n" + "  )),\n" + "  DEFINE(inner2_1, ROOT(\n" + "    STATEMENT(EXPRESSION(EXPRESSION))\n" + "  )),\n" + "  EXPRESSION,\n" + "  STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2))),\n" + "  EXPRESSION,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession(SourceElement.EXPRESSION)) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 15, true, "EXPRESSION").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 15, false, "EXPRESSION").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, true, "EXPRESSION(CALL(inner1))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, false, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "EXPRESSION(CONSTANT(1))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, false, "EXPRESSION(CONSTANT(1))").prepareStepOut(1);
            Assert.assertEquals("(1)", event.getReturnValue().as(String.class));
            Assert.assertEquals(Arrays.asList(event.getInputValues()).toString(), 0, event.getInputValues().length);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, false, "EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))").prepareStepInto(1);
            Assert.assertEquals("((1)+(2))", event.getReturnValue().as(String.class));
            DebugValue[] inputValues = event.getInputValues();
            Assert.assertEquals(Arrays.asList(inputValues).toString(), 2, event.getInputValues().length);
            Assert.assertEquals("(1)", inputValues[0].as(String.class));
            Assert.assertEquals("(2)", inputValues[1].as(String.class));
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "CALL(inner1)").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "EXPRESSION(CALL(inner1))").prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 8, true, "EXPRESSION").prepareStepOver(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "EXPRESSION(CALL(inner2_1))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 13, true, "EXPRESSION(EXPRESSION)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 13, false, "EXPRESSION(EXPRESSION)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "CALL(inner2_1)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "EXPRESSION(CALL(inner2_1))").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "CALL(inner2)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "EXPRESSION(CALL(inner2))").prepareStepOut(1);
        });
        expectDone();
    }
}
Also used : 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 64 with SuspendedEvent

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

the class StepTest method testCallLoopStepInto.

@Test
public void testCallLoopStepInto() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, false, "CALL(foo)").prepareContinue();
        });
        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 65 with SuspendedEvent

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

the class StepTest method testExpressionAndStatementStep.

@Test
public void testExpressionAndStatementStep() {
    final Source source = testSource("ROOT(\n" + "  DEFINE(inner1, ROOT(\n" + "    STATEMENT,\n" + "    EXPRESSION\n" + "  )),\n" + "  DEFINE(inner2, ROOT(\n" + "    EXPRESSION(STATEMENT), STATEMENT(CONSTANT(1))\n" + "  )),\n" + "  EXPRESSION,\n" + "  STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2))),\n" + "  EXPRESSION,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession(SourceElement.EXPRESSION, SourceElement.STATEMENT)) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 9, true, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 9, false, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2)))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "EXPRESSION(CALL(inner1))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "CALL(inner1)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "EXPRESSION(CALL(inner2))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "EXPRESSION(STATEMENT)").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, false, "EXPRESSION(STATEMENT)").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT(CONSTANT(1))").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "CALL(inner2)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "EXPRESSION(CALL(inner2))").prepareStepOut(1);
        });
        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)

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