Search in sources :

Example 36 with DebuggerSession

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

the class BreakpointTest method testBreakpointCondition.

@Test
public void testBreakpointCondition() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
        // No condition initially:
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(1, breakpoint.getHitCount());
        expectDone();
        breakpoint.setCondition("CONSTANT(true)");
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(2, breakpoint.getHitCount());
        expectDone();
        breakpoint.setCondition("CONSTANT(false)");
        startEval(testSource);
        expectDone();
        assertEquals(2, breakpoint.getHitCount());
        // remove the condition
        breakpoint.setCondition(null);
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(3, breakpoint.getHitCount());
        expectDone();
        // error by parse exception
        breakpoint.setCondition("CONSTANT(");
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNotNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(4, breakpoint.getHitCount());
        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 37 with DebuggerSession

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

the class BreakpointTest method testMultiSessionBreakpointConditionExecutedOnce.

@Test
public void testMultiSessionBreakpointConditionExecutedOnce() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session1 = startSession()) {
        Breakpoint breakpoint1 = session1.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        breakpoint1.setCondition("ROOT(PRINT(OUT, Hi1), CONSTANT(true))");
        try (DebuggerSession session2 = startSession()) {
            session2.install(breakpoint1);
            try (DebuggerSession session3 = startSession()) {
                Breakpoint breakpoint3 = session3.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
                breakpoint3.setCondition("ROOT(PRINT(OUT, Hi3), CONSTANT(true))");
                session3.suspendNextExecution();
                startEval(testSource);
                expectSuspended((SuspendedEvent event) -> {
                    assertSame(session3, event.getSession());
                    assertTrue(event.getBreakpoints().isEmpty());
                    event.prepareStepOver(1);
                });
                expectSuspended((SuspendedEvent event) -> {
                    assertSame(session3, event.getSession());
                    assertEquals(1, event.getBreakpoints().size());
                    assertSame(breakpoint3, event.getBreakpoints().get(0));
                });
                expectSuspended((SuspendedEvent event) -> {
                    assertSame(session1, event.getSession());
                    assertEquals(1, event.getBreakpoints().size());
                    assertSame(breakpoint1, event.getBreakpoints().get(0));
                });
                expectSuspended((SuspendedEvent event) -> {
                    assertSame(session2, event.getSession());
                    assertEquals(1, event.getBreakpoints().size());
                    assertSame(breakpoint1, event.getBreakpoints().get(0));
                });
                expectDone();
                assertEquals("Hi3Hi1", getOutput());
                assertEquals(1, breakpoint1.getHitCount());
                assertEquals(1, breakpoint3.getHitCount());
            }
        }
    }
}
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 38 with DebuggerSession

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

the class BreakpointTest method testBreakAtExpressions.

@Test
public void testBreakAtExpressions() {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  EXPRESSION,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).sourceElements(SourceElement.EXPRESSION).build();
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
            checkState(event, 3, true, "EXPRESSION");
        });
        expectDone();
    }
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).sourceElements(SourceElement.EXPRESSION).build();
        // Will be moved from line 2 to the expression at line 3.
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
            checkState(event, 3, true, "EXPRESSION");
        });
        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 39 with DebuggerSession

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

the class BreakpointTest method testBreakpointAfter.

@Test
public void testBreakpointAfter() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT(CONSTANT(10)))");
    Breakpoint breakpoint2 = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).suspendAnchor(SuspendAnchor.AFTER).build();
    Breakpoint breakpoint3a = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(SuspendAnchor.BEFORE).build();
    Breakpoint breakpoint3b = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(SuspendAnchor.AFTER).build();
    assertEquals(SuspendAnchor.AFTER, breakpoint2.getSuspendAnchor());
    try (DebuggerSession session = startSession()) {
        session.install(breakpoint2);
        session.install(breakpoint3a);
        session.install(breakpoint3b);
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint2, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
            assertEquals("Null", event.getReturnValue().as(String.class));
        });
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint3a, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.BEFORE, event.getSuspendAnchor());
            assertNull(event.getReturnValue());
        });
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint3b, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
            assertEquals("10", event.getReturnValue().as(String.class));
        });
    }
    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 40 with DebuggerSession

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

the class BreakpointTest method testNotStepIntoBreakpointCondition.

@Test
public void testNotStepIntoBreakpointCondition() {
    Source defineSource = testSource("ROOT(DEFINE(test, ROOT(\n" + "STATEMENT(EXPRESSION),\n" + "CONSTANT(true))))");
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        startEval(defineSource);
        expectDone();
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        breakpoint.setCondition("CALL(test)");
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(2, event.getSourceSection().getStartLine());
            assertEquals(0, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        assertEquals(0, breakpoint.getHitCount());
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(3, event.getSourceSection().getStartLine());
            assertEquals(1, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        assertEquals(1, breakpoint.getHitCount());
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(4, event.getSourceSection().getStartLine());
            assertEquals(0, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        expectDone();
        assertEquals(1, breakpoint.getHitCount());
    }
}
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)

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