use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugStackFrameTest method testFrameValidity.
@Test
public void testFrameValidity() throws Throwable {
final Source source = testSource("ROOT(\n" + " VARIABLE(a, 42), \n" + " VARIABLE(b, 43), \n" + " VARIABLE(c, 44), \n" + " STATEMENT(),\n" + " STATEMENT()\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
class SharedData {
DebugStackFrame frame;
DebugValue stackValueWithGetValue;
DebugValue stackValueWithIterator;
Iterator<DebugStackFrame> frameIterator2;
DebugValue heapValue;
}
SharedData data = new SharedData();
expectSuspended((SuspendedEvent event) -> {
data.frame = event.getTopStackFrame();
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
assertSame(data.frame, frameIterator.next());
assertFalse(frameIterator.hasNext());
checkStack(data.frame, "a", "42", "b", "43", "c", "44");
// values for verifying state checks
data.frameIterator2 = event.getStackFrames().iterator();
data.stackValueWithGetValue = data.frame.getScope().getDeclaredValue("a");
data.stackValueWithIterator = data.frame.getScope().getDeclaredValues().iterator().next();
// should dynamically create a local variable
data.heapValue = data.frame.eval("VARIABLE(d, 45)");
// should render all pointers invalid
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
// next event everything should be invalidated except heap values
assertInvalidFrame(data.frame);
assertInvalidIterator(data.frameIterator2);
assertInvalidDebugValue(data.stackValueWithGetValue);
assertInvalidDebugValue(data.stackValueWithIterator);
assertEquals("45", data.heapValue.as(String.class));
assertFalse(data.heapValue.isWritable());
assertTrue(data.heapValue.isReadable());
try {
data.heapValue.set(data.heapValue);
fail();
} catch (IllegalStateException e) {
}
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugValueTest method testNumValue.
@Test
public void testNumValue() throws Throwable {
final Source source = testSource("ROOT(\n" + " VARIABLE(a, 42), \n" + " VARIABLE(inf, infinity), \n" + " STATEMENT()\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugValue value42 = frame.getScope().getDeclaredValue("a");
assertEquals("a", value42.getName());
assertFalse(value42.isArray());
assertNull(value42.getArray());
assertNull(value42.getProperties());
assertEquals("Integer", value42.getMetaObject().as(String.class));
assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
SourceSection integerSS = value42.getSourceLocation();
assertEquals("source integer", integerSS.getCharacters());
SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
assertEquals("source infinity", infinitySS.getCharacters());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugValueTest method testValueAttributes.
/**
* Test of {@link DebugValue#isReadable()}, {@link DebugValue#isWritable()} and
* {@link DebugValue#isInternal()}.
*/
@Test
public void testValueAttributes() throws Throwable {
final Source source = testSource("DEFINE(function, ROOT(\n" + " ARGUMENT(a), \n" + " STATEMENT()\n" + "))\n");
Context context = Context.create();
context.eval(source);
Value functionValue = context.getBindings(InstrumentationTestLanguage.ID).getMember("function");
assertNotNull(functionValue);
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
// Test of the default attribute values:
NoAttributesTruffleObject nao = new NoAttributesTruffleObject();
boolean[] suspended = new boolean[] { false };
DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
assertFalse(suspended[0]);
DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
assertNotNull(value);
DebugValue attributesTOValue = value.getProperties().iterator().next();
assertEquals("property", attributesTOValue.getName());
// Property is readable by default
assertTrue(attributesTOValue.isReadable());
// Property is writable by default
assertTrue(attributesTOValue.isWritable());
// Property is not internal by default
assertFalse(attributesTOValue.isInternal());
event.prepareContinue();
suspended[0] = true;
});
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
functionValue.execute(nao);
session.close();
assertTrue(suspended[0]);
// Test of the modified attribute values:
suspended[0] = false;
final ModifiableAttributesTruffleObject mao = new ModifiableAttributesTruffleObject();
session = debugger.startSession((SuspendedEvent event) -> {
assertFalse(suspended[0]);
DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
assertNotNull(value);
DebugValue attributesTOValue = value.getProperties().iterator().next();
assertEquals("property", attributesTOValue.getName());
// All false initially
assertFalse(attributesTOValue.isReadable());
assertFalse(attributesTOValue.isWritable());
assertFalse(attributesTOValue.isInternal());
mao.setIsReadable(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isReadable());
mao.setIsWritable(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isWritable());
mao.setIsInternal(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isInternal());
event.prepareContinue();
suspended[0] = true;
});
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
functionValue.execute(mao);
session.close();
assertTrue(suspended[0]);
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class AbstractDebugTest method checkStack.
protected void checkStack(DebugStackFrame frame, String... expectedFrame) {
Map<String, DebugValue> values = new HashMap<>();
for (DebugValue value : frame) {
values.put(value.getName(), value);
}
Assert.assertEquals(expectedFrame.length / 2, values.size());
for (int i = 0; i < expectedFrame.length; i = i + 2) {
String expectedIdentifier = expectedFrame[i];
String expectedValue = expectedFrame[i + 1];
DebugValue value = values.get(expectedIdentifier);
Assert.assertNotNull(value);
Assert.assertEquals(expectedValue, value.as(String.class));
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class TruffleDebugger method evaluateOnCallFrame.
@Override
public Params evaluateOnCallFrame(String callFrameId, String expression, String objectGroup, boolean includeCommandLineAPI, boolean silent, boolean returnByValue, boolean generatePreview, boolean throwOnSideEffect) throws CommandProcessException {
if (callFrameId == null) {
throw new CommandProcessException("A callFrameId required.");
}
if (expression == null) {
throw new CommandProcessException("An expression required.");
}
int frameId;
try {
frameId = Integer.parseInt(callFrameId);
} catch (NumberFormatException ex) {
throw new CommandProcessException(ex.getLocalizedMessage());
}
JSONObject jsonResult;
try {
jsonResult = context.executeInSuspendThread(new SuspendThreadExecutable<JSONObject>() {
@Override
public JSONObject executeCommand() throws CommandProcessException {
if (frameId >= suspendedInfo.getCallFrames().length) {
throw new CommandProcessException("Too big callFrameId: " + frameId);
}
CallFrame cf = suspendedInfo.getCallFrames()[frameId];
JSONObject json = new JSONObject();
try {
DebugValue value = cf.getFrame().eval(expression);
RemoteObject ro = new RemoteObject(value, context.getErr());
context.getRemoteObjectsHandler().register(ro);
json.put("result", ro.toJSON());
} catch (Throwable t) {
if (t instanceof TruffleException && !((TruffleException) t).isInternalError()) {
JSONObject err = new JSONObject();
err.putOpt("value", t.getLocalizedMessage());
json.put("result", err);
} else {
throw t;
}
}
return json;
}
});
} catch (NoSuspendedThreadException e) {
jsonResult = new JSONObject();
JSONObject err = new JSONObject();
err.putOpt("value", e.getLocalizedMessage());
jsonResult.put("result", err);
} catch (GuestLanguageException e) {
jsonResult = new JSONObject();
TruffleRuntime.fillExceptionDetails(jsonResult, e);
}
return new Params(jsonResult);
}
Aggregations