Search in sources :

Example 1 with GuestLanguageException

use of com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException 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 2 with GuestLanguageException

use of com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException 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 3 with GuestLanguageException

use of com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException in project graal by oracle.

the class TruffleRuntime method compileScript.

@Override
public Params compileScript(String expression, String sourceURL, boolean persistScript, long executionContextId) throws CommandProcessException {
    if (expression == null) {
        throw new CommandProcessException("An expression required.");
    }
    JSONObject ret = new JSONObject();
    ScriptsHandler sh = context.getScriptsHandler();
    try {
        if (sh != null) {
            Source source = createSource(expression, sourceURL);
            boolean parsed = false;
            String[] exceptionText = new String[1];
            if (context.getSuspendedInfo() != null) {
                try {
                    parsed = context.executeInSuspendThread(new SuspendThreadExecutable<Boolean>() {

                        @Override
                        public Boolean executeCommand() throws CommandProcessException {
                            try {
                                context.getEnv().parse(source);
                                return true;
                            } catch (Exception ex) {
                                // Didn't manage to parse this
                                exceptionText[0] = ex.getLocalizedMessage();
                                return false;
                            }
                        }
                    });
                } catch (GuestLanguageException ex) {
                    fillExceptionDetails(ret, ex);
                } catch (NoSuspendedThreadException ex) {
                    exceptionText[0] = ex.getLocalizedMessage();
                }
            } else {
                // Parse on the current thread will fail most likely due to a lack of context
                parsed = false;
                exceptionText[0] = "<Not suspended>";
            }
            if (parsed && persistScript) {
                int id = sh.assureLoaded(source);
                ret.put("scriptId", Integer.toString(id));
            }
            if (exceptionText[0] != null) {
                JSONObject exceptionDetails = new JSONObject();
                exceptionDetails.put("text", exceptionText[0]);
                ret.put("exceptionDetails", exceptionDetails);
            }
        }
    } finally {
        context.releaseScriptsHandler();
    }
    return new Params(ret);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) Source(com.oracle.truffle.api.source.Source) 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) JSONObject(org.json.JSONObject) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)

Example 4 with GuestLanguageException

use of com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException 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 5 with GuestLanguageException

use of com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException 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

GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)5 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)5 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)5 JSONObject (org.json.JSONObject)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 TruffleException (com.oracle.truffle.api.TruffleException)1 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 DebugScope (com.oracle.truffle.api.debug.DebugScope)1 Source (com.oracle.truffle.api.source.Source)1 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 JSONArray (org.json.JSONArray)1