Search in sources :

Example 11 with DebugScope

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

the class SLDebugTest method testValuesScope.

@Test
public void testValuesScope() throws Throwable {
    final Source varsSource = slCode("function main() {\n" + "  a = 1;\n" + "  if (a > 0) {\n" + "    b = 10;\n" + "    println(b);\n" + "  }\n" + "  println(b);\n" + "  println(a);\n" + "  println(\"END.\");\n" + "}");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(varsSource);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            // No variables first:
            assertFalse(frame.getScope().getDeclaredValues().iterator().hasNext());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            // "a" only:
            DebugScope scope = frame.getScope();
            Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
            assertTrue(varIt.hasNext());
            DebugValue a = varIt.next();
            assertEquals("a", a.getName());
            assertEquals(scope, a.getScope());
            assertFalse(varIt.hasNext());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            // "a" only:
            DebugScope scope = frame.getScope();
            Iterator<DebugValue> varIt = scope.getParent().getDeclaredValues().iterator();
            assertTrue(varIt.hasNext());
            DebugValue a = varIt.next();
            assertEquals("a", a.getName());
            assertEquals(scope.getParent(), a.getScope());
            assertFalse(varIt.hasNext());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            // "a" and "b":
            DebugScope scope = frame.getScope();
            Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
            assertTrue(varIt.hasNext());
            DebugValue b = varIt.next();
            assertEquals("b", b.getName());
            assertEquals(scope, b.getScope());
            // "a" is in the parent:
            assertFalse(varIt.hasNext());
            varIt = scope.getParent().getDeclaredValues().iterator();
            assertTrue(varIt.hasNext());
            DebugValue a = varIt.next();
            assertEquals("a", a.getName());
            assertEquals(scope.getParent(), a.getScope());
            assertFalse(varIt.hasNext());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            // "a" only again:
            DebugScope scope = frame.getScope();
            Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
            assertTrue(varIt.hasNext());
            DebugValue a = varIt.next();
            assertEquals("a", a.getName());
            assertEquals(scope, a.getScope());
            assertFalse(varIt.hasNext());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) 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 12 with DebugScope

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

the class SLDebugTest method checkArgs.

protected void checkArgs(DebugStackFrame frame, String... expectedArgs) {
    Iterable<DebugValue> arguments = null;
    DebugScope scope = frame.getScope();
    while (scope != null) {
        if (scope.isFunctionScope()) {
            arguments = scope.getArguments();
            break;
        }
        scope = scope.getParent();
    }
    checkDebugValues("arguments", arguments, expectedArgs);
}
Also used : DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugValue(com.oracle.truffle.api.debug.DebugValue)

Aggregations

DebugScope (com.oracle.truffle.api.debug.DebugScope)12 DebugValue (com.oracle.truffle.api.debug.DebugValue)9 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)7 Source (org.graalvm.polyglot.Source)6 Test (org.junit.Test)6 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)5 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)5 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)2 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)2 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)2 Scope (com.oracle.truffle.tools.chromeinspector.types.Scope)2 ArrayList (java.util.ArrayList)2 TruffleException (com.oracle.truffle.api.TruffleException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 Source (com.oracle.truffle.api.source.Source)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)1