Search in sources :

Example 6 with CommandProcessException

use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.

the class TruffleDebugger method restartFrame.

@Override
public Params restartFrame(long cmdId, String callFrameId, CommandPostProcessor postProcessor) throws CommandProcessException {
    if (callFrameId == null) {
        throw new CommandProcessException("A callFrameId required.");
    }
    int frameId;
    try {
        frameId = Integer.parseInt(callFrameId);
    } catch (NumberFormatException ex) {
        throw new CommandProcessException(ex.getLocalizedMessage());
    }
    DebuggerSuspendedInfo susp = suspendedInfo;
    if (susp != null) {
        if (frameId >= susp.getCallFrames().length) {
            throw new CommandProcessException("Too big callFrameId: " + frameId);
        }
        CallFrame cf = susp.getCallFrames()[frameId];
        susp.getSuspendedEvent().prepareUnwindFrame(cf.getFrame());
        postProcessor.setPostProcessJob(() -> {
            silentResume = true;
            commandLazyResponse = (DebuggerSuspendedInfo suspInfo) -> {
                JSONObject res = new JSONObject();
                res.put("callFrames", getFramesParam(suspInfo.getCallFrames()));
                return new Event(cmdId, new Result(new Params(res)));
            };
            doResume();
        });
    }
    return new Params(null);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) JSONObject(org.json.JSONObject) CallFrame(com.oracle.truffle.tools.chromeinspector.types.CallFrame) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Event(com.oracle.truffle.tools.chromeinspector.events.Event) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Result(com.oracle.truffle.tools.chromeinspector.commands.Result)

Example 7 with CommandProcessException

use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.

the class TruffleDebugger method getScriptSource.

@Override
public Params getScriptSource(String scriptId) throws CommandProcessException {
    if (scriptId == null) {
        throw new CommandProcessException("A scriptId required.");
    }
    Script script;
    try {
        script = slh.getScript(Integer.parseInt(scriptId));
        if (script == null) {
            throw new CommandProcessException("Unknown scriptId: " + scriptId);
        }
    } catch (NumberFormatException nfe) {
        throw new CommandProcessException(nfe.getMessage());
    }
    JSONObject json = new JSONObject();
    json.put("scriptSource", script.getSource().getCharacters());
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) JSONObject(org.json.JSONObject) Params(com.oracle.truffle.tools.chromeinspector.commands.Params)

Example 8 with CommandProcessException

use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException 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 9 with CommandProcessException

use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException 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 10 with CommandProcessException

use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.

the class BreakpointsHandler method createOneShotBreakpoint.

void createOneShotBreakpoint(Location location) throws CommandProcessException {
    Script script = slh.getScript(location.getScriptId());
    if (script == null) {
        throw new CommandProcessException("No script with id '" + location.getScriptId() + "'");
    }
    Breakpoint bp = createBuilder(script.getSource(), location.getLine(), location.getColumn()).oneShot().build();
    ds.install(bp);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Aggregations

CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)11 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)9 JSONObject (org.json.JSONObject)9 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)5 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 Script (com.oracle.truffle.tools.chromeinspector.types.Script)4 JSONArray (org.json.JSONArray)3 TruffleException (com.oracle.truffle.api.TruffleException)2 Source (com.oracle.truffle.api.source.Source)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)2 Location (com.oracle.truffle.tools.chromeinspector.types.Location)2 DebugScope (com.oracle.truffle.api.debug.DebugScope)1 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)1 Result (com.oracle.truffle.tools.chromeinspector.commands.Result)1 Event (com.oracle.truffle.tools.chromeinspector.events.Event)1 URISyntaxException (java.net.URISyntaxException)1