Search in sources :

Example 86 with DebuggerSession

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

the class DebuggerContextsTest method testGetActiveContexts.

@Test
public void testGetActiveContexts() {
    final DebuggerSession[] sessionPtr = new DebuggerSession[1];
    try (Engine engine = Engine.create()) {
        TestContextsListener contextsListener = new TestContextsListener();
        List<ContextEvent> events = contextsListener.events;
        Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
        try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {

            @Override
            public void onSuspend(SuspendedEvent event) {
                sessionPtr[0].setContextsListener(contextsListener, true);
                assertEquals(3, events.size());
                assertTrue(events.get(0).created);
                assertNull(events.get(0).language);
                assertTrue(events.get(1).created);
                assertEquals(InstrumentationTestLanguage.ID, events.get(1).language.getId());
                assertTrue(events.get(2).languageInitialized);
            }
        })) {
            session.setContextsListener(contextsListener, true);
            try (Context context = Context.newBuilder().engine(engine).build()) {
                context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
                assertEquals(3, events.size());
                // Have creation of polyglot context and a language
                assertTrue(events.get(0).created);
                assertNotNull(events.get(0).context);
                assertNull(events.get(0).language);
                assertTrue(events.get(1).created);
                assertNotNull(events.get(1).language);
                assertTrue(events.get(2).languageInitialized);
            }
            assertEquals(6, events.size());
            session.setContextsListener(null, true);
            events.clear();
            // Contexts created and closed:
            try (Context context = Context.newBuilder().engine(engine).build()) {
                context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
                context.eval(Source.create(InstrumentationTestLanguage.ID, "CONTEXT(STATEMENT())"));
            }
            assertEquals(0, events.size());
            sessionPtr[0] = session;
            session.suspendNextExecution();
            Context context = Context.newBuilder().engine(engine).build();
            context.eval(Source.create(InstrumentationTestLanguage.ID, "ROOT(CONTEXT(EXPRESSION()), CONTEXT(STATEMENT))"));
        }
    }
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Engine(org.graalvm.polyglot.Engine) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 87 with DebuggerSession

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

the class DebuggerSessionTest method testClosing2.

@Test
public void testClosing2() throws Exception {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    Context context = Context.create();
    final AtomicBoolean suspend = new AtomicBoolean();
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    DebuggerSession session = debugger.startSession(new SuspendedCallback() {

        public void onSuspend(SuspendedEvent event) {
            suspend.set(true);
        }
    });
    context.eval(testSource);
    context.close();
    // if the engine disposes the session should still work
    session.suspendNextExecution();
    suspend(session, Thread.currentThread());
    suspendAll(session);
    session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
    resume(session, Thread.currentThread());
    session.resumeAll();
    session.getDebugger();
    session.getBreakpoints();
    // after closing the session none of these methods should work
    session.close();
    try {
        session.suspendNextExecution();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        suspend(session, Thread.currentThread());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        suspendAll(session);
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        resume(session, Thread.currentThread());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.resumeAll();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.getBreakpoints();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    // still works after closing
    session.getDebugger();
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 88 with DebuggerSession

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

the class DebuggerSessionTest method testSuspendAll2.

@Test
public void testSuspendAll2() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        suspendAll(session);
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        // prepareContinue should be ignored here as suspenions counts higher
        suspendAll(session);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, 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) Test(org.junit.Test)

Example 89 with DebuggerSession

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

the class DebuggerSessionTest method testSuspendAll3.

@Test
public void testSuspendAll3() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        suspendAll(session);
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareKill();
        });
        // For prepareKill additional suspensions should be ignored
        suspendAll(session);
        expectKilled();
    }
}
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 90 with DebuggerSession

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

the class DebuggerSessionTest method testSuspendThread2.

@Test
public void testSuspendThread2() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        suspend(session, getEvalThread());
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        // prepareContinue should be ignored here as suspensions counts more
        suspend(session, getEvalThread());
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, 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) 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