use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointTest method testInactive.
@Test
public void testInactive() throws Throwable {
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
// Breakpoints deactivated after the first suspend - no breakpoints are hit
try (DebuggerSession session = startSession()) {
Assert.assertTrue(session.isBreakpointsActive());
// normal breakpoint
Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
// disabled breakpoint
Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
breakpoint4.setEnabled(false);
// re-enabled breakpoint
Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(5).build());
breakpoint5.setEnabled(false);
breakpoint5.setEnabled(true);
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
session.setBreakpointsActive(false);
});
expectDone();
Assert.assertEquals(0, breakpoint3.getHitCount());
Assert.assertEquals(0, breakpoint4.getHitCount());
Assert.assertEquals(0, breakpoint5.getHitCount());
Assert.assertTrue(breakpoint3.isEnabled());
Assert.assertFalse(breakpoint4.isEnabled());
Assert.assertTrue(breakpoint5.isEnabled());
}
// Breakpoints deactivated after the first one is hit - the others are not
try (DebuggerSession session = startSession()) {
Assert.assertTrue(session.isBreakpointsActive());
// normal breakpoint
Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build());
// disabled breakpoint
Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
breakpoint4.setEnabled(false);
// re-enabled breakpoint
Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(5).build());
breakpoint5.setEnabled(false);
breakpoint5.setEnabled(true);
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
session.setBreakpointsActive(false);
});
expectDone();
Assert.assertEquals(1, breakpoint2.getHitCount());
Assert.assertEquals(0, breakpoint4.getHitCount());
Assert.assertEquals(0, breakpoint5.getHitCount());
Assert.assertTrue(breakpoint2.isEnabled());
Assert.assertFalse(breakpoint4.isEnabled());
Assert.assertTrue(breakpoint5.isEnabled());
}
// Breakpoints initially deactivated, they are activated before the last one is hit.
try (DebuggerSession session = startSession()) {
Assert.assertTrue(session.isBreakpointsActive());
session.setBreakpointsActive(false);
Assert.assertFalse(session.isBreakpointsActive());
// normal breakpoint
Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build());
// disabled breakpoint
Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
breakpoint4.setEnabled(false);
// re-enabled breakpoint
Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(5).build());
breakpoint5.setEnabled(false);
breakpoint5.setEnabled(true);
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareStepOver(2);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT");
session.setBreakpointsActive(true);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, true, "STATEMENT");
});
expectDone();
Assert.assertEquals(0, breakpoint2.getHitCount());
Assert.assertEquals(0, breakpoint4.getHitCount());
Assert.assertEquals(1, breakpoint5.getHitCount());
Assert.assertTrue(breakpoint2.isEnabled());
Assert.assertFalse(breakpoint4.isEnabled());
Assert.assertTrue(breakpoint5.isEnabled());
}
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointTest method testBreakpointDefaults.
@Test
public void testBreakpointDefaults() {
Source testSource = testSource("STATEMENT");
Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(1).build();
assertEquals(0, breakpoint.getHitCount());
assertEquals(0, breakpoint.getIgnoreCount());
assertEquals(SuspendAnchor.BEFORE, breakpoint.getSuspendAnchor());
assertFalse(breakpoint.isDisposed());
assertTrue(breakpoint.isEnabled());
assertFalse(breakpoint.isResolved());
// Make some state changes
breakpoint.setIgnoreCount(9);
assertEquals(9, breakpoint.getIgnoreCount());
breakpoint.setEnabled(false);
assertFalse(breakpoint.isEnabled());
breakpoint.setCondition("a + b");
breakpoint.dispose();
assertTrue(breakpoint.isDisposed());
assertFalse(breakpoint.isEnabled());
assertFalse(breakpoint.isResolved());
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointTest method testResolveListener.
@Test
public void testResolveListener() {
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT,\n" + // break here
" STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
Breakpoint sessionBreakpoint = null;
try (DebuggerSession session = startSession()) {
Breakpoint[] resolvedBp = new Breakpoint[1];
SourceSection[] resolvedSection = new SourceSection[1];
Breakpoint.ResolveListener bpResolveListener = (Breakpoint breakpoint, SourceSection section) -> {
resolvedBp[0] = breakpoint;
resolvedSection[0] = section;
};
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).resolveListener(bpResolveListener).build());
Assert.assertNull(resolvedBp[0]);
Assert.assertNull(resolvedSection[0]);
sessionBreakpoint = breakpoint;
startEval(source);
expectSuspended((SuspendedEvent event) -> {
Assert.assertSame(breakpoint, resolvedBp[0]);
Assert.assertEquals(event.getSourceSection(), resolvedSection[0]);
checkState(event, 4, true, "STATEMENT");
Assert.assertEquals(1, event.getBreakpoints().size());
Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
});
Assert.assertEquals(1, breakpoint.getHitCount());
Assert.assertEquals(true, breakpoint.isEnabled());
Assert.assertEquals(true, breakpoint.isResolved());
expectDone();
}
Assert.assertEquals(false, sessionBreakpoint.isResolved());
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointTest method testOneShot.
@Test
public void testOneShot() throws Throwable {
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " LOOP(3, STATEMENT),\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).oneShot().build());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT");
Assert.assertEquals(1, event.getBreakpoints().size());
Assert.assertSame(breakpoint, event.getBreakpoints().iterator().next());
Assert.assertFalse(breakpoint.isEnabled());
Assert.assertEquals(1, breakpoint.getHitCount());
// reenable breakpoint to hit again
breakpoint.setEnabled(true);
event.prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
Assert.assertEquals(1, event.getBreakpoints().size());
Assert.assertSame(breakpoint, event.getBreakpoints().iterator().next());
Assert.assertFalse(breakpoint.isEnabled());
Assert.assertEquals(2, breakpoint.getHitCount());
event.prepareContinue();
});
// we don't reenable the breakpoint so we should not hit it again
expectDone();
}
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointTest method testDisableDispose.
@Test
public void testDisableDispose() throws Throwable {
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession()) {
// test normal breakpoint should hit
Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
// test disposed breakpoint should not hit
Breakpoint breakpoint6 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build());
breakpoint6.dispose();
// test disabled breakpoint should not hit
Breakpoint breakpoint8 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(8).build());
breakpoint8.setEnabled(false);
// test re-enabled breakpoint should hit
Breakpoint breakpoint10 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(10).build());
breakpoint10.setEnabled(false);
breakpoint10.setEnabled(true);
// Breakpoints are in the install order:
List<Breakpoint> breakpoints = session.getBreakpoints();
Assert.assertSame(breakpoint4, breakpoints.get(0));
Assert.assertSame(breakpoint8, breakpoints.get(1));
Assert.assertSame(breakpoint10, breakpoints.get(2));
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT").prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 10, true, "STATEMENT").prepareContinue();
});
expectDone();
Assert.assertEquals(1, breakpoint4.getHitCount());
Assert.assertTrue(breakpoint4.isEnabled());
Assert.assertEquals(0, breakpoint6.getHitCount());
Assert.assertFalse(breakpoint6.isEnabled());
Assert.assertEquals(0, breakpoint8.getHitCount());
Assert.assertFalse(breakpoint8.isEnabled());
Assert.assertEquals(1, breakpoint10.getHitCount());
Assert.assertTrue(breakpoint10.isEnabled());
}
}
Aggregations