Search in sources :

Example 1 with CallFrame

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

the class TruffleDebugger method createCallFrames.

private CallFrame[] createCallFrames(Iterable<DebugStackFrame> frames) {
    List<CallFrame> cfs = new ArrayList<>();
    int depth = 0;
    for (DebugStackFrame frame : frames) {
        SourceSection sourceSection = frame.getSourceSection();
        if (sourceSection == null) {
            continue;
        }
        if (frame.isInternal()) {
            continue;
        }
        Source source = sourceSection.getSource();
        if (source.isInternal()) {
            // should not be, double-check
            continue;
        }
        slh.assureLoaded(source);
        Script script = slh.getScript(slh.getScriptId(source));
        List<Scope> scopes = new ArrayList<>();
        DebugScope dscope;
        try {
            dscope = frame.getScope();
        } catch (Exception ex) {
            PrintWriter err = context.getErr();
            if (err != null) {
                err.println("getScope() has caused " + ex);
                ex.printStackTrace(err);
            }
            dscope = null;
        }
        String scopeType = "block";
        boolean wasFunction = false;
        SourceSection functionSourceSection = null;
        while (dscope != null) {
            if (wasFunction) {
                scopeType = "closure";
            } else if (dscope.isFunctionScope()) {
                scopeType = "local";
                functionSourceSection = dscope.getSourceSection();
                wasFunction = true;
            }
            if (dscope.isFunctionScope() || dscope.getDeclaredValues().iterator().hasNext()) {
                // provide only scopes that have some variables
                scopes.add(createScope(scopeType, dscope));
            }
            dscope = getParent(dscope);
        }
        try {
            dscope = ds.getTopScope(source.getLanguage());
        } catch (Exception ex) {
            PrintWriter err = context.getErr();
            if (err != null) {
                err.println("getTopScope() has caused " + ex);
                ex.printStackTrace(err);
            }
        }
        while (dscope != null) {
            if (dscope.getDeclaredValues().iterator().hasNext()) {
                // provide only scopes that have some variables
                scopes.add(createScope("global", dscope));
            }
            dscope = getParent(dscope);
        }
        CallFrame cf = new CallFrame(frame, depth++, script, sourceSection, functionSourceSection, null, scopes.toArray(new Scope[scopes.size()]));
        cfs.add(cf);
    }
    return cfs.toArray(new CallFrame[cfs.size()]);
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Script(com.oracle.truffle.tools.chromeinspector.types.Script) ArrayList(java.util.ArrayList) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Source(com.oracle.truffle.api.source.Source) CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) TruffleException(com.oracle.truffle.api.TruffleException) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException) DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugScope(com.oracle.truffle.api.debug.DebugScope) Scope(com.oracle.truffle.tools.chromeinspector.types.Scope) CallFrame(com.oracle.truffle.tools.chromeinspector.types.CallFrame) SourceSection(com.oracle.truffle.api.source.SourceSection) PrintWriter(java.io.PrintWriter)

Example 2 with CallFrame

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

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

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)3 TruffleException (com.oracle.truffle.api.TruffleException)2 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)2 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)2 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)2 JSONObject (org.json.JSONObject)2 DebugScope (com.oracle.truffle.api.debug.DebugScope)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 DebugValue (com.oracle.truffle.api.debug.DebugValue)1 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)1 Source (com.oracle.truffle.api.source.Source)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 Result (com.oracle.truffle.tools.chromeinspector.commands.Result)1 Event (com.oracle.truffle.tools.chromeinspector.events.Event)1 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)1 Scope (com.oracle.truffle.tools.chromeinspector.types.Scope)1 Script (com.oracle.truffle.tools.chromeinspector.types.Script)1 PrintWriter (java.io.PrintWriter)1