Search in sources :

Example 1 with DebugScope

use of com.oracle.truffle.api.debug.DebugScope in project graal by oracle.

the class DebugScopeTest method testTopScope.

// Local scopes are well tested by DebugStackFrameTest and others.
@Test
public void testTopScope() {
    final Source source = testSource("ROOT(DEFINE(function1,ROOT(\n" + "  EXPRESSION()\n" + "  )\n" + "),\n" + "DEFINE(g,ROOT(\n" + "  EXPRESSION()\n" + "  )\n" + "),\n" + "STATEMENT())\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugScope topScope = session.getTopScope(event.getSourceSection().getSource().getLanguage());
            assertNotNull(topScope);
            DebugValue function1 = topScope.getDeclaredValue("function1");
            assertNotNull(function1);
            assertTrue(function1.as(String.class).contains("Function"));
            DebugValue functionType = function1.getMetaObject();
            assertEquals("Function", functionType.as(String.class));
            assertEquals(function1.getOriginalLanguage(), functionType.getOriginalLanguage());
            DebugValue g = topScope.getDeclaredValue("g");
            assertNotNull(g);
            assertTrue(g.as(String.class).contains("Function"));
        });
        expectDone();
    }
}
Also used : DebugScope(com.oracle.truffle.api.debug.DebugScope) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 2 with DebugScope

use of com.oracle.truffle.api.debug.DebugScope in project graal by oracle.

the class TruffleDebugger method createScope.

private Scope createScope(String scopeType, DebugScope dscope) {
    RemoteObject scopeVars = new RemoteObject(dscope);
    context.getRemoteObjectsHandler().register(scopeVars);
    return new Scope(scopeType, scopeVars, dscope.getName(), null, null);
}
Also used : RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) DebugScope(com.oracle.truffle.api.debug.DebugScope) Scope(com.oracle.truffle.tools.chromeinspector.types.Scope)

Example 3 with DebugScope

use of com.oracle.truffle.api.debug.DebugScope 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 4 with DebugScope

use of com.oracle.truffle.api.debug.DebugScope 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 5 with DebugScope

use of com.oracle.truffle.api.debug.DebugScope in project graal by oracle.

the class DebugALot method logFrame.

private void logFrame(String prefix, DebugStackFrame frame) {
    logger.print(frame.getName());
    if (frame.isInternal()) {
        logger.print(" [Internal]");
    }
    logSourceSection(frame.getSourceSection());
    List<DebugScope> scopes = new ArrayList<>();
    for (DebugScope scope = frame.getScope(); scope != null; scope = scope.getParent()) {
        scopes.add(scope);
    }
    logger.print(prefix);
    logger.print("Scopes: ");
    logger.println(scopes.size());
    for (int i = 0; i < scopes.size(); i++) {
        logger.print(prefix);
        logger.print(i + 1);
        logger.print(". ");
        int offset = prefix.length() + Integer.toString(i + 1).length() + 2;
        String scopePrefix = getPrefix(offset);
        logScope(scopePrefix, scopes.get(i), (i == 0) ? frame : null);
    }
}
Also used : DebugScope(com.oracle.truffle.api.debug.DebugScope) ArrayList(java.util.ArrayList)

Aggregations

DebugScope (com.oracle.truffle.api.debug.DebugScope)12 DebugValue (com.oracle.truffle.api.debug.DebugValue)9 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)7 Source (org.graalvm.polyglot.Source)6 Test (org.junit.Test)6 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)5 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)5 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)2 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)2 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)2 Scope (com.oracle.truffle.tools.chromeinspector.types.Scope)2 ArrayList (java.util.ArrayList)2 TruffleException (com.oracle.truffle.api.TruffleException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 Source (com.oracle.truffle.api.source.Source)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)1