Search in sources :

Example 26 with DebugValue

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

the class DebugStackFrameTest method testFrameValidity.

@Test
public void testFrameValidity() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(b, 43), \n" + "  VARIABLE(c, 44), \n" + "  STATEMENT(),\n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        class SharedData {

            DebugStackFrame frame;

            DebugValue stackValueWithGetValue;

            DebugValue stackValueWithIterator;

            Iterator<DebugStackFrame> frameIterator2;

            DebugValue heapValue;
        }
        SharedData data = new SharedData();
        expectSuspended((SuspendedEvent event) -> {
            data.frame = event.getTopStackFrame();
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            assertSame(data.frame, frameIterator.next());
            assertFalse(frameIterator.hasNext());
            checkStack(data.frame, "a", "42", "b", "43", "c", "44");
            // values for verifying state checks
            data.frameIterator2 = event.getStackFrames().iterator();
            data.stackValueWithGetValue = data.frame.getScope().getDeclaredValue("a");
            data.stackValueWithIterator = data.frame.getScope().getDeclaredValues().iterator().next();
            // should dynamically create a local variable
            data.heapValue = data.frame.eval("VARIABLE(d, 45)");
            // should render all pointers invalid
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            // next event everything should be invalidated except heap values
            assertInvalidFrame(data.frame);
            assertInvalidIterator(data.frameIterator2);
            assertInvalidDebugValue(data.stackValueWithGetValue);
            assertInvalidDebugValue(data.stackValueWithIterator);
            assertEquals("45", data.heapValue.as(String.class));
            assertFalse(data.heapValue.isWritable());
            assertTrue(data.heapValue.isReadable());
            try {
                data.heapValue.set(data.heapValue);
                fail();
            } catch (IllegalStateException e) {
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Iterator(java.util.Iterator) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 27 with DebugValue

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

the class DebugValueTest method testNumValue.

@Test
public void testNumValue() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(inf, infinity), \n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value42 = frame.getScope().getDeclaredValue("a");
            assertEquals("a", value42.getName());
            assertFalse(value42.isArray());
            assertNull(value42.getArray());
            assertNull(value42.getProperties());
            assertEquals("Integer", value42.getMetaObject().as(String.class));
            assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
            SourceSection integerSS = value42.getSourceLocation();
            assertEquals("source integer", integerSS.getCharacters());
            SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
            assertEquals("source infinity", infinitySS.getCharacters());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) 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 28 with DebugValue

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

the class DebugValueTest method testValueAttributes.

/**
 * Test of {@link DebugValue#isReadable()}, {@link DebugValue#isWritable()} and
 * {@link DebugValue#isInternal()}.
 */
@Test
public void testValueAttributes() throws Throwable {
    final Source source = testSource("DEFINE(function, ROOT(\n" + "  ARGUMENT(a), \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);
    // Test of the default attribute values:
    NoAttributesTruffleObject nao = new NoAttributesTruffleObject();
    boolean[] suspended = new boolean[] { false };
    DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
        assertNotNull(value);
        DebugValue attributesTOValue = value.getProperties().iterator().next();
        assertEquals("property", attributesTOValue.getName());
        // Property is readable by default
        assertTrue(attributesTOValue.isReadable());
        // Property is writable by default
        assertTrue(attributesTOValue.isWritable());
        // Property is not internal by default
        assertFalse(attributesTOValue.isInternal());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
    functionValue.execute(nao);
    session.close();
    assertTrue(suspended[0]);
    // Test of the modified attribute values:
    suspended[0] = false;
    final ModifiableAttributesTruffleObject mao = new ModifiableAttributesTruffleObject();
    session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
        assertNotNull(value);
        DebugValue attributesTOValue = value.getProperties().iterator().next();
        assertEquals("property", attributesTOValue.getName());
        // All false initially
        assertFalse(attributesTOValue.isReadable());
        assertFalse(attributesTOValue.isWritable());
        assertFalse(attributesTOValue.isInternal());
        mao.setIsReadable(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isReadable());
        mao.setIsWritable(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isWritable());
        mao.setIsInternal(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isInternal());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
    functionValue.execute(mao);
    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 29 with DebugValue

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

the class AbstractDebugTest method checkStack.

protected void checkStack(DebugStackFrame frame, String... expectedFrame) {
    Map<String, DebugValue> values = new HashMap<>();
    for (DebugValue value : frame) {
        values.put(value.getName(), value);
    }
    Assert.assertEquals(expectedFrame.length / 2, values.size());
    for (int i = 0; i < expectedFrame.length; i = i + 2) {
        String expectedIdentifier = expectedFrame[i];
        String expectedValue = expectedFrame[i + 1];
        DebugValue value = values.get(expectedIdentifier);
        Assert.assertNotNull(value);
        Assert.assertEquals(expectedValue, value.as(String.class));
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) HashMap(java.util.HashMap)

Example 30 with DebugValue

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

the class TruffleDebugger method evaluateOnCallFrame.

@Override
public Params evaluateOnCallFrame(String callFrameId, String expression, String objectGroup, boolean includeCommandLineAPI, boolean silent, boolean returnByValue, boolean generatePreview, boolean throwOnSideEffect) throws CommandProcessException {
    if (callFrameId == null) {
        throw new CommandProcessException("A callFrameId required.");
    }
    if (expression == null) {
        throw new CommandProcessException("An expression required.");
    }
    int frameId;
    try {
        frameId = Integer.parseInt(callFrameId);
    } catch (NumberFormatException ex) {
        throw new CommandProcessException(ex.getLocalizedMessage());
    }
    JSONObject jsonResult;
    try {
        jsonResult = context.executeInSuspendThread(new SuspendThreadExecutable<JSONObject>() {

            @Override
            public JSONObject executeCommand() throws CommandProcessException {
                if (frameId >= suspendedInfo.getCallFrames().length) {
                    throw new CommandProcessException("Too big callFrameId: " + frameId);
                }
                CallFrame cf = suspendedInfo.getCallFrames()[frameId];
                JSONObject json = new JSONObject();
                try {
                    DebugValue value = cf.getFrame().eval(expression);
                    RemoteObject ro = new RemoteObject(value, context.getErr());
                    context.getRemoteObjectsHandler().register(ro);
                    json.put("result", ro.toJSON());
                } catch (Throwable t) {
                    if (t instanceof TruffleException && !((TruffleException) t).isInternalError()) {
                        JSONObject err = new JSONObject();
                        err.putOpt("value", t.getLocalizedMessage());
                        json.put("result", err);
                    } else {
                        throw t;
                    }
                }
                return json;
            }
        });
    } catch (NoSuspendedThreadException e) {
        jsonResult = new JSONObject();
        JSONObject err = new JSONObject();
        err.putOpt("value", e.getLocalizedMessage());
        jsonResult.put("result", err);
    } catch (GuestLanguageException e) {
        jsonResult = new JSONObject();
        TruffleRuntime.fillExceptionDetails(jsonResult, e);
    }
    return new Params(jsonResult);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) DebugValue(com.oracle.truffle.api.debug.DebugValue) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(org.json.JSONObject) CallFrame(com.oracle.truffle.tools.chromeinspector.types.CallFrame) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException) TruffleException(com.oracle.truffle.api.TruffleException)

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