Search in sources :

Example 71 with DebuggerSession

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

Example 72 with DebuggerSession

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

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

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

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

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