use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class VariablesHandler method getDebugValue.
static DebugValue getDebugValue(DebugStackFrame frame, String value) {
try {
return frame.eval(value);
} catch (DebugException de) {
}
DebugValue receiver = frame.getScope().getReceiver();
if (receiver != null && value.equals(receiver.getName())) {
return receiver;
}
DebugScope scope = frame.getScope();
while (scope != null) {
DebugValue debugValue = scope.getDeclaredValue(value);
if (debugValue != null) {
return debugValue;
}
scope = scope.getParent();
}
return null;
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class RemoteObject method initFromValue.
private boolean initFromValue() {
DebugValue debugValue = valueValue;
LanguageInfo originalLanguage = debugValue.getOriginalLanguage();
// Setup the object with a language-specific value
if (originalLanguage != null) {
debugValue = debugValue.asInLanguage(originalLanguage);
}
PrintWriter err = context != null ? context.getErr() : null;
this.typeInfo = TypeInfo.fromValue(debugValue, typeMark, originalLanguage, err);
boolean readable = debugValue.isReadable();
String toString;
boolean addType = true;
Object rawValue = null;
String unserializable = null;
boolean replicableRawValue = true;
try {
if (typeInfo.subtype == SUBTYPE.INTERNAL_ENTRY) {
toString = createMapEntryDescription(debugValue, context.areToStringSideEffectsAllowed(), err);
addType = false;
} else if (readable) {
SourceSection sourceSection;
if (typeInfo.isFunction && (sourceSection = debugValue.getSourceLocation()) != null && sourceSection.isAvailable() && sourceSection.getSource().hasCharacters()) {
toString = sourceSection.getCharacters().toString();
addType = false;
} else {
toString = debugValue.toDisplayString(context.areToStringSideEffectsAllowed());
if (typeInfo.type == TYPE.STRING || typeInfo.type == TYPE.SYMBOL) {
// The whole description is rendered as a String in quotes, or highlighted
// as a symbol. Do not prepend the type.
addType = false;
}
}
} else {
toString = InspectorExecutionContext.VALUE_NOT_READABLE;
replicableRawValue = false;
}
if (readable && !typeInfo.isObject) {
if (typeInfo.subtype == SUBTYPE.NULL && typeInfo.type == TYPE.OBJECT) {
replicableRawValue = false;
} else if (typeInfo.type == TYPE.UNDEFINED) {
replicableRawValue = false;
} else {
if (debugValue.isBoolean()) {
rawValue = debugValue.asBoolean();
} else if (debugValue.isNumber()) {
rawValue = TypeInfo.toNumber(debugValue);
if (!isFinite((Number) rawValue)) {
unserializable = rawValue.toString();
rawValue = null;
}
} else {
replicableRawValue = false;
rawValue = toString;
}
}
}
} catch (DebugException ex) {
if (err != null && ex.isInternalError()) {
err.println(debugValue.getName() + " toDisplayString() has caused: " + ex);
ex.printStackTrace(err);
}
throw ex;
}
this.value = rawValue;
this.replicableValue = replicableRawValue;
this.unserializableValue = unserializable;
if (addType && typeInfo.descriptionType != null && !typeInfo.descriptionType.equals(toString)) {
this.description = typeInfo.descriptionType + ((toString != null && !toString.isEmpty()) ? " " + toString : "");
} else {
this.description = toString;
}
if (typeInfo.isObject && addType && typeInfo.isJS && generatePreview) {
try {
this.preview = ObjectPreview.create(debugValue, typeInfo.type, typeInfo.subtype, context.areToStringSideEffectsAllowed(), originalLanguage, err);
} catch (DebugException ex) {
if (err != null && ex.isInternalError()) {
err.println(debugValue.getName() + " preview has caused: " + ex);
ex.printStackTrace(err);
}
}
}
if (readable && context != null && context.isCustomObjectFormatterEnabled()) {
if (originalLanguage != null) {
try {
this.customPreview = CustomPreview.create(debugValue, originalLanguage, context);
} catch (DebugException ex) {
if (err != null) {
if (ex.isInternalError()) {
err.println(debugValue.getName() + " custom preview has caused: " + ex);
ex.printStackTrace(err);
} else {
err.println("Custom Formatter Failed: " + ex.getLocalizedMessage());
}
}
}
}
}
return typeInfo.isObject;
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class RemoteObject method createJSONResultValue.
/**
* Create a JSON object representing the provided {@link DebugValue}. Use when a reply by value
* is requested.
*/
public static JSONObject createJSONResultValue(DebugValue debugValue, boolean allowToStringSideEffects, PrintWriter err) {
JSONObject json = new JSONObject();
DebugValue metaObject = getMetaObject(debugValue, null, err);
boolean isObject = TypeInfo.isObject(debugValue, err);
boolean isJS = LanguageChecks.isJS(debugValue.getOriginalLanguage());
String vtype = null;
if (metaObject != null & isJS) {
try {
Collection<DebugValue> properties = metaObject.getProperties();
if (properties != null) {
for (DebugValue prop : properties) {
String name = prop.getName();
if ("type".equals(name)) {
vtype = toMetaName(prop, err);
}
}
}
} catch (DebugException ex) {
if (err != null && ex.isInternalError()) {
err.println("getProperties of meta object of (" + debugValue.getName() + ") has caused: " + ex);
ex.printStackTrace(err);
}
throw ex;
}
}
if (vtype == null) {
if (isObject) {
vtype = "object";
} else {
vtype = (metaObject != null) ? toString(metaObject, allowToStringSideEffects, err) : "object";
}
}
json.put("type", vtype);
String[] unserializablePtr = new String[1];
try {
json.putOpt("value", createJSONValue(debugValue, allowToStringSideEffects, unserializablePtr, err));
} catch (DebugException ex) {
if (err != null && ex.isInternalError()) {
err.println("getProperties(" + debugValue.getName() + ") has caused: " + ex);
ex.printStackTrace(err);
}
throw ex;
}
json.putOpt("unserializableValue", unserializablePtr[0]);
return json;
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class LanguageExceptionsTest method testBuggyLanguageCalls.
private void testBuggyLanguageCalls(ProxyLanguage language, SuspendedCallback callback, String prefix) {
ProxyLanguage.setDelegate(language);
DebuggerSession session = tester.startSession();
session.suspendNextExecution();
Source source = Source.create(ProxyLanguage.ID, prefix + "1");
tester.startEval(source);
tester.expectSuspended((SuspendedEvent event) -> {
try {
callback.onSuspend(event);
Assert.fail("No DebugException is thrown!");
} catch (DebugException dex) {
Assert.assertEquals("1", dex.getLocalizedMessage());
verifyExStack(dex, IllegalStateException.class.getName());
} catch (Throwable t) {
Assert.fail(t.getLocalizedMessage());
}
});
tester.expectDone();
source = Source.create(ProxyLanguage.ID, prefix + "2");
session.suspendNextExecution();
tester.startEval(source);
tester.expectSuspended((SuspendedEvent event) -> {
try {
callback.onSuspend(event);
Assert.fail("No DebugException is thrown!");
} catch (DebugException dex) {
Assert.assertEquals("A TruffleException", dex.getLocalizedMessage());
Assert.assertNull(Objects.toString(dex.getCause()), dex.getCause());
} catch (Throwable t) {
Assert.fail(t.getLocalizedMessage());
}
});
tester.expectDone();
source = Source.create(ProxyLanguage.ID, prefix + "3");
session.suspendNextExecution();
tester.startEval(source);
tester.expectSuspended((SuspendedEvent event) -> {
try {
callback.onSuspend(event);
Assert.fail("No DebugException is thrown!");
} catch (DebugException dex) {
Assert.assertEquals("3", dex.getLocalizedMessage());
verifyExStack(dex, AssertionError.class.getName());
} catch (Throwable t) {
Assert.fail(t.getLocalizedMessage());
}
});
tester.expectDone();
}
Aggregations