use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testNotStepIntoBreakpointCondition.
@Test
public void testNotStepIntoBreakpointCondition() {
Source defineSource = testSource("ROOT(DEFINE(test, ROOT(\n" + "STATEMENT(EXPRESSION),\n" + "CONSTANT(true))))");
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
startEval(defineSource);
expectDone();
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
breakpoint.setCondition("CALL(test)");
session.suspendNextExecution();
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertEquals("STATEMENT", event.getSourceSection().getCharacters());
assertEquals(2, event.getSourceSection().getStartLine());
assertEquals(0, event.getBreakpoints().size());
event.prepareStepInto(1);
});
assertEquals(0, breakpoint.getHitCount());
expectSuspended((SuspendedEvent event) -> {
assertEquals("STATEMENT", event.getSourceSection().getCharacters());
assertEquals(3, event.getSourceSection().getStartLine());
assertEquals(1, event.getBreakpoints().size());
event.prepareStepInto(1);
});
assertEquals(1, breakpoint.getHitCount());
expectSuspended((SuspendedEvent event) -> {
assertEquals("STATEMENT", event.getSourceSection().getCharacters());
assertEquals(4, event.getSourceSection().getStartLine());
assertEquals(0, event.getBreakpoints().size());
event.prepareStepInto(1);
});
expectDone();
assertEquals(1, breakpoint.getHitCount());
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakURI2.
@Test
public void testBreakURI2() throws Throwable {
File testFile = testFile("ROOT(\n" + " DEFINE(foo,\n" + " LOOP(3,\n" + " STATEMENT)\n" + " ),\n" + " CALL(foo)\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(testFile.toURI()).lineIs(4).build());
session.suspendNextExecution();
startEval(Source.newBuilder(InstrumentationTestLanguage.ID, testFile).build());
for (int i = 0; i < 3; i++) {
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT").prepareContinue();
});
}
Assert.assertEquals(3, breakpoint.getHitCount());
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakpointConditionExecutedOnce.
@Test
public void testBreakpointConditionExecutedOnce() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
breakpoint.setCondition("ROOT(PRINT(OUT, Hi), CONSTANT(true))");
// Breakpoint only:
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertSame(breakpoint, event.getBreakpoints().iterator().next());
assertNull(event.getBreakpointConditionException(breakpoint));
});
assertEquals(1, breakpoint.getHitCount());
expectDone();
assertEquals("Hi", getOutput());
// Breakpoint with step and an other breakpoint:
Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
session.suspendNextExecution();
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
assertEquals(2, event.getBreakpoints().size());
assertTrue(event.getBreakpoints().contains(breakpoint));
assertTrue(event.getBreakpoints().contains(breakpoint2));
assertNull(event.getBreakpointConditionException(breakpoint));
assertNull(event.getBreakpointConditionException(breakpoint2));
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
assertTrue(event.getBreakpoints().isEmpty());
event.prepareStepOver(1);
});
expectDone();
assertEquals("HiHi", getOutput());
assertEquals(2, breakpoint.getHitCount());
assertEquals(1, breakpoint2.getHitCount());
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent 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 com.oracle.truffle.api.debug.SuspendedEvent 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();
}
}
Aggregations