use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugALot method logValues.
private void logValues(String prefix, List<DebugValue> values) {
for (int i = 0; i < values.size(); i++) {
logger.print(prefix);
logger.print(i + 1);
logger.print(". ");
DebugValue v = values.get(i);
logger.print(v.getName());
logger.print(" = ");
logger.println(v.as(String.class));
int offset = prefix.length() + Integer.toString(i + 1).length() + 2;
String valuePrefix = getPrefix(offset);
logValue(valuePrefix, v);
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugALot method testEval.
private void testEval(String prefix, DebugStackFrame frame, List<DebugValue> values) {
for (DebugValue v : values) {
DebugValue ev = frame.eval(v.getName());
String value = v.as(String.class);
String evalue = ev.as(String.class);
if (!value.equals(evalue)) {
hasFailed = true;
logger.print(prefix);
logger.print("ERROR: local value '");
logger.print(v.getName());
logger.print("' has value '");
logger.print(v.as(String.class));
logger.print("' but evaluated to '");
logger.print(ev.as(String.class));
logger.println("'");
}
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class SLDebugDirectTest method assertLocation.
private void assertLocation(final String name, final int line, final boolean isBefore, final String code, final Object... expectedFrame) {
run.addLast(() -> {
assertNotNull(suspendedEvent);
final SourceSection suspendedSourceSection = suspendedEvent.getSourceSection();
Assert.assertEquals(line, suspendedSourceSection.getStartLine());
Assert.assertEquals(code, suspendedSourceSection.getCharacters());
Assert.assertEquals(isBefore, suspendedEvent.getSuspendAnchor() == SuspendAnchor.BEFORE);
final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
assertEquals(name, frame.getName());
for (int i = 0; i < expectedFrame.length; i = i + 2) {
final String expectedIdentifier = (String) expectedFrame[i];
final Object expectedValue = expectedFrame[i + 1];
DebugScope scope = frame.getScope();
DebugValue slot = scope.getDeclaredValue(expectedIdentifier);
while (slot == null && (scope = scope.getParent()) != null) {
slot = scope.getDeclaredValue(expectedIdentifier);
}
if (expectedValue != UNASSIGNED) {
Assert.assertNotNull(expectedIdentifier, slot);
final String slotValue = slot.as(String.class);
Assert.assertEquals(expectedValue, slotValue);
} else {
Assert.assertNull(expectedIdentifier, slot);
}
}
run.removeFirst().run();
});
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class SLDebugDirectTest method testPause.
@Test
public void testPause() throws Throwable {
final Source interopComp = createInteropComputation();
context.eval(interopComp);
assertExecutedOK();
final ExecNotifyHandler nh = new ExecNotifyHandler();
// Do pause after execution has really started
new Thread() {
@Override
public void run() {
nh.waitTillCanPause();
session.suspendNextExecution();
}
}.start();
run.addLast(() -> {
// paused
assertNotNull(suspendedEvent);
int line = suspendedEvent.getSourceSection().getStartLine();
Assert.assertTrue("Unexpected line: " + line, 5 <= line && line <= 6);
final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
DebugScope scope = frame.getScope();
DebugValue slot = scope.getDeclaredValue("executing");
if (slot == null) {
slot = scope.getParent().getDeclaredValue("executing");
}
Assert.assertNotNull(slot);
Assert.assertNotNull("Value is null", slot.toString());
suspendedEvent.prepareContinue();
nh.pauseDone();
});
Value value = context.getBindings("sl").getMember("interopFunction").execute(nh);
assertExecutedOK();
assertTrue(value.isBoolean());
boolean n = value.asBoolean();
assertTrue("Interop computation OK", !n);
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class SLDebugTest method testDebugValue.
@Test
public void testDebugValue() throws Throwable {
final Source varsSource = slCode("function main() {\n" + " a = doNull();\n" + " b = 10 == 10;\n" + " c = 10;\n" + " d = \"str\";\n" + " e = new();\n" + " e.p1 = 1;\n" + " e.p2 = new();\n" + " e.p2.p21 = 21;\n" + " return;\n" + "}\n" + "function doNull() {}\n");
try (DebuggerSession session = startSession()) {
session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(10).build());
startEval(varsSource);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugScope scope = frame.getScope();
DebugValue a = scope.getDeclaredValue("a");
assertFalse(a.isArray());
assertNull(a.getArray());
assertNull(a.getProperties());
DebugValue b = scope.getDeclaredValue("b");
assertFalse(b.isArray());
assertNull(b.getArray());
assertNull(b.getProperties());
DebugValue c = scope.getDeclaredValue("c");
assertFalse(c.isArray());
assertEquals("10", c.as(String.class));
assertNull(c.getArray());
assertNull(c.getProperties());
DebugValue d = scope.getDeclaredValue("d");
assertFalse(d.isArray());
assertEquals("str", d.as(String.class));
assertNull(d.getArray());
assertNull(d.getProperties());
DebugValue e = scope.getDeclaredValue("e");
assertFalse(e.isArray());
assertNull(e.getArray());
assertEquals(scope, e.getScope());
Collection<DebugValue> propertyValues = e.getProperties();
assertEquals(2, propertyValues.size());
Iterator<DebugValue> propertiesIt = propertyValues.iterator();
assertTrue(propertiesIt.hasNext());
DebugValue p1 = propertiesIt.next();
assertEquals("p1", p1.getName());
assertEquals("1", p1.as(String.class));
assertNull(p1.getScope());
assertTrue(propertiesIt.hasNext());
DebugValue p2 = propertiesIt.next();
assertEquals("p2", p2.getName());
assertNull(p2.getScope());
assertFalse(propertiesIt.hasNext());
propertyValues = p2.getProperties();
assertEquals(1, propertyValues.size());
propertiesIt = propertyValues.iterator();
assertTrue(propertiesIt.hasNext());
DebugValue p21 = propertiesIt.next();
assertEquals("p21", p21.getName());
assertEquals("21", p21.as(String.class));
assertNull(p21.getScope());
assertFalse(propertiesIt.hasNext());
});
expectDone();
}
}
Aggregations