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;
}
Aggregations