use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testLocationBreakpointOnException.
@Test
public void testLocationBreakpointOnException() {
final Source source = testSource("ROOT(\n" + " TRY(STATEMENT(THROW(a, b)), CATCH(a, EXPRESSION)),\n" + " STATEMENT\n" + ")\n");
Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).suspendAnchor(SuspendAnchor.AFTER).build();
try (DebuggerSession session = startSession()) {
session.install(breakpoint);
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertSame(breakpoint, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
DebugException exception = event.getException();
assertEquals("b", exception.getMessage());
CatchLocation catchLocation = exception.getCatchLocation();
assertEquals("TRY(STATEMENT(THROW(a, b))", catchLocation.getSourceSection().getCharacters());
assertEquals(event.getTopStackFrame(), catchLocation.getFrame());
SourceSection throwLocation = exception.getThrowLocation();
assertEquals("THROW(a, b)", throwLocation.getCharacters());
assertEquals("a: b", exception.getExceptionObject().toDisplayString());
});
expectDone();
// Add exception breakpoints to test which breakpoints were hit
Breakpoint uncaughtBreakpoint = Breakpoint.newExceptionBuilder(false, true).build();
Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, false).build();
session.install(uncaughtBreakpoint);
session.install(caughtBreakpoint);
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertEquals(2, event.getBreakpoints().size());
assertSame(caughtBreakpoint, event.getBreakpoints().get(0));
assertSame(breakpoint, event.getBreakpoints().get(1));
DebugException exception = event.getException();
assertEquals("b", exception.getMessage());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testGetRawUncaughtExceptionRestricted.
@Test
public void testGetRawUncaughtExceptionRestricted() {
Source testSource = testSource("STATEMENT(THROW(a, b))");
Breakpoint uncaughtBreakpoint = Breakpoint.newExceptionBuilder(false, true).build();
try (DebuggerSession session = startSession()) {
session.install(uncaughtBreakpoint);
// Exception breakpoints are resolved right
assertTrue(uncaughtBreakpoint.isResolved());
// away
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertSame(uncaughtBreakpoint, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
DebugException exception = event.getException();
// no access from other languages
assertEquals(null, exception.getRawException(ProxyLanguage.class));
});
Throwable t = expectThrowable();
assertEquals("b", t.getMessage());
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class LanguageExceptionsLegacyTest 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();
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugValueIteratorTest method testIterable.
@Test
public void testIterable() throws Throwable {
List<Integer> list = Arrays.asList(1, 2, 3);
Object iterable = new TestIteratorObject(true, false, list);
checkDebugValueOf(iterable, value -> {
assertTrue(value.hasIterator());
assertFalse(value.isIterator());
try {
value.hasIteratorNextElement();
fail();
} catch (DebugException ex) {
// O.K.
}
try {
value.getIteratorNextElement();
fail();
} catch (DebugException ex) {
// O.K.
}
// Iterable's iterator:
DebugValue iterator = value.getIterator();
checkIntIterator(iterator, list);
// The iterator is re-created when obtained again:
iterator = value.getIterator();
checkIntIterator(iterator, list);
});
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class ObjectPreview method create.
private static JSONObject create(DebugValue debugValue, TYPE type, SUBTYPE subtype, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err, boolean isMapEntryKV) {
JSONObject json = new JSONObject();
json.put("type", type.getId());
if (subtype != null) {
json.put("subtype", subtype.getId());
}
boolean isArray = debugValue.isArray();
boolean isMap = debugValue.hasHashEntries();
if (isMapEntryKV) {
String valueStr = RemoteObject.toString(debugValue, allowToStringSideEffects, err);
json.putOpt("description", valueStr);
} else {
DebugValue metaObject = RemoteObject.getMetaObject(debugValue, language, err);
String metaType = null;
if (metaObject != null) {
metaType = RemoteObject.toMetaName(metaObject, err);
if (isArray) {
metaType += "(" + debugValue.getArray().size() + ")";
} else if (isMap) {
metaType += "(" + debugValue.getHashSize() + ")";
}
}
json.putOpt("description", metaType);
}
boolean overflow;
JSONArray properties = new JSONArray();
JSONArray entries = new JSONArray();
if (isArray) {
List<DebugValue> array = debugValue.getArray();
int size = array.size();
overflow = size > OVERFLOW_LIMIT_ARRAY_ELEMENTS;
int n = Math.min(size, OVERFLOW_LIMIT_ARRAY_ELEMENTS);
for (int i = 0; i < n; i++) {
try {
properties.put(createPropertyPreview(array.get(i), allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
} else if (isMap && !isMapEntryKV) {
DebugValue entriesIter = debugValue.getHashEntriesIterator();
overflow = false;
while (entriesIter.hasIteratorNextElement()) {
DebugValue entry = entriesIter.getIteratorNextElement();
JSONObject entryPreview;
try {
entryPreview = createEntryPreview(entry, allowToStringSideEffects, language, err);
} catch (DebugException ex) {
overflow = true;
break;
}
if (entryPreview != null) {
if (entries.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
entries.put(entryPreview);
}
}
} else {
Collection<DebugValue> valueProperties = debugValue.getProperties();
if (valueProperties != null) {
Iterator<DebugValue> propertyIterator = valueProperties.iterator();
overflow = false;
while (propertyIterator.hasNext()) {
DebugValue property = propertyIterator.next();
if (!property.isInternal() && !property.hasReadSideEffects() && property.isReadable()) {
if (properties.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
try {
properties.put(createPropertyPreview(property, allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
}
} else {
overflow = false;
}
}
json.put("overflow", overflow);
json.put("properties", properties);
if (isMap && !isMapEntryKV) {
json.put("entries", entries);
}
return json;
}
Aggregations