use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class SLDebugTest method testUnwindAndReenter.
@Test
public void testUnwindAndReenter() {
final Source source = slCode("function main() {\n" + " return fac(10);\n" + "}\n" + "function fac(n) {\n" + " if (n <= 1) {\n" + // break
" return 1;\n" + " }\n" + " return n * fac(n - 1);\n" + "}\n");
try (DebuggerSession session = startSession()) {
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
for (int i = 0; i < 5; i++) {
frames.next();
}
event.prepareUnwindFrame(frames.next());
});
expectSuspended((SuspendedEvent event) -> {
assertEquals(8, event.getTopStackFrame().getSourceSection().getStartLine());
assertEquals("7", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
assertEquals(5, event.getTopStackFrame().getSourceSection().getStartLine());
assertEquals("6", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
event.prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
// The breakpoint hit again
assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent 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();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class SLDebugTest method testMetaObjects.
@Test
public void testMetaObjects() {
final Source varsSource = slCode("function main() {\n" + " a = doNull();\n" + " b = 10 == 10;\n" + " c = 10;\n" + " cBig = 1000000000*1000000000*1000000000*1000000000;\n" + " d = \"str\";\n" + " e = new();\n" + " f = doNull;\n" + " return;\n" + "}\n" + "function doNull() {}\n");
try (DebuggerSession session = startSession()) {
session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(9).build());
startEval(varsSource);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugScope scope = frame.getScope();
DebugValue v = scope.getDeclaredValue("a");
assertEquals("Null", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("b");
assertEquals("Boolean", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("c");
assertEquals("Number", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("cBig");
assertEquals("Number", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("d");
assertEquals("String", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("e");
assertEquals("Object", v.getMetaObject().as(String.class));
v = scope.getDeclaredValue("f");
assertEquals("Function", v.getMetaObject().as(String.class));
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class SLDebugTest method testSourceLocation.
@Test
public void testSourceLocation() {
final Source varsSource = slCode("function main() {\n" + " a = doNull();\n" + " c = 10;\n" + " d = \"str\";\n" + " e = new();\n" + " f = doNull;\n" + " return;\n" + "}\n" + "function doNull() {}\n");
try (DebuggerSession session = startSession()) {
session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(7).build());
startEval(varsSource);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugScope scope = frame.getScope();
DebugValue v = scope.getDeclaredValue("a");
assertNull(v.getSourceLocation());
v = scope.getDeclaredValue("c");
assertNull(v.getSourceLocation());
v = scope.getDeclaredValue("d");
assertNull(v.getSourceLocation());
v = scope.getDeclaredValue("e");
assertNull(v.getSourceLocation());
v = scope.getDeclaredValue("f");
SourceSection sourceLocation = v.getSourceLocation();
Assert.assertNotNull(sourceLocation);
assertEquals(9, sourceLocation.getStartLine());
assertEquals(9, sourceLocation.getEndLine());
assertEquals("doNull() {}", sourceLocation.getCharacters());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class SLDebugTest method testValuesScope.
@Test
public void testValuesScope() throws Throwable {
final Source varsSource = slCode("function main() {\n" + " a = 1;\n" + " if (a > 0) {\n" + " b = 10;\n" + " println(b);\n" + " }\n" + " println(b);\n" + " println(a);\n" + " println(\"END.\");\n" + "}");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(varsSource);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
// No variables first:
assertFalse(frame.getScope().getDeclaredValues().iterator().hasNext());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
// "a" only:
DebugScope scope = frame.getScope();
Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
assertTrue(varIt.hasNext());
DebugValue a = varIt.next();
assertEquals("a", a.getName());
assertEquals(scope, a.getScope());
assertFalse(varIt.hasNext());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
// "a" only:
DebugScope scope = frame.getScope();
Iterator<DebugValue> varIt = scope.getParent().getDeclaredValues().iterator();
assertTrue(varIt.hasNext());
DebugValue a = varIt.next();
assertEquals("a", a.getName());
assertEquals(scope.getParent(), a.getScope());
assertFalse(varIt.hasNext());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
// "a" and "b":
DebugScope scope = frame.getScope();
Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
assertTrue(varIt.hasNext());
DebugValue b = varIt.next();
assertEquals("b", b.getName());
assertEquals(scope, b.getScope());
// "a" is in the parent:
assertFalse(varIt.hasNext());
varIt = scope.getParent().getDeclaredValues().iterator();
assertTrue(varIt.hasNext());
DebugValue a = varIt.next();
assertEquals("a", a.getName());
assertEquals(scope.getParent(), a.getScope());
assertFalse(varIt.hasNext());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
// "a" only again:
DebugScope scope = frame.getScope();
Iterator<DebugValue> varIt = scope.getDeclaredValues().iterator();
assertTrue(varIt.hasNext());
DebugValue a = varIt.next();
assertEquals("a", a.getName());
assertEquals(scope, a.getScope());
assertFalse(varIt.hasNext());
event.prepareContinue();
});
expectDone();
}
}
Aggregations