Search in sources :

Example 41 with DebuggerSession

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

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

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

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

Example 45 with DebuggerSession

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

the class SLDebugTest method testBreakpoint.

@Test
public void testBreakpoint() throws Throwable {
    /*
         * Wrappers need to remain inserted for recursive functions to work for debugging. Like in
         * this test case when the breakpoint is in the exit condition and we want to step out.
         */
    final Source factorial = slCode("function main() {\n" + "  return fac(5);\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()) {
        startEval(factorial);
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(factorial)).lineIs(6).build());
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 6, true, "return 1", "n", "1");
            checkArgs(event.getTopStackFrame(), "n", "1");
            Iterator<DebugStackFrame> sfi = event.getStackFrames().iterator();
            for (int i = 1; i <= 5; i++) {
                checkArgs(sfi.next(), "n", Integer.toString(i));
            }
            // main
            checkArgs(sfi.next());
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "2");
            checkArgs(event.getTopStackFrame(), "n", "2");
            assertEquals("1", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "3");
            assertEquals("2", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "4");
            assertEquals("6", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "5");
            assertEquals("24", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "main", 2, false, "fac(5)");
            checkArgs(event.getTopStackFrame());
            assertEquals("120", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        assertEquals("120", expectDone());
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) 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)

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