Search in sources :

Example 21 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebugStackFrameTest method testSourceSections.

@Test
public void testSourceSections() {
    final Source source = testSource("ROOT(DEFINE(a,ROOT(\n" + "  STATEMENT())\n" + "),\n" + "DEFINE(b,ROOT(\n" + "  CALL(a))\n" + "), \n" + "CALL(b))\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            SourceSection ss = frame.getSourceSection();
            assertSection(ss, "STATEMENT()", 2, 3, 2, 13);
            SourceSection fss = getFunctionSourceSection(frame);
            assertSection(fss, "ROOT(\n  STATEMENT())\n", 1, 15, 2, 15);
            Iterator<DebugStackFrame> stackFrames = event.getStackFrames().iterator();
            // The top one
            assertEquals(frame, stackFrames.next());
            // b
            frame = stackFrames.next();
            ss = frame.getSourceSection();
            assertSection(ss, "CALL(a)", 5, 3, 5, 9);
            fss = getFunctionSourceSection(frame);
            assertSection(fss, "ROOT(\n  CALL(a))\n", 4, 10, 5, 11);
            // root
            frame = stackFrames.next();
            ss = frame.getSourceSection();
            assertSection(ss, "CALL(b)", 7, 1, 7, 7);
            fss = getFunctionSourceSection(frame);
            assertSection(fss, source.getCharacters().toString(), 1, 1, 7, 9);
            assertFalse(stackFrames.hasNext());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 22 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerContextsTest method testMultipleContexts.

@Test
public void testMultipleContexts() {
    Source source = Source.create(InstrumentationTestLanguage.ID, "STATEMENT()");
    Engine engine = Engine.create();
    TestContextsListener contextsListener = new TestContextsListener();
    List<ContextEvent> events = contextsListener.events;
    int numContexts = 5;
    Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
    try (DebuggerSession session = debugger.startSession(null)) {
        session.setContextsListener(contextsListener, false);
        for (int i = 0; i < numContexts; i++) {
            try (Context context = Context.newBuilder().engine(engine).build()) {
                assertEquals(6 * i + 1, events.size());
                context.eval(source);
            }
            assertEquals(6 * i + 6, events.size());
        }
        assertEquals(6 * numContexts, events.size());
        DebugContext lastContext = null;
        for (int i = 0; i < numContexts; i++) {
            int ci = 6 * i;
            assertTrue(events.get(ci).created);
            assertNull(events.get(ci).language);
            assertNotEquals(lastContext, events.get(ci).context);
            lastContext = events.get(ci).context;
            assertTrue(events.get(ci + 1).created);
            assertNotNull(events.get(ci + 1).language);
            assertEquals(lastContext, events.get(ci + 1).context);
            assertTrue(events.get(ci + 2).languageInitialized);
            assertTrue(events.get(ci + 3).languageFinalized);
            assertNotNull(events.get(ci + 4).language);
            assertNull(events.get(ci + 5).language);
        }
        engine.close();
    }
    // No more events
    assertEquals(6 * numContexts, events.size());
}
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) DebugContext(com.oracle.truffle.api.debug.DebugContext) Source(org.graalvm.polyglot.Source) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 23 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerSessionTest method testResumeAll4.

@Test
public void testResumeAll4() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        for (int i = 0; i < 10; i++) {
            session.suspendNextExecution();
            startEval(testSource);
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 2, true, "STATEMENT").prepareStepOver(1);
            });
            // test that resume does not affect current stepping behavior
            session.resumeAll();
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 3, true, "STATEMENT").prepareStepOver(1);
            });
            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 24 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerSessionTest method testSuspendNextExecution3.

@Test
public void testSuspendNextExecution3() {
    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++) {
            session.suspendNextExecution();
            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 25 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerSessionTest method testSuspendNextExecution4.

@Test
public void testSuspendNextExecution4() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareContinue();
            // use suspend next in an event
            event.getSession().suspendNextExecution();
        });
        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

Source (org.graalvm.polyglot.Source)196 Test (org.junit.Test)165 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)103 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)95 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)51 Value (org.graalvm.polyglot.Value)31 Context (org.graalvm.polyglot.Context)25 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)21 DebugValue (com.oracle.truffle.api.debug.DebugValue)20 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)14 Instrument (org.graalvm.polyglot.Instrument)14 Debugger (com.oracle.truffle.api.debug.Debugger)13 SourceSection (com.oracle.truffle.api.source.SourceSection)12 EventContext (com.oracle.truffle.api.instrumentation.EventContext)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Engine (org.graalvm.polyglot.Engine)9 ArrayList (java.util.ArrayList)8 PolyglotException (org.graalvm.polyglot.PolyglotException)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)7