Search in sources :

Example 1 with RemoteObject

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject in project graal by oracle.

the class TruffleDebugger method createScope.

private Scope createScope(String scopeType, DebugScope dscope) {
    RemoteObject scopeVars = new RemoteObject(dscope);
    context.getRemoteObjectsHandler().register(scopeVars);
    return new Scope(scopeType, scopeVars, dscope.getName(), null, null);
}
Also used : RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) DebugScope(com.oracle.truffle.api.debug.DebugScope) Scope(com.oracle.truffle.tools.chromeinspector.types.Scope)

Example 2 with RemoteObject

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject in project graal by oracle.

the class TruffleRuntime method evaluate.

@Override
public Params evaluate(String expression, String objectGroup, boolean includeCommandLineAPI, boolean silent, int contextId, boolean returnByValue, boolean awaitPromise) throws CommandProcessException {
    if (expression == null) {
        throw new CommandProcessException("An expression required.");
    }
    JSONObject json = new JSONObject();
    DebuggerSuspendedInfo suspendedInfo = context.getSuspendedInfo();
    if (suspendedInfo != null) {
        try {
            context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {

                @Override
                public Void executeCommand() throws CommandProcessException {
                    JSONObject result;
                    DebugValue value = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(expression);
                    if (returnByValue) {
                        result = RemoteObject.createJSONResultValue(value, context.getErr());
                    } else {
                        RemoteObject ro = new RemoteObject(value, context.getErr());
                        context.getRemoteObjectsHandler().register(ro);
                        result = ro.toJSON();
                    }
                    json.put("result", result);
                    return null;
                }
            });
        } catch (NoSuspendedThreadException ex) {
            JSONObject exceptionDetails = new JSONObject();
            exceptionDetails.put("text", ex.getLocalizedMessage());
            json.put("exceptionDetails", exceptionDetails);
        } catch (GuestLanguageException ex) {
            fillExceptionDetails(json, ex);
        }
    } else {
        JSONObject exceptionDetails = new JSONObject();
        exceptionDetails.put("text", "<Not suspended>");
        json.put("exceptionDetails", exceptionDetails);
    }
    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 3 with RemoteObject

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject 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 4 with RemoteObject

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject in project graal by oracle.

the class TruffleRuntime method createPropertyJSON.

private JSONObject createPropertyJSON(DebugValue v, String defaultName) {
    PropertyDescriptor pd;
    RemoteObject rv = new RemoteObject(v, context.getErr());
    context.getRemoteObjectsHandler().register(rv);
    String name = v.getName();
    if (name == null && defaultName != null) {
        name = defaultName;
    }
    if (!v.isInternal()) {
        pd = new PropertyDescriptor(name, rv, v.isWritable(), null, null, true, true, null, true, null);
        return pd.toJSON();
    } else {
        InternalPropertyDescriptor ipd = new InternalPropertyDescriptor(name, rv);
        return ipd.toJSON();
    }
}
Also used : RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) InternalPropertyDescriptor(com.oracle.truffle.tools.chromeinspector.types.InternalPropertyDescriptor) PropertyDescriptor(com.oracle.truffle.tools.chromeinspector.types.PropertyDescriptor) InternalPropertyDescriptor(com.oracle.truffle.tools.chromeinspector.types.InternalPropertyDescriptor)

Example 5 with RemoteObject

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject in project graal by oracle.

the class RemoteObjectsHandler method getRemote.

RemoteObject getRemote(DebugValue value) {
    RemoteObject remote;
    synchronized (remotesByIDs) {
        remote = remotesByValue.get(value);
        if (remote == null) {
            remote = new RemoteObject(value, err);
            remotesByValue.put(value, remote);
            remotesByIDs.put(remote.getId(), remote);
        }
    }
    return remote;
}
Also used : RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject)

Aggregations

RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)7 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)4 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)4 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)4 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)4 JSONObject (org.json.JSONObject)4 DebugScope (com.oracle.truffle.api.debug.DebugScope)2 TruffleException (com.oracle.truffle.api.TruffleException)1 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)1 InternalPropertyDescriptor (com.oracle.truffle.tools.chromeinspector.types.InternalPropertyDescriptor)1 PropertyDescriptor (com.oracle.truffle.tools.chromeinspector.types.PropertyDescriptor)1 Scope (com.oracle.truffle.tools.chromeinspector.types.Scope)1 Collection (java.util.Collection)1 JSONArray (org.json.JSONArray)1