Search in sources :

Example 16 with SuspendedEvent

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

the class ValueLanguageTest method testValueLanguage.

@Test
public void testValueLanguage() {
    Source source1 = Source.create(ValuesLanguage1.ID, "i=10\n" + "s=test\n" + "a=null\n" + "b={}\n" + "b.a={}\n" + "b.j=100\n" + "b.k=200\n");
    Source source2 = Source.create(ValuesLanguage2.ID, "j=20\n" + "s=test2\n" + "d=null\n" + "e={}\n" + "b.c={}\n" + "e.d={}\n" + "e.k=200\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint bp1 = Breakpoint.newBuilder(getSourceImpl(source1)).lineIs(7).build();
        session.install(bp1);
        startEval(source1);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value = frame.getScope().getDeclaredValue("i");
            assertNull(value.getOriginalLanguage());
            assertEquals("L1:10", value.as(String.class));
            value = frame.getScope().getDeclaredValue("s");
            assertNull(value.getOriginalLanguage());
            assertEquals("L1:test", value.as(String.class));
            value = frame.getScope().getDeclaredValue("a");
            assertNull(value.getOriginalLanguage());
            assertEquals("null", value.as(String.class));
            value = frame.getScope().getDeclaredValue("b");
            LanguageInfo lang = value.getOriginalLanguage();
            assertNotNull(lang);
            assertEquals(ValuesLanguage1.NAME, lang.getName());
            assertEquals("{a={}, j=100}", value.as(String.class));
            event.prepareContinue();
        });
        expectDone();
        Breakpoint bp2 = Breakpoint.newBuilder(getSourceImpl(source2)).lineIs(7).build();
        session.install(bp2);
        startEval(source2);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value = frame.getScope().getDeclaredValue("j");
            assertNull(value.getOriginalLanguage());
            assertEquals("L2:20", value.as(String.class));
            value = frame.getScope().getDeclaredValue("s");
            assertNull(value.getOriginalLanguage());
            assertEquals("L2:test2", value.as(String.class));
            value = frame.getScope().getDeclaredValue("e");
            LanguageInfo lang2 = value.getOriginalLanguage();
            assertNotNull(lang2);
            assertEquals(ValuesLanguage2.NAME, lang2.getName());
            assertEquals("{d={}}", value.as(String.class));
            value = frame.getScope().getDeclaredValue("b");
            LanguageInfo lang1 = value.getOriginalLanguage();
            assertNotNull(lang1);
            assertNotEquals(lang1, lang2);
            assertEquals(ValuesLanguage1.NAME, lang1.getName());
            // info from current lang2:
            assertEquals("Object", value.as(String.class));
            assertEquals("L2:Object", value.getMetaObject().as(String.class));
            // info from original lang1:
            value = value.asInLanguage(lang1);
            assertEquals("{a={}, j=100, k=200, c={}}", value.as(String.class));
            assertEquals("L1:Map", value.getMetaObject().as(String.class));
            assertEquals("L2:Map", value.getMetaObject().asInLanguage(lang2).as(String.class));
            // Properties are always in the original language:
            value = frame.getScope().getDeclaredValue("b");
            DebugValue a = value.getProperties().iterator().next();
            assertEquals(lang1, a.getOriginalLanguage());
            Iterator<DebugValue> it = value.getProperties().iterator();
            it.next();
            it.next();
            it.next();
            DebugValue c = it.next();
            assertEquals(lang2, c.getOriginalLanguage());
            value = value.asInLanguage(lang2);
            a = value.getProperties().iterator().next();
            assertEquals(lang1, a.getOriginalLanguage());
            it = value.getProperties().iterator();
            it.next();
            it.next();
            it.next();
            c = it.next();
            assertEquals(lang2, c.getOriginalLanguage());
            value = frame.getScope().getDeclaredValue("j");
            assertNull(value.getSourceLocation());
            value = value.asInLanguage(lang1);
            assertEquals("L1:20", value.as(String.class));
            assertNull(value.getSourceLocation());
            value = frame.getScope().getDeclaredValue("d");
            assertEquals("null", value.as(String.class));
            value = value.asInLanguage(lang1);
            assertEquals("null", value.as(String.class));
            value = frame.getScope().getDeclaredValue("e");
            assertEquals(getSourceImpl(source2).createSection(4, 3, 2), value.getSourceLocation());
            value = value.asInLanguage(lang1);
            assertNull(value.getSourceLocation());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 17 with SuspendedEvent

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

the class DebugScopeTest method testTopScope.

// Local scopes are well tested by DebugStackFrameTest and others.
@Test
public void testTopScope() {
    final Source source = testSource("ROOT(DEFINE(function1,ROOT(\n" + "  EXPRESSION()\n" + "  )\n" + "),\n" + "DEFINE(g,ROOT(\n" + "  EXPRESSION()\n" + "  )\n" + "),\n" + "STATEMENT())\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugScope topScope = session.getTopScope(event.getSourceSection().getSource().getLanguage());
            assertNotNull(topScope);
            DebugValue function1 = topScope.getDeclaredValue("function1");
            assertNotNull(function1);
            assertTrue(function1.as(String.class).contains("Function"));
            DebugValue functionType = function1.getMetaObject();
            assertEquals("Function", functionType.as(String.class));
            assertEquals(function1.getOriginalLanguage(), functionType.getOriginalLanguage());
            DebugValue g = topScope.getDeclaredValue("g");
            assertNotNull(g);
            assertTrue(g.as(String.class).contains("Function"));
        });
        expectDone();
    }
}
Also used : DebugScope(com.oracle.truffle.api.debug.DebugScope) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 18 with SuspendedEvent

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

the class DebugStackFrameTest method testEvalAndSideEffects.

@Test
public void testEvalAndSideEffects() throws Throwable {
    final Source source = testSource("ROOT(DEFINE(a,ROOT( \n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(b, 43), \n" + "  VARIABLE(c, 44), \n" + // will start stepping here
    "  STATEMENT(),\n" + "  STATEMENT())\n" + "), \n" + "VARIABLE(a, 42), VARIABLE(b, 43), VARIABLE(c, 44), \n" + "CALL(a))\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Iterator<DebugStackFrame> stackFrames = event.getStackFrames().iterator();
            // assert changes to the current frame
            DebugStackFrame frame = stackFrames.next();
            assertDynamicFrame(frame);
            DebugValue aValue = frame.getScope().getDeclaredValue("a");
            String aStringValue = aValue.as(String.class);
            // assert changes to a parent frame
            frame = stackFrames.next();
            assertDynamicFrame(frame);
            // assign from one stack frame to another one
            frame.getScope().getDeclaredValue("a").set(aValue);
            assertEquals(aStringValue, frame.getScope().getDeclaredValue("a").as(String.class));
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 19 with SuspendedEvent

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

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

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