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();
}
}
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);
}
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()]);
}
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);
}
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);
}
}
Aggregations