use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLDebugDirectTest method stepInStepOver.
@Test
public void stepInStepOver() throws Throwable {
final Source factorial = createFactorial();
context.eval(factorial);
session.suspendNextExecution();
assertLocation("test", 2, true, "res = fac(2)", "res", UNASSIGNED);
stepInto(1);
assertLocation("fac", 7, true, "n <= 1", "n", "2", "nMinusOne", UNASSIGNED, "nMOFact", UNASSIGNED, "res", UNASSIGNED);
stepOver(1);
assertLocation("fac", 10, true, "nMinusOne = n - 1", "n", "2", "nMinusOne", UNASSIGNED, "nMOFact", UNASSIGNED, "res", UNASSIGNED);
stepOver(1);
assertLocation("fac", 11, true, "nMOFact = fac(nMinusOne)", "n", "2", "nMinusOne", "1", "nMOFact", UNASSIGNED, "res", UNASSIGNED);
stepOver(1);
assertLocation("fac", 12, true, "res = n * nMOFact", "n", "2", "nMinusOne", "1", "nMOFact", "1", "res", UNASSIGNED);
stepOver(1);
assertLocation("fac", 13, true, "return res", "n", "2", "nMinusOne", "1", "nMOFact", "1", "res", "2");
stepOver(1);
assertLocation("test", 2, false, "fac(2)", "res", UNASSIGNED);
stepOver(1);
assertLocation("test", 3, true, "println(res)", "res", "2");
stepOut();
Value value = context.getBindings("sl").getMember("test");
assertTrue(value.canExecute());
Value resultValue = value.execute();
String resultStr = resultValue.toString();
Number result = resultValue.asInt();
assertExecutedOK();
assertNotNull(result);
assertEquals("Factorial computed OK", 2, result.intValue());
assertEquals("Factorial computed OK", "2", resultStr);
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLDebugDirectTest method testNull.
@Test
public void testNull() throws Throwable {
final Source nullTest = createNull();
context.eval(nullTest);
session.suspendNextExecution();
assertLocation("nullTest", 2, true, "res = doNull()", "res", UNASSIGNED);
stepInto(1);
assertLocation("nullTest", 3, true, "return res", "res", "NULL");
continueExecution();
Value value = context.getBindings("sl").getMember("nullTest").execute();
assertExecutedOK();
String val = value.toString();
assertNotNull(val);
assertEquals("SL displays null as NULL", "NULL", val);
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLDebugTest method testDebugger.
@Test
public void testDebugger() throws Throwable {
/*
* Test AlwaysHalt is working.
*/
final Source factorial = slCode("function main() {\n" + " return fac(5);\n" + "}\n" + "function fac(n) {\n" + " if (n <= 1) {\n" + // // break
" debugger; return 1;\n" + " }\n" + " return n * fac(n - 1);\n" + "}\n");
try (DebuggerSession session = startSession()) {
startEval(factorial);
// make javac happy and use the session
session.getBreakpoints();
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 6, true, "debugger", "n", "1").prepareContinue();
});
expectDone();
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLDebugTest method testStack.
@Test
public void testStack() {
final Source stackSource = 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(stackSource)).lineIs(6).build());
startEval(stackSource);
expectSuspended((SuspendedEvent event) -> {
Iterator<DebugStackFrame> sfIt = event.getStackFrames().iterator();
assertTrue(sfIt.hasNext());
DebugStackFrame dsf = sfIt.next();
assertEquals("fac", dsf.getName());
assertEquals(6, dsf.getSourceSection().getStartLine());
assertFalse(dsf.isInternal());
int numStacksAt8 = 10 - 1;
for (int i = 0; i < numStacksAt8; i++) {
assertTrue(sfIt.hasNext());
dsf = sfIt.next();
assertEquals("fac", dsf.getName());
assertEquals(8, dsf.getSourceSection().getStartLine());
assertFalse(dsf.isInternal());
}
assertTrue(sfIt.hasNext());
dsf = sfIt.next();
assertEquals("main", dsf.getName());
assertEquals(2, dsf.getSourceSection().getStartLine());
assertFalse(dsf.isInternal());
// skip internal frames
while (sfIt.hasNext()) {
dsf = sfIt.next();
assertTrue(dsf.isInternal());
}
});
expectDone();
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class SLDebugTest method testBreakpoint.
@Test
public void testBreakpoint() throws Throwable {
/*
* Wrappers need to remain inserted for recursive functions to work for debugging. Like in
* this test case when the breakpoint is in the exit condition and we want to step out.
*/
final Source factorial = slCode("function main() {\n" + " return fac(5);\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()) {
startEval(factorial);
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(factorial)).lineIs(6).build());
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 6, true, "return 1", "n", "1");
checkArgs(event.getTopStackFrame(), "n", "1");
Iterator<DebugStackFrame> sfi = event.getStackFrames().iterator();
for (int i = 1; i <= 5; i++) {
checkArgs(sfi.next(), "n", Integer.toString(i));
}
// main
checkArgs(sfi.next());
assertSame(breakpoint, event.getBreakpoints().iterator().next());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 8, false, "fac(n - 1)", "n", "2");
checkArgs(event.getTopStackFrame(), "n", "2");
assertEquals("1", event.getReturnValue().as(String.class));
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 8, false, "fac(n - 1)", "n", "3");
assertEquals("2", event.getReturnValue().as(String.class));
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 8, false, "fac(n - 1)", "n", "4");
assertEquals("6", event.getReturnValue().as(String.class));
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, "fac", 8, false, "fac(n - 1)", "n", "5");
assertEquals("24", event.getReturnValue().as(String.class));
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, "main", 2, false, "fac(5)");
checkArgs(event.getTopStackFrame());
assertEquals("120", event.getReturnValue().as(String.class));
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOut(1);
});
assertEquals("120", expectDone());
}
}
Aggregations