Search in sources :

Example 6 with NoSuspendedThreadException

use of com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException in project graal by oracle.

the class InspectorDebugger method evaluateOnCallFrame.

@Override
public Params evaluateOnCallFrame(String callFrameId, String expressionOrig, String objectGroup, boolean includeCommandLineAPI, boolean silent, boolean returnByValue, boolean generatePreview, boolean throwOnSideEffect) throws CommandProcessException {
    if (callFrameId == null) {
        throw new CommandProcessException("A callFrameId required.");
    }
    if (expressionOrig == null) {
        throw new CommandProcessException("An expression required.");
    }
    int frameId;
    try {
        frameId = Integer.parseInt(callFrameId);
    } catch (NumberFormatException ex) {
        throw new CommandProcessException(ex.getLocalizedMessage());
    }
    ConsoleUtilitiesAPI cuAPI;
    if (includeCommandLineAPI) {
        cuAPI = ConsoleUtilitiesAPI.parse(expressionOrig);
    } else {
        cuAPI = null;
    }
    final String expression;
    if (cuAPI != null) {
        expression = cuAPI.getExpression();
    } else {
        expression = expressionOrig;
    }
    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();
                if (runSpecialFunctions(expression, cf, json)) {
                    return json;
                }
                DebugValue value = getVarValue(expression, cf);
                if (value == null) {
                    try {
                        value = cf.getFrame().eval(expression);
                        suspendedInfo.refreshFrames();
                    } catch (IllegalStateException ex) {
                    // Not an interactive language
                    }
                }
                if (value == null) {
                    LanguageInfo languageInfo = cf.getFrame().getLanguage();
                    if (languageInfo == null || !languageInfo.isInteractive()) {
                        String errorMessage = getEvalNonInteractiveMessage();
                        ExceptionDetails exceptionDetails = new ExceptionDetails(errorMessage);
                        json.put("exceptionDetails", exceptionDetails.createJSON(context));
                        JSONObject err = new JSONObject();
                        err.putOpt("value", errorMessage);
                        err.putOpt("type", "string");
                        json.put("result", err);
                    }
                }
                if (value != null) {
                    if (cuAPI != null) {
                        value = cuAPI.process(value, breakpointsHandler);
                        if (value == null) {
                            return json;
                        }
                    }
                    RemoteObject ro = new RemoteObject(value, generatePreview, context);
                    context.getRemoteObjectsHandler().register(ro, objectGroup);
                    json.put("result", ro.toJSON());
                }
                return json;
            }

            @Override
            public JSONObject processException(DebugException dex) {
                JSONObject json = new JSONObject();
                InspectorRuntime.fillExceptionDetails(json, dex, context);
                DebugValue exceptionObject = dex.getExceptionObject();
                if (exceptionObject != null) {
                    RemoteObject ro = context.createAndRegister(exceptionObject, generatePreview);
                    json.put("result", ro.toJSON());
                } else {
                    JSONObject err = new JSONObject();
                    err.putOpt("value", dex.getLocalizedMessage());
                    err.putOpt("type", "string");
                    json.put("result", err);
                }
                return json;
            }
        });
    } catch (NoSuspendedThreadException e) {
        jsonResult = new JSONObject();
        JSONObject err = new JSONObject();
        err.putOpt("value", e.getLocalizedMessage());
        jsonResult.put("result", err);
    }
    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) ExceptionDetails(com.oracle.truffle.tools.chromeinspector.types.ExceptionDetails) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException) DebugException(com.oracle.truffle.api.debug.DebugException) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) CallFrame(com.oracle.truffle.tools.chromeinspector.types.CallFrame)

Aggregations

DebugException (com.oracle.truffle.api.debug.DebugException)6 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)6 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)6 DebugValue (com.oracle.truffle.api.debug.DebugValue)5 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)5 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)5 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 DebugScope (com.oracle.truffle.api.debug.DebugScope)3 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)2 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Source (com.oracle.truffle.api.source.Source)1 CallArgument (com.oracle.truffle.tools.chromeinspector.types.CallArgument)1 ExceptionDetails (com.oracle.truffle.tools.chromeinspector.types.ExceptionDetails)1 TypeMark (com.oracle.truffle.tools.chromeinspector.types.RemoteObject.TypeMark)1 Scope (com.oracle.truffle.tools.chromeinspector.types.Scope)1 PrintWriter (java.io.PrintWriter)1