Search in sources :

Example 91 with SuspendedEvent

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

the class BreakpointTest method testBreakAtMultipleSourceElements.

@Test
public void testBreakAtMultipleSourceElements() {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,EXPRESSION,\n" + "  EXPRESSION,STATEMENT,\n" + "  STATEMENT,EXPRESSION\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).sourceElements(SourceElement.STATEMENT, SourceElement.EXPRESSION).build();
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
            checkState(event, 3, true, "EXPRESSION");
        });
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
            checkState(event, 3, true, "STATEMENT");
        });
        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 92 with SuspendedEvent

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

the class BreakpointTest method testBreakpointResolve.

@Test
public void testBreakpointResolve() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    Breakpoint breakpoint2 = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build();
    assertFalse(breakpoint2.isResolved());
    Breakpoint breakpoint3 = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build();
    assertFalse(breakpoint3.isResolved());
    try (DebuggerSession session = startSession()) {
        session.install(breakpoint2);
        assertFalse(breakpoint2.isResolved());
        assertFalse(breakpoint3.isResolved());
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint2, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.BEFORE, event.getSuspendAnchor());
        });
        assertTrue(breakpoint2.isResolved());
        expectDone();
        assertTrue(breakpoint2.isResolved());
        assertFalse(breakpoint3.isResolved());
        // breakpoint3 should be resolved by just installing it
        session.install(breakpoint3);
        assertTrue(breakpoint2.isResolved());
        assertTrue(breakpoint3.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 93 with SuspendedEvent

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

the class BreakpointTest method testBreakURI1.

@Test
public void testBreakURI1() 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(source.getURI()).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 94 with SuspendedEvent

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

the class BreakpointTest method testGlobalBreakpoints.

@Test
// auto-closeable resource session is never referenced in body of
@SuppressWarnings("try")
public // corresponding try statement
void testGlobalBreakpoints() 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" + ")\n");
    Debugger debugger = getDebugger();
    assertTrue(debugger.getBreakpoints().isEmpty());
    Breakpoint globalBreakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
    boolean[] notified = new boolean[] { false };
    BreakpointListener newBPListener = BreakpointListener.register(notified, debugger, globalBreakpoint);
    debugger.install(globalBreakpoint);
    Assert.assertTrue(notified[0]);
    Assert.assertEquals(1, debugger.getBreakpoints().size());
    Breakpoint newBP = debugger.getBreakpoints().get(0);
    Assert.assertTrue(globalBreakpoint.isModifiable());
    Assert.assertFalse(newBP.isModifiable());
    try {
        newBP.dispose();
        Assert.fail("Public dispose must not be possible for global breakpoints.");
    } catch (IllegalStateException ex) {
    // O.K.
    }
    try {
        newBP.setCondition("Something");
        Assert.fail();
    } catch (IllegalStateException ex) {
    // O.K.
    }
    try {
        newBP.setCondition(null);
        Assert.fail();
    } catch (IllegalStateException ex) {
    // O.K.
    }
    try {
        newBP.setEnabled(false);
        Assert.fail();
    } catch (IllegalStateException ex) {
    // O.K.
    }
    try {
        newBP.setIgnoreCount(10);
        Assert.fail();
    } catch (IllegalStateException ex) {
    // O.K.
    }
    Assert.assertNull(newBP.getCondition());
    Assert.assertEquals(0, newBP.getHitCount());
    Assert.assertTrue(newBP.isEnabled());
    Assert.assertFalse(newBP.isDisposed());
    Assert.assertFalse(newBP.isResolved());
    try (DebuggerSession session = startSession()) {
        // global breakpoint is not among session breakpoints
        Assert.assertTrue(session.getBreakpoints().isEmpty());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            Breakpoint eventBP = event.getBreakpoints().get(0);
            try {
                eventBP.dispose();
                Assert.fail("Public dispose must not be possible for global breakpoints.");
            } catch (IllegalStateException ex) {
            // O.K.
            }
            Assert.assertTrue(eventBP.isResolved());
            event.prepareContinue();
        });
    }
    assertFalse(newBP.isDisposed());
    assertFalse(newBP.isResolved());
    expectDone();
    try (DebuggerSession session = startSession()) {
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            event.prepareContinue();
        });
    }
    expectDone();
    newBPListener.unregister();
    notified[0] = false;
    BreakpointDisposeListener.register(notified, debugger, globalBreakpoint);
    globalBreakpoint.dispose();
    Assert.assertTrue(notified[0]);
    Assert.assertEquals(0, debugger.getBreakpoints().size());
}
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 95 with SuspendedEvent

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

the class BreakpointTest method testChangeDuringSuspension.

@Test
public void testChangeDuringSuspension() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    STATEMENT\n" + "  ),\n" + "  STATEMENT,\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT");
            Assert.assertEquals(0, event.getBreakpoints().size());
            session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
            event.prepareContinue();
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT");
            event.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)

Aggregations

SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)100 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)97 Source (org.graalvm.polyglot.Source)95 Test (org.junit.Test)93 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)45 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)19 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 Debugger (com.oracle.truffle.api.debug.Debugger)11 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)9 Context (org.graalvm.polyglot.Context)9 SourceSection (com.oracle.truffle.api.source.SourceSection)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 DebugScope (com.oracle.truffle.api.debug.DebugScope)5 HashMap (java.util.HashMap)3 DebugContext (com.oracle.truffle.api.debug.DebugContext)2 Map (java.util.Map)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2