Search in sources :

Example 11 with DebugValue

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

the class DebugALot method logValues.

private void logValues(String prefix, List<DebugValue> values) {
    for (int i = 0; i < values.size(); i++) {
        logger.print(prefix);
        logger.print(i + 1);
        logger.print(". ");
        DebugValue v = values.get(i);
        logger.print(v.getName());
        logger.print(" = ");
        logger.println(v.as(String.class));
        int offset = prefix.length() + Integer.toString(i + 1).length() + 2;
        String valuePrefix = getPrefix(offset);
        logValue(valuePrefix, v);
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue)

Example 12 with DebugValue

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

the class DebugALot method testEval.

private void testEval(String prefix, DebugStackFrame frame, List<DebugValue> values) {
    for (DebugValue v : values) {
        DebugValue ev = frame.eval(v.getName());
        String value = v.as(String.class);
        String evalue = ev.as(String.class);
        if (!value.equals(evalue)) {
            hasFailed = true;
            logger.print(prefix);
            logger.print("ERROR: local value '");
            logger.print(v.getName());
            logger.print("' has value '");
            logger.print(v.as(String.class));
            logger.print("' but evaluated to '");
            logger.print(ev.as(String.class));
            logger.println("'");
        }
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue)

Example 13 with DebugValue

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

the class SLDebugDirectTest method assertLocation.

private void assertLocation(final String name, final int line, final boolean isBefore, final String code, final Object... expectedFrame) {
    run.addLast(() -> {
        assertNotNull(suspendedEvent);
        final SourceSection suspendedSourceSection = suspendedEvent.getSourceSection();
        Assert.assertEquals(line, suspendedSourceSection.getStartLine());
        Assert.assertEquals(code, suspendedSourceSection.getCharacters());
        Assert.assertEquals(isBefore, suspendedEvent.getSuspendAnchor() == SuspendAnchor.BEFORE);
        final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
        assertEquals(name, frame.getName());
        for (int i = 0; i < expectedFrame.length; i = i + 2) {
            final String expectedIdentifier = (String) expectedFrame[i];
            final Object expectedValue = expectedFrame[i + 1];
            DebugScope scope = frame.getScope();
            DebugValue slot = scope.getDeclaredValue(expectedIdentifier);
            while (slot == null && (scope = scope.getParent()) != null) {
                slot = scope.getDeclaredValue(expectedIdentifier);
            }
            if (expectedValue != UNASSIGNED) {
                Assert.assertNotNull(expectedIdentifier, slot);
                final String slotValue = slot.as(String.class);
                Assert.assertEquals(expectedValue, slotValue);
            } else {
                Assert.assertNull(expectedIdentifier, slot);
            }
        }
        run.removeFirst().run();
    });
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugValue(com.oracle.truffle.api.debug.DebugValue) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) SourceSection(com.oracle.truffle.api.source.SourceSection) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Example 14 with DebugValue

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

the class SLDebugDirectTest method testPause.

@Test
public void testPause() throws Throwable {
    final Source interopComp = createInteropComputation();
    context.eval(interopComp);
    assertExecutedOK();
    final ExecNotifyHandler nh = new ExecNotifyHandler();
    // Do pause after execution has really started
    new Thread() {

        @Override
        public void run() {
            nh.waitTillCanPause();
            session.suspendNextExecution();
        }
    }.start();
    run.addLast(() -> {
        // paused
        assertNotNull(suspendedEvent);
        int line = suspendedEvent.getSourceSection().getStartLine();
        Assert.assertTrue("Unexpected line: " + line, 5 <= line && line <= 6);
        final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
        DebugScope scope = frame.getScope();
        DebugValue slot = scope.getDeclaredValue("executing");
        if (slot == null) {
            slot = scope.getParent().getDeclaredValue("executing");
        }
        Assert.assertNotNull(slot);
        Assert.assertNotNull("Value is null", slot.toString());
        suspendedEvent.prepareContinue();
        nh.pauseDone();
    });
    Value value = context.getBindings("sl").getMember("interopFunction").execute(nh);
    assertExecutedOK();
    assertTrue(value.isBoolean());
    boolean n = value.asBoolean();
    assertTrue("Interop computation OK", !n);
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugValue(com.oracle.truffle.api.debug.DebugValue) Value(org.graalvm.polyglot.Value) DebugValue(com.oracle.truffle.api.debug.DebugValue) Source(org.graalvm.polyglot.Source) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 15 with DebugValue

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

the class SLDebugTest method testDebugValue.

@Test
public void testDebugValue() throws Throwable {
    final Source varsSource = slCode("function main() {\n" + "  a = doNull();\n" + "  b = 10 == 10;\n" + "  c = 10;\n" + "  d = \"str\";\n" + "  e = new();\n" + "  e.p1 = 1;\n" + "  e.p2 = new();\n" + "  e.p2.p21 = 21;\n" + "  return;\n" + "}\n" + "function doNull() {}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(10).build());
        startEval(varsSource);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugScope scope = frame.getScope();
            DebugValue a = scope.getDeclaredValue("a");
            assertFalse(a.isArray());
            assertNull(a.getArray());
            assertNull(a.getProperties());
            DebugValue b = scope.getDeclaredValue("b");
            assertFalse(b.isArray());
            assertNull(b.getArray());
            assertNull(b.getProperties());
            DebugValue c = scope.getDeclaredValue("c");
            assertFalse(c.isArray());
            assertEquals("10", c.as(String.class));
            assertNull(c.getArray());
            assertNull(c.getProperties());
            DebugValue d = scope.getDeclaredValue("d");
            assertFalse(d.isArray());
            assertEquals("str", d.as(String.class));
            assertNull(d.getArray());
            assertNull(d.getProperties());
            DebugValue e = scope.getDeclaredValue("e");
            assertFalse(e.isArray());
            assertNull(e.getArray());
            assertEquals(scope, e.getScope());
            Collection<DebugValue> propertyValues = e.getProperties();
            assertEquals(2, propertyValues.size());
            Iterator<DebugValue> propertiesIt = propertyValues.iterator();
            assertTrue(propertiesIt.hasNext());
            DebugValue p1 = propertiesIt.next();
            assertEquals("p1", p1.getName());
            assertEquals("1", p1.as(String.class));
            assertNull(p1.getScope());
            assertTrue(propertiesIt.hasNext());
            DebugValue p2 = propertiesIt.next();
            assertEquals("p2", p2.getName());
            assertNull(p2.getScope());
            assertFalse(propertiesIt.hasNext());
            propertyValues = p2.getProperties();
            assertEquals(1, propertyValues.size());
            propertiesIt = propertyValues.iterator();
            assertTrue(propertiesIt.hasNext());
            DebugValue p21 = propertiesIt.next();
            assertEquals("p21", p21.getName());
            assertEquals("21", p21.as(String.class));
            assertNull(p21.getScope());
            assertFalse(propertiesIt.hasNext());
        });
        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)

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