Search in sources :

Example 6 with RemoteObject

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

Example 7 with RemoteObject

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

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