Search in sources :

Example 6 with DebuggerSession

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

the class StepTest method testNoPreparesAfterContinueOrKill.

@Test
public void testNoPreparesAfterContinueOrKill() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(loop,\n" + "    LOOP(3,\n" + "      STATEMENT),\n" + "    STATEMENT\n" + "  ),\n" + "  STATEMENT(CALL(loop))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        Breakpoint bp5 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(5).build();
        session.install(bp5);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT(CALL(loop))").prepareContinue();
            try {
                event.prepareStepInto(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOver(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOut(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareContinue();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareKill();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT").prepareKill();
            try {
                event.prepareStepInto(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOver(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOut(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareContinue();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareKill();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
        });
        expectKilled();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 7 with DebuggerSession

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

the class StepTest method testIncompatibleSourceElements.

@Test
public void testIncompatibleSourceElements() {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  EXPRESSION\n" + ")\n");
    // No SourceElements, no stepping/suspensions
    try (DebuggerSession session = startSession(new SourceElement[] {})) {
        startEval(source);
        session.suspendNextExecution();
        expectDone();
    }
    try (DebuggerSession session = startSession(new SourceElement[] {})) {
        Breakpoint breakpoint = Breakpoint.newBuilder(DebuggerTester.getSourceImpl(source)).lineIs(2).oneShot().build();
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.STATEMENT).build());
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
            try {
                event.prepareStepInto(1);
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
        });
        expectDone();
    }
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
                fail();
            } catch (IllegalArgumentException ex) {
            // O.K.
            }
        });
        expectDone();
    }
    try (DebuggerSession session = startSession(SourceElement.EXPRESSION)) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "EXPRESSION");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.STATEMENT).build());
                fail();
            } catch (IllegalArgumentException ex) {
            // O.K.
            }
            // O.K.
            event.prepareStepInto(1);
            // O.K.
            event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 8 with DebuggerSession

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

the class StepTest method testStepIntoAndOut.

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

Example 9 with DebuggerSession

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

the class StepTest method testBlockStepIntoOver.

@Test
public void testBlockStepIntoOver() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT").prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT").prepareStepOver(3);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 9, true, "STATEMENT").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 10 with DebuggerSession

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

the class StepTest method testStepOver1.

@Test
public void testStepOver1() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, STATEMENT),\n" + "  DEFINE(foo, ROOT(STATEMENT(CALL(bar)), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(CALL(foo)),\n" + "  STATEMENT(CALL(foo)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT(CALL(foo))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT(CALL(foo))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT(CALL(foo))").prepareStepOver(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

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