Search in sources :

Example 6 with DebugValue

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

the class TruffleRuntime method getProperties.

@Override
public Params getProperties(String objectId, boolean ownProperties) throws CommandProcessException {
    if (objectId == null) {
        throw new CommandProcessException("An objectId required.");
    }
    RemoteObject object = context.getRemoteObjectsHandler().getRemote(objectId);
    JSONObject json = new JSONObject();
    if (object != null) {
        DebugValue value = object.getDebugValue();
        try {
            if (value != null) {
                context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {

                    @Override
                    public Void executeCommand() throws CommandProcessException {
                        putResultProperties(json, value.getProperties(), value.isArray() ? value.getArray() : Collections.emptyList());
                        return null;
                    }
                });
            } else {
                final DebugScope scope = object.getScope();
                context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {

                    @Override
                    public Void executeCommand() throws CommandProcessException {
                        Collection<DebugValue> properties = new ArrayList<>();
                        for (DebugValue p : scope.getDeclaredValues()) {
                            properties.add(p);
                        }
                        putResultProperties(json, properties, Collections.emptyList());
                        return null;
                    }
                });
            }
        } catch (NoSuspendedThreadException ex) {
            // Not suspended, no properties
            json.put("result", new JSONArray());
        } catch (GuestLanguageException ex) {
            fillExceptionDetails(json, ex);
        }
    }
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) DebugScope(com.oracle.truffle.api.debug.DebugScope) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(org.json.JSONObject) Collection(java.util.Collection) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)

Example 7 with DebugValue

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

the class TruffleRuntime method createCodecompletion.

private JSONObject createCodecompletion(DebugValue value) {
    Collection<DebugValue> properties = null;
    try {
        properties = value.getProperties();
    } catch (Exception ex) {
        PrintWriter err = context.getErr();
        if (err != null) {
            err.println("getProperties(" + value.getName() + ") has caused: " + ex);
            ex.printStackTrace(err);
        }
    }
    JSONObject result = new JSONObject();
    JSONArray valueArray = new JSONArray();
    JSONObject itemsObj = new JSONObject();
    JSONArray items = new JSONArray();
    if (properties != null) {
        for (DebugValue property : properties) {
            items.put(property.getName());
        }
    }
    itemsObj.put("items", items);
    valueArray.put(itemsObj);
    result.put("type", "object");
    result.put("value", valueArray);
    return result;
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) URISyntaxException(java.net.URISyntaxException) CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException) PrintWriter(java.io.PrintWriter)

Example 8 with DebugValue

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

the class RemoteObject method createJSONResultValue.

/**
 * Create a JSON object representing the provided {@link DebugValue}. Use when a reply by value
 * is requested.
 */
public static JSONObject createJSONResultValue(DebugValue debugValue, PrintWriter err) {
    JSONObject json = new JSONObject();
    DebugValue metaObject = getMetaObject(debugValue, null, err);
    boolean isObject = isObject(debugValue, err);
    String vtype = null;
    if (metaObject != null) {
        try {
            Collection<DebugValue> properties = metaObject.getProperties();
            if (properties != null) {
                for (DebugValue prop : properties) {
                    String name = prop.getName();
                    if ("type".equals(name)) {
                        vtype = prop.as(String.class);
                    }
                }
            }
        } catch (Exception ex) {
            if (err != null) {
                err.println("getProperties of meta object of (" + debugValue.getName() + ") has caused: " + ex);
                ex.printStackTrace(err);
            }
        }
    }
    if (vtype == null) {
        if (isObject) {
            vtype = "object";
        } else {
            vtype = (metaObject != null) ? metaObject.as(String.class) : "object";
        }
    }
    json.put("type", vtype);
    json.put("value", createJSONValue(debugValue, err));
    return json;
}
Also used : JSONObject(org.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue)

Example 9 with DebugValue

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

the class SLDebugTest method checkDebugValues.

private static void checkDebugValues(String msg, Iterable<DebugValue> values, String... expected) {
    Map<String, DebugValue> valMap = new HashMap<>();
    for (DebugValue value : values) {
        valMap.put(value.getName(), value);
    }
    String message = String.format("Frame %s expected %s got %s", msg, Arrays.toString(expected), valMap.toString());
    Assert.assertEquals(message, expected.length / 2, valMap.size());
    for (int i = 0; i < expected.length; i = i + 2) {
        String expectedIdentifier = expected[i];
        String expectedValue = expected[i + 1];
        DebugValue value = valMap.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) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Example 10 with DebugValue

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

the class SLDebugTest method checkExpressionStepPositions.

private void checkExpressionStepPositions(String stepPositions, boolean includeStatements, StepDepth... steps) {
    Source source = slCode("function main() {\n" + "  x = 2;\n" + "  while (x >= 0 && 5 >= 0) {\n" + "    a = 2 * x;\n" + "    b = (a * a) / (x * x + 1);\n" + "    x = x - transform(a, b);\n" + "  }\n" + "  return x / 1;\n" + "}\n" + "function transform(a, b) {\n" + "  return (1 + 1) * (a + b);\n" + "}\n");
    SourceElement[] elements;
    if (includeStatements) {
        elements = new SourceElement[] { SourceElement.EXPRESSION, SourceElement.STATEMENT };
    } else {
        elements = new SourceElement[] { SourceElement.EXPRESSION };
    }
    try (DebuggerSession session = startSession(elements)) {
        session.suspendNextExecution();
        startEval(source);
        // Step through the program
        StepDepth lastStep = steps[0];
        int stepIndex = 0;
        StepConfig expressionStepConfig = StepConfig.newBuilder().sourceElements(elements).build();
        for (String stepPos : stepPositions.split("\n")) {
            if (stepIndex < steps.length) {
                lastStep = steps[stepIndex++];
            }
            final StepDepth stepDepth = lastStep;
            expectSuspended((SuspendedEvent event) -> {
                if (!includeStatements) {
                    assertTrue("Needs to be an expression", event.hasSourceElement(SourceElement.EXPRESSION));
                } else {
                    assertTrue("Needs to be an expression or statement", event.hasSourceElement(SourceElement.EXPRESSION) || event.hasSourceElement(SourceElement.STATEMENT));
                }
                SourceSection ss = event.getSourceSection();
                DebugValue[] inputValues = event.getInputValues();
                String input = "";
                if (inputValues != null) {
                    StringBuilder inputBuilder = new StringBuilder("(");
                    for (DebugValue v : inputValues) {
                        if (inputBuilder.length() > 1) {
                            inputBuilder.append(',');
                        }
                        if (v != null) {
                            inputBuilder.append(v.as(String.class));
                        } else {
                            inputBuilder.append("null");
                        }
                    }
                    inputBuilder.append(") ");
                    input = inputBuilder.toString();
                }
                DebugValue returnValue = event.getReturnValue();
                String ret = (returnValue != null) ? returnValue.as(String.class) : "<none>";
                String actualPos = "<" + ss.getStartLine() + ":" + ss.getStartColumn() + " - " + ss.getEndLine() + ":" + ss.getEndColumn() + "> " + input + ret;
                assertEquals(stepPos, actualPos);
                switch(stepDepth) {
                    case INTO:
                        event.prepareStepInto(expressionStepConfig);
                        break;
                    case OVER:
                        event.prepareStepOver(expressionStepConfig);
                        break;
                    case OUT:
                        event.prepareStepOut(expressionStepConfig);
                        break;
                }
            });
        }
        expectDone();
    }
}
Also used : SourceElement(com.oracle.truffle.api.debug.SourceElement) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) StepConfig(com.oracle.truffle.api.debug.StepConfig) Source(org.graalvm.polyglot.Source) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SourceSection(com.oracle.truffle.api.source.SourceSection)

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