Search in sources :

Example 21 with DebugStackFrame

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

the class SuspendedEventTest method testStackFrames.

@Test
public void testStackFrames() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + "  DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(VARIABLE(root0, 43)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT(VARIABLE(root0, 43))").prepareStepOver(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next());
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT(CALL(foo))", "root0", "43").prepareStepInto(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(CALL(bar))", "foo0", "42").prepareStepInto(1);
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "foo0", "42");
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT", "bar0", "41", "bar1", "40").prepareContinue();
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            checkStack(frameIterator.next(), "bar0", "41", "bar1", "40");
            checkStack(frameIterator.next(), "foo0", "42");
            checkStack(frameIterator.next(), "root0", "43");
            Assert.assertFalse(frameIterator.hasNext());
        });
        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 22 with DebugStackFrame

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

the class SuspendedEventTest method testOtherThreadAccess.

@Test
public void testOtherThreadAccess() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + "  DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(VARIABLE(root0, 43)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        final Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            run(() -> event.getBreakpointConditionException(breakpoint));
            run(() -> event.getSession());
            run(() -> event.getSourceSection());
            run(() -> event.getBreakpoints());
            run(() -> event.getSuspendAnchor());
            run(() -> event.toString());
            run(() -> {
                event.prepareStepInto(1);
                return null;
            });
            run(() -> {
                event.prepareStepOut(1);
                return null;
            });
            run(() -> {
                event.prepareStepOver(1);
                return null;
            });
            run(() -> {
                event.prepareContinue();
                return null;
            });
            run(() -> {
                event.prepareKill();
                return null;
            });
            runExpectIllegalState(() -> event.getStackFrames());
            runExpectIllegalState(() -> event.getTopStackFrame());
            runExpectIllegalState(() -> event.getReturnValue());
            for (DebugStackFrame frame : event.getStackFrames()) {
                for (DebugValue value : frame) {
                    runExpectIllegalState(() -> value.as(String.class));
                    runExpectIllegalState(() -> {
                        value.set(null);
                        return null;
                    });
                    // Name is known
                    value.getName();
                    runExpectIllegalState(() -> value.isReadable());
                    runExpectIllegalState(() -> value.isWritable());
                }
                run(() -> frame.getName());
                run(() -> frame.getSourceSection());
                run(() -> frame.isInternal());
                run(() -> frame.toString());
                runExpectIllegalState(() -> frame.getScope().getDeclaredValue(""));
                runExpectIllegalState(() -> frame.getScope().getDeclaredValues().iterator());
                runExpectIllegalState(() -> frame.eval(""));
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) 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 23 with DebugStackFrame

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

the class DebugStackFrameTest method testFrameValidity.

@Test
public void testFrameValidity() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(b, 43), \n" + "  VARIABLE(c, 44), \n" + "  STATEMENT(),\n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        class SharedData {

            DebugStackFrame frame;

            DebugValue stackValueWithGetValue;

            DebugValue stackValueWithIterator;

            Iterator<DebugStackFrame> frameIterator2;

            DebugValue heapValue;
        }
        SharedData data = new SharedData();
        expectSuspended((SuspendedEvent event) -> {
            data.frame = event.getTopStackFrame();
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            assertSame(data.frame, frameIterator.next());
            assertFalse(frameIterator.hasNext());
            checkStack(data.frame, "a", "42", "b", "43", "c", "44");
            // values for verifying state checks
            data.frameIterator2 = event.getStackFrames().iterator();
            data.stackValueWithGetValue = data.frame.getScope().getDeclaredValue("a");
            data.stackValueWithIterator = data.frame.getScope().getDeclaredValues().iterator().next();
            // should dynamically create a local variable
            data.heapValue = data.frame.eval("VARIABLE(d, 45)");
            // should render all pointers invalid
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            // next event everything should be invalidated except heap values
            assertInvalidFrame(data.frame);
            assertInvalidIterator(data.frameIterator2);
            assertInvalidDebugValue(data.stackValueWithGetValue);
            assertInvalidDebugValue(data.stackValueWithIterator);
            assertEquals("45", data.heapValue.as(String.class));
            assertFalse(data.heapValue.isWritable());
            assertTrue(data.heapValue.isReadable());
            try {
                data.heapValue.set(data.heapValue);
                fail();
            } catch (IllegalStateException e) {
            }
        });
        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) Iterator(java.util.Iterator) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 24 with DebugStackFrame

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

the class DebugValueTest method testNumValue.

@Test
public void testNumValue() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(inf, infinity), \n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value42 = frame.getScope().getDeclaredValue("a");
            assertEquals("a", value42.getName());
            assertFalse(value42.isArray());
            assertNull(value42.getArray());
            assertNull(value42.getProperties());
            assertEquals("Integer", value42.getMetaObject().as(String.class));
            assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
            SourceSection integerSS = value42.getSourceLocation();
            assertEquals("source integer", integerSS.getCharacters());
            SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
            assertEquals("source infinity", infinitySS.getCharacters());
        });
        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) SourceSection(com.oracle.truffle.api.source.SourceSection) 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