Search in sources :

Example 31 with DebugValue

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

the class TruffleRuntime method putResultProperties.

private void putResultProperties(JSONObject json, Collection<DebugValue> properties, Collection<DebugValue> arrayElements) {
    JSONArray result = new JSONArray();
    JSONArray internals = new JSONArray();
    HashSet<String> storedPropertyNames = new HashSet<>(properties.size());
    for (DebugValue v : properties) {
        if (v.isReadable()) {
            if (!v.isInternal()) {
                result.put(createPropertyJSON(v));
                storedPropertyNames.add(v.getName());
            } else {
                internals.put(createPropertyJSON(v));
            }
        }
    }
    int i = 0;
    for (DebugValue v : arrayElements) {
        String name = Integer.toString(i++);
        if (v.isReadable() && !storedPropertyNames.contains(name)) {
            result.put(createPropertyJSON(v, name));
        }
    }
    json.put("result", result);
    json.put("internalProperties", internals);
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONArray(org.json.JSONArray) HashSet(java.util.HashSet)

Example 32 with DebugValue

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

the class TruffleRuntime method callFunctionOn.

@Override
public Params callFunctionOn(String objectId, String functionDeclaration, JSONArray arguments, boolean silent, boolean returnByValue, boolean awaitPromise) 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();
        DebuggerSuspendedInfo suspendedInfo = context.getSuspendedInfo();
        if (suspendedInfo != null) {
            try {
                context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {

                    @Override
                    public Void executeCommand() throws CommandProcessException {
                        JSONObject result;
                        if (functionDeclaration.startsWith("function getCompletions(")) {
                            result = createCodecompletion(value);
                        } else {
                            String code = "(" + functionDeclaration + ")(" + value.getName() + ")";
                            DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code);
                            if (!returnByValue) {
                                RemoteObject ro = new RemoteObject(eval, context.getErr());
                                context.getRemoteObjectsHandler().register(ro);
                                result = ro.toJSON();
                            } else {
                                result = RemoteObject.createJSONResultValue(eval, context.getErr());
                            }
                        }
                        json.put("result", result);
                        return null;
                    }
                });
            } catch (NoSuspendedThreadException ex) {
                json.put("result", new JSONObject());
            } catch (GuestLanguageException ex) {
                fillExceptionDetails(json, ex);
            }
        }
    }
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(org.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)

Example 33 with DebugValue

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

the class LLVMDebugTest method assertValues.

private static void assertValues(DebugScope scope, Map<String, LLVMDebugValue> expectedLocals) {
    if (scope == null) {
        throw new AssertionError("Missing Scope!");
    }
    int count = 0;
    for (DebugValue actual : scope.getDeclaredValues()) {
        final String name = actual.getName();
        final LLVMDebugValue expected = expectedLocals.get(actual.getName());
        if (expected == null) {
            throw new AssertionError(String.format("Unexpected scope member: %s", name));
        }
        try {
            expected.check(actual);
        } catch (Throwable t) {
            throw new AssertionError(String.format("Error in local %s", name), t);
        }
        count++;
    }
    assertEquals("Unexpected number of scope variables", expectedLocals.size(), count);
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

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