use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class InspectorRuntime method getProperties.
@Override
public Params getProperties(String objectId, boolean ownProperties, boolean accessorPropertiesOnly, boolean generatePreview) throws CommandProcessException {
if (objectId == null) {
throw new CommandProcessException("An objectId required.");
}
RemoteObject object = context.getRemoteObjectsHandler().getRemote(objectId);
String objectGroup = context.getRemoteObjectsHandler().getObjectGroupOf(objectId);
JSONObject json = new JSONObject();
if (object != null) {
DebugValue value = object.getDebugValue();
RemoteObject.IndexRange indexRange = object.getIndexRange();
try {
if (value != null) {
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
TypeMark typeMark = object.getTypeMark();
if (typeMark != null) {
switch(typeMark) {
case MAP_ENTRIES:
putMapEntries(json, value, indexRange, generatePreview, objectGroup);
break;
case MAP_ENTRY:
putMapEntry(json, value, generatePreview, objectGroup);
break;
default:
throw new CommandProcessException("Unknown type mark " + typeMark);
}
return null;
}
Collection<DebugValue> properties = null;
if (!value.hasHashEntries()) {
properties = value.getProperties();
}
if (properties == null) {
properties = Collections.emptyList();
} else if (indexRange != null && indexRange.isNamed()) {
List<DebugValue> list = new ArrayList<>(properties);
properties = list.subList(indexRange.start(), indexRange.end());
}
Collection<DebugValue> array;
if (!value.isArray()) {
array = Collections.emptyList();
} else if (indexRange != null && !indexRange.isNamed()) {
List<DebugValue> arr = value.getArray();
array = arr.subList(indexRange.start(), indexRange.end());
} else {
array = value.getArray();
}
putResultProperties(json, value, properties, array, generatePreview, objectGroup);
return null;
}
@Override
public Void processException(DebugException ex) {
fillExceptionDetails(json, ex);
return null;
}
});
} else {
final DebugScope scope = object.getScope();
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
Collection<DebugValue> properties = new ArrayList<>();
DebugValue scopeReceiver = object.getScopeReceiver();
if (scopeReceiver != null) {
properties.add(scopeReceiver);
}
for (DebugValue p : scope.getDeclaredValues()) {
properties.add(p);
}
putResultProperties(json, null, properties, Collections.emptyList(), generatePreview, objectGroup);
return null;
}
@Override
public Void processException(DebugException ex) {
fillExceptionDetails(json, ex);
return null;
}
});
}
} catch (NoSuspendedThreadException ex) {
// Not suspended, no properties
json.put("result", new JSONArray());
}
}
return new Params(json);
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugValueHashMapTest method checkIntEntriesIterator.
static void checkIntEntriesIterator(DebugValue iterator, Collection<Map.Entry<HashElement, Object>> entries) {
assertTrue(iterator.isIterator());
// it's not iterable
assertFalse(iterator.hasIterator());
try {
iterator.getIterator();
fail();
} catch (DebugException ex) {
// O.K.
}
for (Map.Entry<HashElement, Object> entry : entries) {
assertTrue(iterator.hasIteratorNextElement());
DebugValue entryArray = iterator.getIteratorNextElement();
assertTrue(entryArray.isArray());
List<DebugValue> array = entryArray.getArray();
assertEquals(2, array.size());
DebugValue key = array.get(0);
DebugValue value = array.get(1);
assertTrue(key.isReadable());
assertEquals(entry.getKey().isRemovable(), key.isWritable());
assertEquals(entry.getKey().getKey(), key.asInt());
assertEquals(entry.getKey().isReadable(), value.isReadable());
assertEquals(entry.getKey().isWritable(), value.isWritable());
if (entry.getKey().isReadable()) {
assertEquals(entry.getValue(), value.asInt());
} else {
try {
value.asInt();
fail();
} catch (UnsupportedOperationException ex) {
// O.K.
}
}
}
assertFalse(iterator.hasIteratorNextElement());
try {
iterator.getIteratorNextElement();
fail();
} catch (NoSuchElementException ex) {
// O.K.
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testUncaughtException1.
@Test
public void testUncaughtException1() {
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();
assertNull(exception.getCatchLocation());
assertEquals("b", exception.getMessage());
SourceSection throwLocation = exception.getThrowLocation();
assertEquals(10, throwLocation.getCharIndex());
assertEquals(21, throwLocation.getCharEndIndex());
assertEquals("a: b", exception.getExceptionObject().toDisplayString());
assertDebugStackTrace(exception.getDebugStackTrace(), " <1:11, 1:21>");
assertStack(exception.getStackTrace(), "<instrumentation-test-language>.(Unnamed:1)");
});
Throwable t = expectThrowable();
assertEquals("b", t.getMessage());
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testUncaughtException2.
@Test
public void testUncaughtException2() {
Source testSource = testSource("ROOT(\n" + "DEFINE(UncaughtThrow,\n" + " TRY(STATEMENT, STATEMENT(THROW(IllegalState, TestExceptionMessage)),\n" + " CATCH(a, STATEMENT))\n" + "),\n" + "CALL(UncaughtThrow))");
Breakpoint uncaughtBreakpoint = Breakpoint.newExceptionBuilder(false, true).build();
try (DebuggerSession session = startSession()) {
session.install(uncaughtBreakpoint);
assertTrue(uncaughtBreakpoint.isResolved());
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertSame(uncaughtBreakpoint, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
DebugException exception = event.getException();
assertNull(exception.getCatchLocation());
assertEquals("TestExceptionMessage", exception.getMessage());
SourceSection throwLocation = exception.getThrowLocation();
assertEquals("THROW(IllegalState, TestExceptionMessage)", throwLocation.getCharacters());
assertEquals("IllegalState: TestExceptionMessage", exception.getExceptionObject().toDisplayString());
assertDebugStackTrace(exception.getDebugStackTrace(), "UncaughtThrow <3:28, 3:68>", " <6:1, 6:19>");
assertStack(exception.getStackTrace(), "<instrumentation-test-language>.UncaughtThrow(Unnamed:3)", "<instrumentation-test-language>.(Unnamed:6)");
});
Throwable t = expectThrowable();
assertEquals("TestExceptionMessage", t.getMessage());
}
}
use of com.oracle.truffle.api.debug.DebugException in project graal by oracle.
the class DebugExceptionTest method testCaughtException1.
@Test
public void testCaughtException1() {
Source testSource = testSource("TRY(STATEMENT(THROW(NPE, TestExceptionMessage)), CATCH(NPE, STATEMENT))\n");
Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, true).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(THROW(NPE, TestExceptionMessage))", catchLocation.getSourceSection().getCharacters());
assertEquals(event.getTopStackFrame(), catchLocation.getFrame());
SourceSection throwLocation = exception.getThrowLocation();
assertEquals("THROW(NPE, TestExceptionMessage)", throwLocation.getCharacters());
assertEquals("NPE: TestExceptionMessage", exception.getExceptionObject().toDisplayString());
assertDebugStackTrace(exception.getDebugStackTrace(), " <1:15, 1:46>");
assertStack(exception.getStackTrace(), "<instrumentation-test-language>.(Unnamed:1)");
});
expectDone();
}
}
Aggregations