Search in sources :

Example 36 with SuspendedEvent

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

Example 37 with SuspendedEvent

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

the class BreakpointTest method testBreakURI2.

@Test
public void testBreakURI2() throws Throwable {
    File testFile = testFile("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(testFile.toURI()).lineIs(4).build());
        session.suspendNextExecution();
        startEval(Source.newBuilder(InstrumentationTestLanguage.ID, testFile).build());
        for (int i = 0; i < 3; i++) {
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 4, true, "STATEMENT").prepareContinue();
            });
        }
        Assert.assertEquals(3, 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) File(java.io.File) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 38 with SuspendedEvent

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

the class BreakpointTest method testBreakpointConditionExecutedOnce.

@Test
public void testBreakpointConditionExecutedOnce() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        breakpoint.setCondition("ROOT(PRINT(OUT, Hi), CONSTANT(true))");
        // Breakpoint only:
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(1, breakpoint.getHitCount());
        expectDone();
        assertEquals("Hi", getOutput());
        // Breakpoint with step and an other breakpoint:
        Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(2, event.getBreakpoints().size());
            assertTrue(event.getBreakpoints().contains(breakpoint));
            assertTrue(event.getBreakpoints().contains(breakpoint2));
            assertNull(event.getBreakpointConditionException(breakpoint));
            assertNull(event.getBreakpointConditionException(breakpoint2));
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOver(1);
        });
        expectDone();
        assertEquals("HiHi", getOutput());
        assertEquals(2, breakpoint.getHitCount());
        assertEquals(1, breakpoint2.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 39 with SuspendedEvent

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

the class SLDebugTest method testDebugger.

@Test
public void testDebugger() throws Throwable {
    /*
         * Test AlwaysHalt is working.
         */
    final Source factorial = slCode("function main() {\n" + "  return fac(5);\n" + "}\n" + "function fac(n) {\n" + "  if (n <= 1) {\n" + // // break
    "    debugger; return 1;\n" + "  }\n" + "  return n * fac(n - 1);\n" + "}\n");
    try (DebuggerSession session = startSession()) {
        startEval(factorial);
        // make javac happy and use the session
        session.getBreakpoints();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 6, true, "debugger", "n", "1").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)

Example 40 with SuspendedEvent

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

the class SLDebugTest method testStack.

@Test
public void testStack() {
    final Source stackSource = slCode("function main() {\n" + "  return fac(10);\n" + "}\n" + "function fac(n) {\n" + "  if (n <= 1) {\n" + // break
    "    return 1;\n" + "  }\n" + "  return n * fac(n - 1);\n" + "}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(stackSource)).lineIs(6).build());
        startEval(stackSource);
        expectSuspended((SuspendedEvent event) -> {
            Iterator<DebugStackFrame> sfIt = event.getStackFrames().iterator();
            assertTrue(sfIt.hasNext());
            DebugStackFrame dsf = sfIt.next();
            assertEquals("fac", dsf.getName());
            assertEquals(6, dsf.getSourceSection().getStartLine());
            assertFalse(dsf.isInternal());
            int numStacksAt8 = 10 - 1;
            for (int i = 0; i < numStacksAt8; i++) {
                assertTrue(sfIt.hasNext());
                dsf = sfIt.next();
                assertEquals("fac", dsf.getName());
                assertEquals(8, dsf.getSourceSection().getStartLine());
                assertFalse(dsf.isInternal());
            }
            assertTrue(sfIt.hasNext());
            dsf = sfIt.next();
            assertEquals("main", dsf.getName());
            assertEquals(2, dsf.getSourceSection().getStartLine());
            assertFalse(dsf.isInternal());
            // skip internal frames
            while (sfIt.hasNext()) {
                dsf = sfIt.next();
                assertTrue(dsf.isInternal());
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) 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)

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