use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakAtMultipleSourceElements.
@Test
public void testBreakAtMultipleSourceElements() {
final Source source = testSource("ROOT(\n" + " STATEMENT,EXPRESSION,\n" + " EXPRESSION,STATEMENT,\n" + " STATEMENT,EXPRESSION\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).sourceElements(SourceElement.STATEMENT, SourceElement.EXPRESSION).build();
session.install(breakpoint);
startEval(source);
expectSuspended((SuspendedEvent event) -> {
Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
checkState(event, 3, true, "EXPRESSION");
});
expectSuspended((SuspendedEvent event) -> {
Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
checkState(event, 3, true, "STATEMENT");
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakpointResolve.
@Test
public void testBreakpointResolve() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
Breakpoint breakpoint2 = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build();
assertFalse(breakpoint2.isResolved());
Breakpoint breakpoint3 = Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build();
assertFalse(breakpoint3.isResolved());
try (DebuggerSession session = startSession()) {
session.install(breakpoint2);
assertFalse(breakpoint2.isResolved());
assertFalse(breakpoint3.isResolved());
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
assertSame(breakpoint2, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.BEFORE, event.getSuspendAnchor());
});
assertTrue(breakpoint2.isResolved());
expectDone();
assertTrue(breakpoint2.isResolved());
assertFalse(breakpoint3.isResolved());
// breakpoint3 should be resolved by just installing it
session.install(breakpoint3);
assertTrue(breakpoint2.isResolved());
assertTrue(breakpoint3.isResolved());
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakURI1.
@Test
public void testBreakURI1() throws Throwable {
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 breakpoint = session.install(Breakpoint.newBuilder(source.getURI()).lineIs(4).build());
sessionBreakpoint = breakpoint;
startEval(source);
expectSuspended((SuspendedEvent event) -> {
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.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testGlobalBreakpoints.
@Test
// auto-closeable resource session is never referenced in body of
@SuppressWarnings("try")
public // corresponding try statement
void testGlobalBreakpoints() throws Throwable {
try {
Class.forName("java.beans.PropertyChangeListener");
} catch (ClassNotFoundException ex) {
// skip the test if running only with java.base JDK9 module
return;
}
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
Debugger debugger = getDebugger();
assertTrue(debugger.getBreakpoints().isEmpty());
Breakpoint globalBreakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
boolean[] notified = new boolean[] { false };
BreakpointListener newBPListener = BreakpointListener.register(notified, debugger, globalBreakpoint);
debugger.install(globalBreakpoint);
Assert.assertTrue(notified[0]);
Assert.assertEquals(1, debugger.getBreakpoints().size());
Breakpoint newBP = debugger.getBreakpoints().get(0);
Assert.assertTrue(globalBreakpoint.isModifiable());
Assert.assertFalse(newBP.isModifiable());
try {
newBP.dispose();
Assert.fail("Public dispose must not be possible for global breakpoints.");
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setCondition("Something");
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setCondition(null);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setEnabled(false);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setIgnoreCount(10);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
Assert.assertNull(newBP.getCondition());
Assert.assertEquals(0, newBP.getHitCount());
Assert.assertTrue(newBP.isEnabled());
Assert.assertFalse(newBP.isDisposed());
Assert.assertFalse(newBP.isResolved());
try (DebuggerSession session = startSession()) {
// global breakpoint is not among session breakpoints
Assert.assertTrue(session.getBreakpoints().isEmpty());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
Breakpoint eventBP = event.getBreakpoints().get(0);
try {
eventBP.dispose();
Assert.fail("Public dispose must not be possible for global breakpoints.");
} catch (IllegalStateException ex) {
// O.K.
}
Assert.assertTrue(eventBP.isResolved());
event.prepareContinue();
});
}
assertFalse(newBP.isDisposed());
assertFalse(newBP.isResolved());
expectDone();
try (DebuggerSession session = startSession()) {
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
event.prepareContinue();
});
}
expectDone();
newBPListener.unregister();
notified[0] = false;
BreakpointDisposeListener.register(notified, debugger, globalBreakpoint);
globalBreakpoint.dispose();
Assert.assertTrue(notified[0]);
Assert.assertEquals(0, debugger.getBreakpoints().size());
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testChangeDuringSuspension.
@Test
public void testChangeDuringSuspension() throws Throwable {
final Source source = testSource("ROOT(\n" + " DEFINE(foo,\n" + " STATEMENT\n" + " ),\n" + " STATEMENT,\n" + " CALL(foo)\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, true, "STATEMENT");
Assert.assertEquals(0, event.getBreakpoints().size());
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
event.prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT");
event.prepareContinue();
});
expectDone();
}
}
Aggregations