Search in sources :

Example 86 with SuspendedEvent

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

the class DebuggerSessionTest method testSuspendAll1.

@Test
public void testSuspendAll1() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        for (int i = 0; i < 10; i++) {
            suspendAll(session);
            startEval(testSource);
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 2, true, "STATEMENT").prepareContinue();
            });
            expectDone();
        }
    }
}
Also used : 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 87 with SuspendedEvent

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

the class DebuggerSessionTest method testClosing1.

@Test
public void testClosing1() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    DebuggerSession session = startSession();
    session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
    session.suspendNextExecution();
    startEval(testSource);
    expectSuspended((SuspendedEvent event) -> {
        checkState(event, 2, true, "STATEMENT").prepareStepOver(1);
    });
    // closing the session should disable breakpoints and current stepping
    session.close();
    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 88 with SuspendedEvent

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

the class DebuggerSessionTest method testSuspendThread1.

@Test
public void testSuspendThread1() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        // do suspend next for a few times
        for (int i = 0; i < 100; i++) {
            suspend(session, getEvalThread());
            startEval(testSource);
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 2, true, "STATEMENT").prepareContinue();
            });
            expectDone();
        }
    }
}
Also used : 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 89 with SuspendedEvent

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

the class DebuggerThreadsTest method testGetStartedThreads.

@Test
public void testGetStartedThreads() throws Exception {
    Engine engine = Engine.create();
    TestThreadsListener threadsListener = new TestThreadsListener();
    List<ThreadEvent> events = threadsListener.events;
    Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
    CountDownLatch latch = new CountDownLatch(1);
    DebuggerSession[] sessionPtr = new DebuggerSession[1];
    try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {

        @Override
        public void onSuspend(SuspendedEvent event) {
            latch.countDown();
            sessionPtr[0].setThreadsListener(threadsListener, true);
            assertEquals(events.toString(), 2, events.size());
            assertTrue(events.get(0).isNew);
            assertNotNull(events.get(0).context);
            assertTrue(events.get(1).isNew);
            assertEquals(events.get(0).context, events.get(1).context);
            assertNotEquals(events.get(0).thread, events.get(1).thread);
        }
    })) {
        session.suspendNextExecution();
        sessionPtr[0] = session;
        try (Context context = Context.newBuilder().engine(engine).allowCreateThread(true).build()) {
            Source source = testSource("ROOT(DEFINE(f1, EXPRESSION), SPAWN(f1), JOIN())");
            context.eval(source);
            source = testSource("ROOT(DEFINE(foo, STATEMENT), SPAWN(foo))");
            context.eval(source);
            latch.await();
            context.eval(testSource("JOIN()"));
            assertEquals(events.toString(), 3, events.size());
            assertFalse(events.get(2).isNew);
            assertTrue(events.get(0).thread == events.get(2).thread || events.get(1).thread == events.get(2).thread);
        }
        assertEquals(4, events.size());
    }
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Source(org.graalvm.polyglot.Source) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) Engine(org.graalvm.polyglot.Engine) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 90 with SuspendedEvent

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

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