use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.
the class TruffleDebugger method getPossibleBreakpoints.
@Override
public Params getPossibleBreakpoints(Location start, Location end, boolean restrictToFunction) throws CommandProcessException {
int scriptId = start.getScriptId();
if (scriptId != end.getScriptId()) {
throw new CommandProcessException("Different location scripts: " + scriptId + ", " + end.getScriptId());
}
Script script = slh.getScript(scriptId);
if (script == null) {
throw new CommandProcessException("Unknown scriptId: " + scriptId);
}
Source source = script.getSource();
int o1 = source.getLineStartOffset(start.getLine());
if (start.getColumn() > 0) {
o1 += start.getColumn() - 1;
}
int o2;
if (end.getLine() > source.getLineCount()) {
o2 = source.getLength();
} else {
o2 = source.getLineStartOffset(end.getLine());
if (end.getColumn() > 0) {
o2 += end.getColumn() - 1;
}
}
SourceSection range = source.createSection(o1, o2 - o1);
Iterable<SourceSection> locations = SuspendableLocationFinder.findSuspendableLocations(range, restrictToFunction, context.getEnv());
JSONObject json = new JSONObject();
JSONArray arr = new JSONArray();
for (SourceSection ss : locations) {
arr.put(new Location(scriptId, ss.getStartLine(), ss.getStartColumn()).toJSON());
}
json.put("locations", arr);
return new Params(json);
}
use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.
the class TruffleExecutionContext method executeInSuspendThread.
<T> T executeInSuspendThread(SuspendThreadExecutable<T> executable) throws NoSuspendedThreadException, GuestLanguageException, CommandProcessException {
CompletableFuture<T> cf = new CompletableFuture<>();
suspendThreadExecutor.execute(new CancellableRunnable() {
@Override
public void run() {
T params = null;
try {
params = executable.executeCommand();
cf.complete(params);
} catch (ThreadDeath td) {
cf.completeExceptionally(td);
throw td;
} catch (Throwable t) {
cf.completeExceptionally(t);
}
}
@Override
public void cancel() {
cf.completeExceptionally(new NoSuspendedThreadException("Resuming..."));
}
});
T params;
try {
params = cf.get();
} catch (ExecutionException ex) {
Throwable cause = ex.getCause();
if (cause instanceof TruffleException && !((TruffleException) cause).isInternalError()) {
throw new GuestLanguageException((TruffleException) cause);
}
if (cause instanceof CommandProcessException) {
throw (CommandProcessException) cause;
}
if (cause instanceof NoSuspendedThreadException) {
throw (NoSuspendedThreadException) cause;
}
if (err != null) {
cause.printStackTrace(err);
}
throw new CommandProcessException(ex.getLocalizedMessage());
} catch (InterruptedException ex) {
throw new CommandProcessException(ex.getLocalizedMessage());
}
return params;
}
use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException in project graal by oracle.
the class TruffleRuntime method evaluate.
@Override
public Params evaluate(String expression, String objectGroup, boolean includeCommandLineAPI, boolean silent, int contextId, boolean returnByValue, boolean awaitPromise) throws CommandProcessException {
if (expression == null) {
throw new CommandProcessException("An expression required.");
}
JSONObject json = new JSONObject();
DebuggerSuspendedInfo suspendedInfo = context.getSuspendedInfo();
if (suspendedInfo != null) {
try {
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
JSONObject result;
DebugValue value = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(expression);
if (returnByValue) {
result = RemoteObject.createJSONResultValue(value, context.getErr());
} else {
RemoteObject ro = new RemoteObject(value, context.getErr());
context.getRemoteObjectsHandler().register(ro);
result = ro.toJSON();
}
json.put("result", result);
return null;
}
});
} catch (NoSuspendedThreadException ex) {
JSONObject exceptionDetails = new JSONObject();
exceptionDetails.put("text", ex.getLocalizedMessage());
json.put("exceptionDetails", exceptionDetails);
} catch (GuestLanguageException ex) {
fillExceptionDetails(json, ex);
}
} else {
JSONObject exceptionDetails = new JSONObject();
exceptionDetails.put("text", "<Not suspended>");
json.put("exceptionDetails", exceptionDetails);
}
return new Params(json);
}
use of com.oracle.truffle.tools.chromeinspector.server.CommandProcessException 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.tools.chromeinspector.server.CommandProcessException in project graal by oracle.
the class TruffleRuntime method compileScript.
@Override
public Params compileScript(String expression, String sourceURL, boolean persistScript, long executionContextId) throws CommandProcessException {
if (expression == null) {
throw new CommandProcessException("An expression required.");
}
JSONObject ret = new JSONObject();
ScriptsHandler sh = context.getScriptsHandler();
try {
if (sh != null) {
Source source = createSource(expression, sourceURL);
boolean parsed = false;
String[] exceptionText = new String[1];
if (context.getSuspendedInfo() != null) {
try {
parsed = context.executeInSuspendThread(new SuspendThreadExecutable<Boolean>() {
@Override
public Boolean executeCommand() throws CommandProcessException {
try {
context.getEnv().parse(source);
return true;
} catch (Exception ex) {
// Didn't manage to parse this
exceptionText[0] = ex.getLocalizedMessage();
return false;
}
}
});
} catch (GuestLanguageException ex) {
fillExceptionDetails(ret, ex);
} catch (NoSuspendedThreadException ex) {
exceptionText[0] = ex.getLocalizedMessage();
}
} else {
// Parse on the current thread will fail most likely due to a lack of context
parsed = false;
exceptionText[0] = "<Not suspended>";
}
if (parsed && persistScript) {
int id = sh.assureLoaded(source);
ret.put("scriptId", Integer.toString(id));
}
if (exceptionText[0] != null) {
JSONObject exceptionDetails = new JSONObject();
exceptionDetails.put("text", exceptionText[0]);
ret.put("exceptionDetails", exceptionDetails);
}
}
} finally {
context.releaseScriptsHandler();
}
return new Params(ret);
}
Aggregations