Search in sources :

Example 16 with DebugValue

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

the class SLDebugTest method testMetaObjects.

@Test
public void testMetaObjects() {
    final Source varsSource = slCode("function main() {\n" + "  a = doNull();\n" + "  b = 10 == 10;\n" + "  c = 10;\n" + "  cBig = 1000000000*1000000000*1000000000*1000000000;\n" + "  d = \"str\";\n" + "  e = new();\n" + "  f = doNull;\n" + "  return;\n" + "}\n" + "function doNull() {}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(9).build());
        startEval(varsSource);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugScope scope = frame.getScope();
            DebugValue v = scope.getDeclaredValue("a");
            assertEquals("Null", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("b");
            assertEquals("Boolean", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("c");
            assertEquals("Number", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("cBig");
            assertEquals("Number", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("d");
            assertEquals("String", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("e");
            assertEquals("Object", v.getMetaObject().as(String.class));
            v = scope.getDeclaredValue("f");
            assertEquals("Function", v.getMetaObject().as(String.class));
        });
        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 17 with DebugValue

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

the class SLDebugTest method testSourceLocation.

@Test
public void testSourceLocation() {
    final Source varsSource = slCode("function main() {\n" + "  a = doNull();\n" + "  c = 10;\n" + "  d = \"str\";\n" + "  e = new();\n" + "  f = doNull;\n" + "  return;\n" + "}\n" + "function doNull() {}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(7).build());
        startEval(varsSource);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugScope scope = frame.getScope();
            DebugValue v = scope.getDeclaredValue("a");
            assertNull(v.getSourceLocation());
            v = scope.getDeclaredValue("c");
            assertNull(v.getSourceLocation());
            v = scope.getDeclaredValue("d");
            assertNull(v.getSourceLocation());
            v = scope.getDeclaredValue("e");
            assertNull(v.getSourceLocation());
            v = scope.getDeclaredValue("f");
            SourceSection sourceLocation = v.getSourceLocation();
            Assert.assertNotNull(sourceLocation);
            assertEquals(9, sourceLocation.getStartLine());
            assertEquals(9, sourceLocation.getEndLine());
            assertEquals("doNull() {}", sourceLocation.getCharacters());
        });
        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) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 18 with DebugValue

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

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

Example 20 with DebugValue

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

the class DebugALot method logScope.

private void logScope(String prefix, DebugScope scope, DebugStackFrame frameForEval) {
    logger.print(scope.getName());
    if (scope.isFunctionScope()) {
        logger.println(" [Function]");
    } else {
        logger.println();
    }
    Iterable<DebugValue> arguments = scope.getArguments();
    List<DebugValue> values;
    if (arguments != null) {
        logger.print(prefix);
        logger.print("Arguments: ");
        values = new ArrayList<>();
        for (DebugValue v : arguments) {
            values.add(v);
        }
        logger.println(values.size());
        logValues(prefix, values);
    }
    Iterable<DebugValue> variables = scope.getDeclaredValues();
    logger.print(prefix);
    logger.print("Variables: ");
    values = new ArrayList<>();
    for (DebugValue v : variables) {
        values.add(v);
    }
    logger.println(values.size());
    logValues(prefix, values);
    if (frameForEval != null && doEval) {
        testEval(prefix, frameForEval, values);
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue)

Aggregations

DebugValue (com.oracle.truffle.api.debug.DebugValue)33 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)15 Source (org.graalvm.polyglot.Source)15 Test (org.junit.Test)15 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)14 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)11 DebugScope (com.oracle.truffle.api.debug.DebugScope)9 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)8 JSONObject (org.json.JSONObject)6 SourceSection (com.oracle.truffle.api.source.SourceSection)5 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)5 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)5 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 Debugger (com.oracle.truffle.api.debug.Debugger)3 Context (org.graalvm.polyglot.Context)3 Value (org.graalvm.polyglot.Value)3 JSONArray (org.json.JSONArray)3 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)2