Search in sources :

Example 96 with DebuggerSession

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

the class DebuggerSessionTest method testResumeAll3.

@Test
public void testResumeAll3() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        for (int i = 0; i < 10; i++) {
            suspend(session, getEvalThread());
            session.resumeAll();
            startEval(testSource);
            expectDone();
        }
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) Source(org.graalvm.polyglot.Source) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 97 with DebuggerSession

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

the class DebuggerThreadsTest method testSpawnThreads.

@Test
public void testSpawnThreads() {
    int numThreads = 10;
    final Source source = testSource("ROOT(DEFINE(foo, STATEMENT), LOOP(" + numThreads + ", SPAWN(foo)), JOIN())");
    TestThreadsListener threadsListener = new TestThreadsListener();
    List<ThreadEvent> events = threadsListener.events;
    try (DebuggerSession session = startSession()) {
        session.setThreadsListener(threadsListener, false);
        startEval(source);
        expectDone();
    }
    assertEquals(1 + 2 * numThreads, events.size());
    List<ThreadEvent> startEvents = new ArrayList<>(1 + numThreads);
    for (ThreadEvent event : events) {
        if (event.isNew) {
            startEvents.add(event);
        }
    }
    assertEquals(1 + numThreads, startEvents.size());
    DebugContext dcontext = events.get(0).context;
    for (ThreadEvent event : events) {
        assertEquals(dcontext, event.context);
    }
    events.clear();
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) ArrayList(java.util.ArrayList) DebugContext(com.oracle.truffle.api.debug.DebugContext) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 98 with DebuggerSession

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

the class DebuggerThreadsTest method testContextThreads.

@Test
public void testContextThreads() throws Exception {
    Engine engine = Engine.create();
    final Source source = testSource("STATEMENT()");
    TestThreadsListener threadsListener = new TestThreadsListener();
    List<ThreadEvent> events = threadsListener.events;
    int numThreads = 10;
    Thread[] threads = new Thread[numThreads];
    Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
    try (DebuggerSession session = debugger.startSession(null)) {
        session.setThreadsListener(threadsListener, false);
        for (int i = 0; i < numThreads; i++) {
            threads[i] = new Thread() {

                @Override
                public void run() {
                    try (Context context = Context.newBuilder().engine(engine).build()) {
                        context.eval(source);
                    }
                }
            };
        }
        for (int i = 0; i < numThreads; i++) {
            threads[i].start();
        }
        for (int i = 0; i < numThreads; i++) {
            threads[i].join();
        }
    }
    assertEquals(2 * numThreads, events.size());
    List<ThreadEvent> startEvents = new ArrayList<>(numThreads);
    for (ThreadEvent event : events) {
        if (event.isNew) {
            startEvents.add(event);
        }
    }
    assertEquals(numThreads, startEvents.size());
    // Verify that we got all threads in the events:
    Set<Thread> allThreads = new HashSet<>(Arrays.asList(threads));
    for (int i = 0; i < numThreads; i++) {
        assertTrue(allThreads.remove(startEvents.get(i).thread));
    }
    assertTrue(allThreads.toString(), allThreads.isEmpty());
    // Verify that we got 'numThreads' number of contexts:
    Set<DebugContext> distinctContexts = new HashSet<>();
    for (ThreadEvent event : events) {
        distinctContexts.add(event.context);
    }
    assertEquals(numThreads, distinctContexts.size());
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) ArrayList(java.util.ArrayList) DebugContext(com.oracle.truffle.api.debug.DebugContext) Source(org.graalvm.polyglot.Source) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) Engine(org.graalvm.polyglot.Engine) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 99 with DebuggerSession

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

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

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