Search in sources :

Example 6 with DebugScope

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

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

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

Example 9 with DebugScope

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

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

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