use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class StepTest method testExpressionAndStatementStep.
@Test
public void testExpressionAndStatementStep() {
final Source source = testSource("ROOT(\n" + " DEFINE(inner1, ROOT(\n" + " STATEMENT,\n" + " EXPRESSION\n" + " )),\n" + " DEFINE(inner2, ROOT(\n" + " EXPRESSION(STATEMENT), STATEMENT(CONSTANT(1))\n" + " )),\n" + " EXPRESSION,\n" + " STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2))),\n" + " EXPRESSION,\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession(SourceElement.EXPRESSION, SourceElement.STATEMENT)) {
startEval(source);
session.suspendNextExecution();
expectSuspended((SuspendedEvent event) -> {
checkState(event, 9, true, "EXPRESSION").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 9, false, "EXPRESSION").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, true, "STATEMENT(EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner1)), EXPRESSION(CALL(inner2)))").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, true, "EXPRESSION(CALL(inner1))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT").prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, false, "CALL(inner1)").prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, false, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, true, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, false, "EXPRESSION(CALL(inner1))").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, true, "EXPRESSION(CALL(inner2))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 7, true, "EXPRESSION(STATEMENT)").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 7, true, "STATEMENT").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 7, false, "EXPRESSION(STATEMENT)").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 7, true, "STATEMENT(CONSTANT(1))").prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, false, "CALL(inner2)").prepareStepOut(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, false, "EXPRESSION(CALL(inner2))").prepareStepOut(1);
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class SuspendedEventTest method testStackFrames.
@Test
public void testStackFrames() throws Throwable {
final Source source = testSource("ROOT(\n" + " DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + " DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + " STATEMENT(CALL(bar)))),\n" + " STATEMENT(VARIABLE(root0, 43)),\n" + " STATEMENT(CALL(foo))\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, true, "STATEMENT(VARIABLE(root0, 43))").prepareStepOver(1);
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
checkStack(frameIterator.next());
Assert.assertFalse(frameIterator.hasNext());
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 6, true, "STATEMENT(CALL(foo))", "root0", "43").prepareStepInto(1);
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
checkStack(frameIterator.next(), "root0", "43");
Assert.assertFalse(frameIterator.hasNext());
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT(CALL(bar))", "foo0", "42").prepareStepInto(1);
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
checkStack(frameIterator.next(), "foo0", "42");
checkStack(frameIterator.next(), "root0", "43");
Assert.assertFalse(frameIterator.hasNext());
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT", "bar0", "41", "bar1", "40").prepareContinue();
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
checkStack(frameIterator.next(), "bar0", "41", "bar1", "40");
checkStack(frameIterator.next(), "foo0", "42");
checkStack(frameIterator.next(), "root0", "43");
Assert.assertFalse(frameIterator.hasNext());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class SuspendedEventTest method testReturnValue.
@Test
public void testReturnValue() throws Throwable {
final Source source = testSource("ROOT(\n" + " DEFINE(bar, STATEMENT(CONSTANT(42))), \n" + " DEFINE(foo, CALL(bar)), \n" + " STATEMENT(CALL(foo))\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT(CALL(foo))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT(CONSTANT(42))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, false, "CALL(bar)").prepareStepInto(1);
assertEquals("42", event.getReturnValue().as(String.class));
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, false, "CALL(foo)").prepareContinue();
assertEquals("42", event.getReturnValue().as(String.class));
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class SuspendedEventTest method testOtherThreadAccess.
@Test
public void testOtherThreadAccess() throws Throwable {
final Source source = testSource("ROOT(\n" + " DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + " DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + " STATEMENT(CALL(bar)))),\n" + " STATEMENT(VARIABLE(root0, 43)),\n" + " STATEMENT(CALL(foo))\n" + ")\n");
try (DebuggerSession session = startSession()) {
final Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
run(() -> event.getBreakpointConditionException(breakpoint));
run(() -> event.getSession());
run(() -> event.getSourceSection());
run(() -> event.getBreakpoints());
run(() -> event.getSuspendAnchor());
run(() -> event.toString());
run(() -> {
event.prepareStepInto(1);
return null;
});
run(() -> {
event.prepareStepOut(1);
return null;
});
run(() -> {
event.prepareStepOver(1);
return null;
});
run(() -> {
event.prepareContinue();
return null;
});
run(() -> {
event.prepareKill();
return null;
});
runExpectIllegalState(() -> event.getStackFrames());
runExpectIllegalState(() -> event.getTopStackFrame());
runExpectIllegalState(() -> event.getReturnValue());
for (DebugStackFrame frame : event.getStackFrames()) {
for (DebugValue value : frame) {
runExpectIllegalState(() -> value.as(String.class));
runExpectIllegalState(() -> {
value.set(null);
return null;
});
// Name is known
value.getName();
runExpectIllegalState(() -> value.isReadable());
runExpectIllegalState(() -> value.isWritable());
}
run(() -> frame.getName());
run(() -> frame.getSourceSection());
run(() -> frame.isInternal());
run(() -> frame.toString());
runExpectIllegalState(() -> frame.getScope().getDeclaredValue(""));
runExpectIllegalState(() -> frame.getScope().getDeclaredValues().iterator());
runExpectIllegalState(() -> frame.eval(""));
}
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class SuspensionFilterTest method testSuspendInInitialization.
@Test
public void testSuspendInInitialization() {
Source initSource = Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION)", "<init>").buildLiteral();
InstrumentationTestLanguage.envConfig = Collections.singletonMap("initSource", initSource);
final Source source = testSource("ROOT(\n" + " DEFINE(foo, \n" + " STATEMENT(CONSTANT(42))\n" + " ), \n" + " STATEMENT(CALL(foo))\n" + ")\n");
SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().build();
// Empty filter does not filter anything
try (DebuggerSession session = startSession()) {
session.setSteppingFilter(suspensionFilter);
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 1, true, "STATEMENT(EXPRESSION)").prepareContinue();
Assert.assertFalse(event.isLanguageContextInitialized());
});
expectDone();
}
}
Aggregations