Search in sources :

Example 1 with Scope

use of com.oracle.truffle.tools.dap.types.Scope in project graal by oracle.

the class StackFramesHandler method getScopes.

public List<Scope> getScopes(ThreadsHandler.SuspendedThreadInfo info, int frameId) {
    FrameWrapper frameWrapper = info.getById(FrameWrapper.class, frameId);
    DebugStackFrame frame = frameWrapper != null ? frameWrapper.getFrame() : null;
    if (frame != null) {
        List<Scope> scopes = new ArrayList<>();
        DebugScope dscope;
        try {
            dscope = frame.getScope();
        } catch (DebugException ex) {
            PrintWriter err = context.getErr();
            if (err != null) {
                err.println("getScope() has caused " + ex);
                ex.printStackTrace(err);
            }
            dscope = null;
        }
        String scopeName = "Block";
        boolean wasFunction = false;
        ScopeWrapper topScopeWrapper = null;
        DebugValue thisValue = null;
        while (dscope != null) {
            if (wasFunction) {
                scopeName = "Closure";
            } else if (dscope.isFunctionScope()) {
                scopeName = "Local";
                thisValue = dscope.getReceiver();
                wasFunction = true;
            }
            if (dscope.isFunctionScope() || dscope.getDeclaredValues().iterator().hasNext()) {
                // provide only scopes that have some variables
                if (scopes.isEmpty()) {
                    topScopeWrapper = new ScopeWrapper(frameWrapper, dscope);
                    scopes.add(Scope.create(scopeName, info.getId(topScopeWrapper), false));
                } else {
                    scopes.add(Scope.create(scopeName, info.getId(new ScopeWrapper(frameWrapper, dscope)), false));
                }
            }
            dscope = getParent(dscope);
        }
        if (thisValue != null && topScopeWrapper != null) {
            topScopeWrapper.thisValue = thisValue;
        }
        try {
            dscope = debuggerSession.getTopScope(frame.getSourceSection().getSource().getLanguage());
        } catch (DebugException ex) {
            PrintWriter err = context.getErr();
            if (err != null) {
                err.println("getTopScope() has caused " + ex);
                ex.printStackTrace(err);
            }
        }
        while (dscope != null) {
            if (dscope.isFunctionScope() || dscope.getDeclaredValues().iterator().hasNext()) {
                // provide only scopes that have some variables
                scopes.add(Scope.create("Global", info.getId(dscope), true));
            }
            dscope = getParent(dscope);
        }
        return scopes;
    }
    return null;
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebugScope(com.oracle.truffle.api.debug.DebugScope) Scope(com.oracle.truffle.tools.dap.types.Scope) DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugValue(com.oracle.truffle.api.debug.DebugValue) ArrayList(java.util.ArrayList) DebugException(com.oracle.truffle.api.debug.DebugException) PrintWriter(java.io.PrintWriter)

Aggregations

DebugException (com.oracle.truffle.api.debug.DebugException)1 DebugScope (com.oracle.truffle.api.debug.DebugScope)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 DebugValue (com.oracle.truffle.api.debug.DebugValue)1 Scope (com.oracle.truffle.tools.dap.types.Scope)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1