Search in sources :

Example 11 with Breakpoint

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

the class BreakpointTest method testBreakpointsAtSamePlaceHitCorrectly.

@Test
public void testBreakpointsAtSamePlaceHitCorrectly() {
    Source testSource = testSource("ROOT(\n" + "  LOOP(4,\n" + "    STATEMENT\n" + "  )\n" + ")\n");
    String conditionTrue = "ROOT(PRINT(OUT, CT), CONSTANT(true))";
    String conditionFalse = "ROOT(PRINT(OUT, CF), CONSTANT(false))";
    boolean isBefore = true;
    String prefix = "";
    do {
        SuspendAnchor anchor = isBefore ? SuspendAnchor.BEFORE : SuspendAnchor.AFTER;
        try (DebuggerSession session = startSession()) {
            Breakpoint breakpoint1 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(anchor).build());
            Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(anchor).build());
            breakpoint1.setCondition(conditionFalse);
            breakpoint2.setCondition(conditionTrue);
            startEval(testSource);
            final String out1 = prefix + ((isBefore) ? "CFCT" : "CTCF");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint2, hit);
                assertEquals(out1, getOutput());
            });
            final String out2 = out1 + ((isBefore) ? "CFCT" : "CTCF");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint2, hit);
                breakpoint1.setCondition(conditionTrue);
                breakpoint2.setCondition(conditionFalse);
                assertEquals(out2, getOutput());
            });
            final String out3 = out2 + ((isBefore) ? "CTCF" : "CFCT");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint1, hit);
                breakpoint1.setCondition(null);
                breakpoint2.setCondition(null);
                assertEquals(out3, getOutput());
            });
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(2, event.getBreakpoints().size());
            });
            expectDone();
            prefix += out3;
            assertEquals(out3, getOutput());
            assertEquals(2, breakpoint1.getHitCount());
            assertEquals(3, breakpoint2.getHitCount());
        }
    } while (!(isBefore = !isBefore));
}
Also used : SuspendAnchor(com.oracle.truffle.api.debug.SuspendAnchor) 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 12 with Breakpoint

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

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

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

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

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)44 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)36 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)36 Source (org.graalvm.polyglot.Source)35 Test (org.junit.Test)33 SourceSection (com.oracle.truffle.api.source.SourceSection)7 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)4 Debugger (com.oracle.truffle.api.debug.Debugger)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Pattern (java.util.regex.Pattern)3 DebugValue (com.oracle.truffle.api.debug.DebugValue)2 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)2 LoadScriptListener (com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)2 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)2 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 Location (com.oracle.truffle.tools.chromeinspector.types.Location)2 Script (com.oracle.truffle.tools.chromeinspector.types.Script)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2