use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class CallFrame method createJSON.
private JSONObject createJSON() {
JSONObject json = new JSONObject();
json.put("callFrameId", Integer.toString(depth));
try {
String functionName = frame.getName();
if (functionName == null) {
functionName = "";
}
json.put("functionName", functionName);
} catch (DebugException ex) {
json.put("functionName", ex.getLocalizedMessage());
}
json.put("location", location.toJSON());
json.putOpt("functionLocation", (functionLocation != null) ? functionLocation.toJSON() : null);
json.put("url", url);
json.put("scopeChain", Scope.createScopesJSON(scopes));
if (thisObject != null) {
json.put("this", thisObject.toJSON());
} else {
json.put("this", JSONObject.NULL);
}
if (returnObject != null) {
json.put("returnValue", returnObject.toJSON());
}
return json;
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class CustomPreview method value2JSON.
public static Object value2JSON(DebugValue value, InspectorExecutionContext context) {
if (value.isArray()) {
JSONArray json = new JSONArray();
List<DebugValue> array = value.getArray();
if (array.size() == 2 && array.get(0).isReadable() && array.get(1).isReadable() && "object".equals(array.get(0).asString()) && array.get(1).getProperty("config") != null) {
// Child object:
json.put(value2JSON(array.get(0), context));
DebugValue child = array.get(1);
DebugValue object = child.getProperty("object");
DebugValue config = child.getProperty("config");
RemoteObject remoteConfig = context.getRemoteObjectsHandler().getRemote(object);
JSONObject childJSON = remoteConfig.toJSON();
JSONObject customPreview = create(object, config, object.getOriginalLanguage(), context);
if (customPreview != null) {
childJSON.put("customPreview", customPreview);
}
json.put(childJSON);
} else {
for (DebugValue element : array) {
if (element.isReadable()) {
json.put(value2JSON(element, context));
} else {
json.put(InspectorExecutionContext.VALUE_NOT_READABLE);
}
}
}
return json;
} else {
Collection<DebugValue> properties = value.getProperties();
if (properties != null) {
JSONObject json = new JSONObject();
for (DebugValue property : properties) {
try {
if (property.isReadable() && !property.canExecute() && !property.isInternal()) {
Object rawValue = getPrimitiveValue(property);
// Do not allow inner objects
if (rawValue != null) {
json.put(property.getName(), rawValue);
}
}
} catch (DebugException ex) {
if (ex.isInternalError()) {
PrintWriter err = context.getErr();
if (err != null) {
ex.printStackTrace(err);
}
} else {
throw ex;
}
}
}
return json;
} else {
return getPrimitiveValue(value);
}
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class CustomPreview method create.
private static JSONObject create(DebugValue debugValue, DebugValue config, LanguageInfo language, InspectorExecutionContext context) {
DebuggerSession debuggerSession = debugValue.getSession();
DebugScope topScope = debuggerSession.getTopScope(language.getId());
DebugValue formatters = null;
while (topScope != null) {
formatters = topScope.getDeclaredValue(DEVTOOLS_FORMATTERS);
if (formatters != null) {
break;
} else {
topScope = topScope.getParent();
}
}
if (formatters == null || !formatters.isArray()) {
return null;
}
for (DebugValue formatter : formatters.getArray()) {
DebugValue headerFunction;
try {
headerFunction = formatter.getProperty(HEADER);
if (headerFunction == null || !headerFunction.canExecute()) {
continue;
}
} catch (DebugException ex) {
continue;
}
DebugValue header = (config != null) ? headerFunction.execute(debugValue, config) : headerFunction.execute(debugValue);
if (header.isNull()) {
continue;
}
boolean hasBody = false;
DebugValue hasBodyFunction;
try {
hasBodyFunction = formatter.getProperty(HAS_BODY);
if (hasBodyFunction != null && hasBodyFunction.canExecute()) {
DebugValue hasBodyValue = (config != null) ? hasBodyFunction.execute(debugValue, config) : hasBodyFunction.execute(debugValue);
hasBody = hasBodyValue.isBoolean() ? hasBodyValue.asBoolean() : false;
}
} catch (DebugException ex) {
PrintWriter err = context.getErr();
if (err != null) {
ex.printStackTrace(err);
}
}
DebugValue bodyFunction = null;
if (hasBody) {
try {
bodyFunction = formatter.getProperty(BODY);
if (bodyFunction != null && !bodyFunction.canExecute()) {
bodyFunction = null;
}
} catch (DebugException ex) {
PrintWriter err = context.getErr();
if (err != null) {
ex.printStackTrace(err);
}
}
}
return createJSON(debugValue, config, header, bodyFunction, context);
}
return null;
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testCaughtException2.
@Test
public void testCaughtException2() {
Source testSource = testSource("ROOT(\n" + "DEFINE(CaughtThrow,\n" + " TRY(STATEMENT(CALL(ThrownNPE)),\n" + " CATCH(NPE, STATEMENT))\n" + "),\n" + "DEFINE(ThrownNPE,\n" + " STATEMENT(THROW(NPE, TestExceptionMessage))\n" + "),\n" + "CALL(CaughtThrow))");
Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, false).build();
try (DebuggerSession session = startSession()) {
session.install(caughtBreakpoint);
assertTrue(caughtBreakpoint.isResolved());
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertSame(caughtBreakpoint, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
DebugException exception = event.getException();
assertEquals("TestExceptionMessage", exception.getMessage());
CatchLocation catchLocation = exception.getCatchLocation();
assertEquals("TRY(STATEMENT(CALL(ThrownNPE))", catchLocation.getSourceSection().getCharacters());
Iterator<DebugStackFrame> stackFrames = event.getStackFrames().iterator();
stackFrames.next();
DebugStackFrame nextFrame = stackFrames.next();
assertEquals(nextFrame, catchLocation.getFrame());
SourceSection throwLocation = exception.getThrowLocation();
assertEquals("THROW(NPE, TestExceptionMessage)", throwLocation.getCharacters());
assertEquals("NPE: TestExceptionMessage", exception.getExceptionObject().toDisplayString());
assertDebugStackTrace(exception.getDebugStackTrace(), "ThrownNPE <7:13, 7:44>", "CaughtThrow <3:17, 3:31>", " <9:1, 9:17>");
assertStack(exception.getStackTrace(), "<instrumentation-test-language>.ThrownNPE(Unnamed:7)", "<instrumentation-test-language>.CaughtThrow(Unnamed:3)", "<instrumentation-test-language>.(Unnamed:9)");
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testEvalExceptional.
@Test
public void testEvalExceptional() {
Source testSource = testSource("ROOT(\n" + " DEFINE(foo,\n" + " STATEMENT\n" + " ),\n" + " CALL(foo)\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT");
try {
event.getTopStackFrame().eval("STATEMENT(THROW(NPE, TestExceptionMessage))");
fail();
} catch (DebugException dex) {
SourceSection throwLocation = dex.getThrowLocation();
assertEquals("THROW(NPE, TestExceptionMessage)", throwLocation.getCharacters());
assertNull(dex.getCatchLocation());
assertEquals("NPE: TestExceptionMessage", dex.getExceptionObject().toDisplayString());
List<DebugStackTraceElement> debugStackTrace = dex.getDebugStackTrace();
assertEquals(2, debugStackTrace.size());
assertEquals("THROW(NPE, TestExceptionMessage)", debugStackTrace.get(0).getSourceSection().getCharacters());
assertEquals("CALL(foo)", debugStackTrace.get(1).getSourceSection().getCharacters());
}
});
}
}
Aggregations