Search in sources :

Example 21 with DebugValue

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

the class DebugALot method logValue.

private void logValue(String prefix, DebugValue v) {
    LanguageInfo language = v.getOriginalLanguage();
    if (language != null) {
        logger.print(prefix);
        logger.print("From: ");
        logger.println(language.getId());
    }
    DebugValue metaObject = v.getMetaObject();
    if (metaObject != null) {
        logger.print(prefix);
        logger.print("Type: ");
        logger.println(metaObject.as(String.class));
    }
    SourceSection sourceLocation = v.getSourceLocation();
    if (sourceLocation != null) {
        logger.print(prefix);
        logger.print("SourceSection: ");
        logSourceSection(sourceLocation);
    }
    if (v.isArray()) {
        List<DebugValue> array = v.getArray();
        int length = array.size();
        logger.print(prefix);
        logger.print("Array of length: ");
        logger.println(Integer.toString(length));
        for (int i = 0; i < length && i < 10; i++) {
            logger.print(prefix);
            logger.print("  element #");
            logger.print(Integer.toString(i));
            logger.print(" : ");
            logger.println(array.get(i).as(String.class));
        }
    }
    Collection<DebugValue> properties = v.getProperties();
    logger.print(prefix);
    if (properties == null || properties.isEmpty()) {
        logger.println("Properties: none");
    } else {
        logger.print("Properties: ");
        logger.println(Integer.toString(properties.size()));
    }
    logger.print(prefix);
    logger.print("Internal: ");
    logger.println(v.isInternal());
    logger.print(prefix);
    logger.print("Readable: ");
    logger.println(v.isReadable());
    logger.print(prefix);
    logger.print("Writable: ");
    logger.println(v.isWritable());
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) DebugValue(com.oracle.truffle.api.debug.DebugValue) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 22 with DebugValue

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

the class StepTest method testExpressionStep.

@Test
public void testExpressionStep() {
    final Source source = testSource("ROOT(\n" + "  DEFINE(inner1, ROOT(\n" + "    STATEMENT,\n" + "    EXPRESSION,\n" + "    EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))\n" + "  )),\n" + "  DEFINE(inner2, ROOT(\n" + "    EXPRESSION,\n" + "    CALL(inner2_1),\n" + "    EXPRESSION(CALL(inner2_1))\n" + "  )),\n" + "  DEFINE(inner2_1, ROOT(\n" + "    STATEMENT(EXPRESSION(EXPRESSION))\n" + "  )),\n" + "  EXPRESSION,\n" + "  STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2))),\n" + "  EXPRESSION,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession(SourceElement.EXPRESSION)) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 15, true, "EXPRESSION").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 15, false, "EXPRESSION").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, true, "EXPRESSION(CALL(inner1))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, false, "EXPRESSION").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "EXPRESSION(CONSTANT(1))").prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, false, "EXPRESSION(CONSTANT(1))").prepareStepOut(1);
            Assert.assertEquals("(1)", event.getReturnValue().as(String.class));
            Assert.assertEquals(Arrays.asList(event.getInputValues()).toString(), 0, event.getInputValues().length);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, false, "EXPRESSION(EXPRESSION(CONSTANT(1)), EXPRESSION(CONSTANT(2)))").prepareStepInto(1);
            Assert.assertEquals("((1)+(2))", event.getReturnValue().as(String.class));
            DebugValue[] inputValues = event.getInputValues();
            Assert.assertEquals(Arrays.asList(inputValues).toString(), 2, event.getInputValues().length);
            Assert.assertEquals("(1)", inputValues[0].as(String.class));
            Assert.assertEquals("(2)", inputValues[1].as(String.class));
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "CALL(inner1)").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "EXPRESSION(CALL(inner1))").prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 8, true, "EXPRESSION").prepareStepOver(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "EXPRESSION(CALL(inner2_1))").prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 13, true, "EXPRESSION(EXPRESSION)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 13, false, "EXPRESSION(EXPRESSION)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "CALL(inner2_1)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, false, "EXPRESSION(CALL(inner2_1))").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "CALL(inner2)").prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 16, false, "EXPRESSION(CALL(inner2))").prepareStepOut(1);
        });
        expectDone();
    }
}
Also used : 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 DebugValue

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

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

the class DebugScopeTest method testArguments.

@Test
public void testArguments() {
    final Source source = testSource("DEFINE(function, ROOT(\n" + "  STATEMENT()\n" + "))\n");
    Context context = Context.create();
    context.eval(source);
    Value functionValue = context.getBindings(InstrumentationTestLanguage.ID).getMember("function");
    assertNotNull(functionValue);
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    boolean[] suspended = new boolean[] { false };
    DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        Iterable<DebugValue> arguments = event.getTopStackFrame().getScope().getArguments();
        assertNotNull(arguments);
        Iterator<DebugValue> iterator = arguments.iterator();
        assertTrue(iterator.hasNext());
        DebugValue arg = iterator.next();
        assertEquals("0", arg.getName());
        assertEquals("true", arg.as(String.class));
        assertTrue(iterator.hasNext());
        arg = iterator.next();
        assertEquals("1", arg.getName());
        assertEquals("10", arg.as(String.class));
        assertFalse(iterator.hasNext());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.suspendNextExecution();
    functionValue.execute(true, 10);
    session.close();
    assertTrue(suspended[0]);
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Value(org.graalvm.polyglot.Value) DebugValue(com.oracle.truffle.api.debug.DebugValue) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 25 with DebugValue

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

the class DebugStackFrameTest method assertDynamicFrame.

private static void assertDynamicFrame(DebugStackFrame frame) {
    assertEquals("42", frame.getScope().getDeclaredValue("a").as(String.class));
    assertEquals("43", frame.getScope().getDeclaredValue("b").as(String.class));
    assertEquals("44", frame.getScope().getDeclaredValue("c").as(String.class));
    // dynamic value should now be accessible
    DebugValue dStackValue = frame.getScope().getDeclaredValue("d");
    assertNull(dStackValue);
    // should change the dynamic value
    assertEquals("45", frame.eval("VARIABLE(d, 45)").as(String.class));
    dStackValue = frame.getScope().getDeclaredValue("d");
    assertEquals("45", dStackValue.as(String.class));
    assertEquals("45", frame.getScope().getDeclaredValue("d").as(String.class));
    // change an existing value
    assertEquals("45", frame.eval("VARIABLE(c, 45)").as(String.class));
    assertEquals("45", frame.getScope().getDeclaredValue("c").as(String.class));
    // set an existing value using a constant expression
    DebugValue bValue = frame.getScope().getDeclaredValue("b");
    frame.getScope().getDeclaredValue("b").set(frame.eval("CONSTANT(46)"));
    assertEquals("46", frame.getScope().getDeclaredValue("b").as(String.class));
    assertEquals("46", bValue.as(String.class));
    // set an existing value using a constant expression with side effect
    frame.getScope().getDeclaredValue("b").set(frame.eval("VARIABLE(a, 47)"));
    assertEquals("47", frame.getScope().getDeclaredValue("b").as(String.class));
    assertEquals("47", frame.getScope().getDeclaredValue("a").as(String.class));
}
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