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