Search in sources :

Example 31 with DebuggerSession

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

the class DoubleHaltTest method testCallLoopStepInto.

@Test
public void testCallLoopStepInto() throws Throwable {
    Source testSource = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(4).build());
        session.suspendNextExecution();
        startEval(testSource);
        for (int i = 0; i < 3; i++) {
            final int modI = i % 3;
            expectSuspended((SuspendedEvent event) -> {
                SuspendedEvent e = checkState(event, 4, true, "STATEMENT");
                assertEquals(1, e.getBreakpoints().size());
                assertSame(breakpoint4, e.getBreakpoints().iterator().next());
                switch(modI) {
                    case 0:
                        /*
                             * Note Chumer: breakpoints should always hit independent if we are
                             * currently stepping out or not. thats why step out does not step out
                             * here.
                             */
                        e.prepareStepOut(1);
                        break;
                    case 1:
                        e.prepareStepInto(1);
                        break;
                    case 2:
                        e.prepareStepOver(1);
                        break;
                }
            });
        }
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, false, "CALL(foo)");
        });
        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) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 32 with DebuggerSession

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

the class DoubleHaltTest method testBreakpointStepping.

@Test
public void testBreakpointStepping() throws Throwable {
    Source testSource = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
        Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(5).build());
        Breakpoint breakpoint6 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(6).build());
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint2, event.getBreakpoints().iterator().next());
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint3, event.getBreakpoints().iterator().next());
            event.prepareStepOver(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint5, event.getBreakpoints().iterator().next());
            event.prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint6, event.getBreakpoints().iterator().next());
            event.prepareContinue();
        });
        expectDone();
        assertEquals(1, breakpoint2.getHitCount());
        assertEquals(1, breakpoint3.getHitCount());
        assertEquals(1, breakpoint5.getHitCount());
        assertEquals(1, breakpoint6.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 33 with DebuggerSession

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

the class BreakpointTest method testGlobalBreakpointsInMultipleSessions.

@Test
public void testGlobalBreakpointsInMultipleSessions() throws Throwable {
    try {
        Class.forName("java.beans.PropertyChangeListener");
    } catch (ClassNotFoundException ex) {
        // skip the test if running only with java.base JDK9 module
        return;
    }
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    Debugger debugger = getDebugger();
    Breakpoint globalBreakpoint1 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
    debugger.install(globalBreakpoint1);
    Breakpoint globalBreakpoint2 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build();
    debugger.install(globalBreakpoint2);
    Breakpoint globalBreakpoint3 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build();
    debugger.install(globalBreakpoint3);
    Breakpoint globalBreakpoint4 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(8).build();
    debugger.install(globalBreakpoint4);
    // Breakpoints are in the install order:
    List<Breakpoint> breakpoints = debugger.getBreakpoints();
    Assert.assertEquals(4, breakpoints.size());
    Assert.assertTrue(breakpoints.get(0).getLocationDescription().contains("line=2"));
    Assert.assertTrue(breakpoints.get(1).getLocationDescription().contains("line=4"));
    Assert.assertTrue(breakpoints.get(2).getLocationDescription().contains("line=6"));
    DebuggerSession session1 = startSession();
    // global breakpoints are not among session breakpoints
    Assert.assertTrue(session1.getBreakpoints().isEmpty());
    try (DebuggerSession session2 = startSession()) {
        // global breakpoints are not among session breakpoints
        Assert.assertTrue(session2.getBreakpoints().isEmpty());
        startEval(source);
        // Both sessions should break here:
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session1, event.getSession());
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session2, event.getSession());
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        // We close session2 after the next BP:
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session1, event.getSession());
            checkState(event, 4, true, "STATEMENT");
        });
    }
    expectSuspended((SuspendedEvent event) -> {
        assertNotSame(session1, event.getSession());
        checkState(event, 4, true, "STATEMENT").prepareContinue();
    });
    // The last breakpoint is hit once only in the session1:
    expectSuspended((SuspendedEvent event) -> {
        assertSame(session1, event.getSession());
        checkState(event, 6, true, "STATEMENT").prepareStepOver(1);
    });
    expectSuspended((SuspendedEvent event) -> {
        assertSame(session1, event.getSession());
        checkState(event, 7, true, "STATEMENT");
        session1.close();
        event.prepareContinue();
    });
    // Breakpoint at line 8 was not hit at all, the session was closed right before continue
    // from line 7.
    expectDone();
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) 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 34 with DebuggerSession

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

the class BreakpointTest method testBreakSource.

@Test
public void testBreakSource() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + // break here
    "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    Breakpoint sessionBreakpoint = null;
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        sessionBreakpoint = breakpoint;
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT");
            Assert.assertEquals(1, event.getBreakpoints().size());
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
        });
        Assert.assertEquals(1, breakpoint.getHitCount());
        Assert.assertEquals(true, breakpoint.isEnabled());
        Assert.assertEquals(true, breakpoint.isResolved());
        expectDone();
    }
    Assert.assertEquals(false, sessionBreakpoint.isResolved());
}
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 35 with DebuggerSession

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

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