Search in sources :

Example 1 with DebugStackFrame

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

the class ReenterStackFrameTest method testReenterDeep.

@Test
public void testReenterDeep() throws Throwable {
    final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + " STATEMENT(),\n" + " DEFINE(aa, ROOT(\n" + "  STATEMENT(EXPRESSION),\n" + "  DEFINE(aaa, ROOT(\n" + "   STATEMENT(EXPRESSION, EXPRESSION))\n" + "  ),\n" + "  CALL(aaa))\n" + " ),\n" + " CALL(aa))\n" + "), \n" + "CALL(a))\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        final Exception[] exception = new Exception[1];
        final int[] suspendHits = new int[1];
        final int[] firstStatementNumJavaFrames = new int[1];
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
                event.prepareStepInto(2);
                suspendHits[0]++;
                firstStatementNumJavaFrames[0] = Thread.currentThread().getStackTrace().length;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT(EXPRESSION, EXPRESSION)", currentFrame.getSourceSection().getCharacters());
                Iterator<DebugStackFrame> sfIter = event.getStackFrames().iterator();
                // the top one (aaa)
                sfIter.next();
                // the second one (aa)
                event.prepareUnwindFrame(sfIter.next());
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("CALL(aa)", currentFrame.getSourceSection().getCharacters());
                // "a"
                event.prepareUnwindFrame(event.getStackFrames().iterator().next());
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
                event.prepareStepInto(2);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT(EXPRESSION)", currentFrame.getSourceSection().getCharacters());
                event.prepareStepInto(1);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT(EXPRESSION, EXPRESSION)", currentFrame.getSourceSection().getCharacters());
                Iterator<DebugStackFrame> sfIter = event.getStackFrames().iterator();
                // the top one (aaa)
                sfIter.next();
                // the second one (aa)
                sfIter.next();
                // the third one (a)
                event.prepareUnwindFrame(sfIter.next());
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
                event.prepareStepInto(1);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
                Assert.assertEquals("Same Java depth", firstStatementNumJavaFrames[0], Thread.currentThread().getStackTrace().length);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectDone();
        if (exception[0] != null) {
            throw exception[0];
        }
        Assert.assertEquals(8, suspendHits[0]);
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 2 with DebugStackFrame

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

the class ReenterStackFrameTest method testVariables.

@Test
public void testVariables() throws Throwable {
    // Test that after a re-enter, variables are cleared.
    final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + "  STATEMENT(),\n" + "  VARIABLE(x, 42),\n" + "  VARIABLE(n, 100),\n" + "  VARIABLE(m, 200),\n" + "  STATEMENT()\n" + ")),\n" + "CALL(a))\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        final Exception[] exception = new Exception[1];
        final int[] suspendHits = new int[1];
        final int numRepeats = 5;
        for (int i = numRepeats - 1; i >= 0; i--) {
            expectSuspended((SuspendedEvent event) -> {
                DebugStackFrame currentFrame = event.getTopStackFrame();
                try {
                    Assert.assertEquals("STATEMENT()", event.getSourceSection().getCharacters());
                    Assert.assertEquals(2, event.getSourceSection().getStartLine());
                    checkStack(currentFrame);
                    event.prepareStepOver(1);
                    suspendHits[0]++;
                } catch (Exception ex) {
                    exception[0] = ex;
                }
            });
            final boolean doUnwind = i > 0;
            expectSuspended((SuspendedEvent event) -> {
                DebugStackFrame currentFrame = event.getTopStackFrame();
                try {
                    Assert.assertEquals("STATEMENT()", event.getSourceSection().getCharacters());
                    Assert.assertEquals(6, event.getSourceSection().getStartLine());
                    checkStack(currentFrame, "n", "100", "m", "200", "x", "42");
                    if (doUnwind) {
                        event.prepareUnwindFrame(currentFrame);
                    }
                    suspendHits[0]++;
                } catch (Exception ex) {
                    exception[0] = ex;
                }
            });
            if (exception[0] != null) {
                throw exception[0];
            }
            if (!doUnwind) {
                break;
            }
            expectSuspended((SuspendedEvent event) -> {
                DebugStackFrame currentFrame = event.getTopStackFrame();
                try {
                    Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
                    Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
                    Assert.assertEquals("", frames.next().getName());
                    Assert.assertFalse(frames.hasNext());
                    checkStack(currentFrame);
                    // Enter into "a"
                    event.prepareStepInto(1);
                    suspendHits[0]++;
                } catch (Exception ex) {
                    exception[0] = ex;
                }
            });
            if (exception[0] != null) {
                throw exception[0];
            }
        }
        expectDone();
        if (exception[0] != null) {
            throw exception[0];
        }
        Assert.assertEquals(3 * numRepeats - 1, suspendHits[0]);
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 3 with DebugStackFrame

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

the class ReenterStackFrameTest method testReenterCurrent.

@Test
public void testReenterCurrent() throws Throwable {
    final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + "  STATEMENT(),\n" + "  STATEMENT(EXPRESSION)\n" + ")),\n" + "CALL(a))\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        final Exception[] exception = new Exception[1];
        final int[] suspendHits = new int[1];
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
                event.prepareStepOver(1);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT(EXPRESSION)", currentFrame.getSourceSection().getCharacters());
                event.prepareUnwindFrame(currentFrame);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
                Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
                Assert.assertEquals("", frames.next().getName());
                Assert.assertFalse(frames.hasNext());
                // Enter into "a"
                event.prepareStepInto(1);
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame currentFrame = event.getTopStackFrame();
            try {
                Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
                suspendHits[0]++;
            } catch (Exception ex) {
                exception[0] = ex;
            }
        });
        expectDone();
        if (exception[0] != null) {
            throw exception[0];
        }
        Assert.assertEquals(4, suspendHits[0]);
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 4 with DebugStackFrame

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

the class SuspendedEventTest method testIsInternal.

@Test
public void testIsInternal() throws Throwable {
    final Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(bar, ROOT(STATEMENT)),\n" + "  DEFINE(foo, STATEMENT, \n" + "              STATEMENT(CALL(bar))),\n" + "  STATEMENT(CALL(foo))\n" + ")\n", "internal test code").internal(true).build();
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            DebugStackFrame frame = frameIterator.next();
            assertTrue(frame.isInternal());
            frame = frameIterator.next();
            assertTrue(frame.isInternal());
            frame = frameIterator.next();
            assertTrue(frame.isInternal());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 5 with DebugStackFrame

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

Aggregations

DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)24 Source (org.graalvm.polyglot.Source)21 Test (org.junit.Test)21 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)20 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)19 DebugValue (com.oracle.truffle.api.debug.DebugValue)12 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)9 DebugScope (com.oracle.truffle.api.debug.DebugScope)7 SourceSection (com.oracle.truffle.api.source.SourceSection)5 ArrayList (java.util.ArrayList)2 Value (org.graalvm.polyglot.Value)2 TruffleException (com.oracle.truffle.api.TruffleException)1 Debugger (com.oracle.truffle.api.debug.Debugger)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 Source (com.oracle.truffle.api.source.Source)1 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)1 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)1 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)1 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)1