Search in sources :

Example 31 with Breakpoint

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

the class BreakpointTest method testDisableBreakpointsDuringSuspend.

@Test
public void testDisableBreakpointsDuringSuspend() throws Throwable {
    Source source = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint1 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        startEval(source);
        for (int i = 0; i < 3; i++) {
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 4, true, "STATEMENT").prepareContinue();
            });
            if (i == 0) {
                breakpoint3.dispose();
            }
            if (i == 1) {
                breakpoint1.dispose();
            }
        }
        Assert.assertEquals(2, breakpoint1.getHitCount());
        Assert.assertEquals(3, breakpoint2.getHitCount());
        Assert.assertEquals(1, breakpoint3.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) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 32 with Breakpoint

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

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

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

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

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