Search in sources :

Example 66 with DebuggerSession

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

the class StepTest method testStepBadArgStepOver.

@Test
public void testStepBadArgStepOver() 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").prepareStepOver(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 67 with DebuggerSession

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

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

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

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

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