use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DebuggerThreadsTest method testSingleThread.
@Test
public void testSingleThread() throws Throwable {
final Source source = testSource("STATEMENT()");
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
session.setThreadsListener(threadsListener, false);
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertEquals(1, events.size());
assertTrue(events.get(0).isNew);
assertEquals(Thread.currentThread(), events.get(0).thread);
assertNotNull(events.get(0).context);
});
expectDone();
closeEngine();
// We're closing the engine not on the execution thread - we get two more thread events.
assertEquals(4, events.size());
assertFalse(events.get(3).isNew);
assertEquals(events.get(0).context, events.get(3).context);
}
events.clear();
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DoubleHaltTest method testCallLoopStepInto.
@Test
public void testCallLoopStepInto() throws Throwable {
Source testSource = testSource("ROOT(\n" + " DEFINE(foo,\n" + " LOOP(3,\n" + " STATEMENT)\n" + " ),\n" + " CALL(foo)\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(4).build());
session.suspendNextExecution();
startEval(testSource);
for (int i = 0; i < 3; i++) {
final int modI = i % 3;
expectSuspended((SuspendedEvent event) -> {
SuspendedEvent e = checkState(event, 4, true, "STATEMENT");
assertEquals(1, e.getBreakpoints().size());
assertSame(breakpoint4, e.getBreakpoints().iterator().next());
switch(modI) {
case 0:
/*
* Note Chumer: breakpoints should always hit independent if we are
* currently stepping out or not. thats why step out does not step out
* here.
*/
e.prepareStepOut(1);
break;
case 1:
e.prepareStepInto(1);
break;
case 2:
e.prepareStepOver(1);
break;
}
});
}
expectSuspended((SuspendedEvent event) -> {
checkState(event, 6, false, "CALL(foo)");
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DoubleHaltTest method testBreakpointStepping.
@Test
public void testBreakpointStepping() throws Throwable {
Source testSource = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(5).build());
Breakpoint breakpoint6 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(6).build());
session.suspendNextExecution();
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
assertSame(breakpoint2, event.getBreakpoints().iterator().next());
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
assertSame(breakpoint3, event.getBreakpoints().iterator().next());
event.prepareStepOver(2);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
assertSame(breakpoint5, event.getBreakpoints().iterator().next());
event.prepareStepInto(2);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 6, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
assertSame(breakpoint6, event.getBreakpoints().iterator().next());
event.prepareContinue();
});
expectDone();
assertEquals(1, breakpoint2.getHitCount());
assertEquals(1, breakpoint3.getHitCount());
assertEquals(1, breakpoint5.getHitCount());
assertEquals(1, breakpoint6.getHitCount());
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testGlobalBreakpointsInMultipleSessions.
@Test
public void testGlobalBreakpointsInMultipleSessions() 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" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
Debugger debugger = getDebugger();
Breakpoint globalBreakpoint1 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
debugger.install(globalBreakpoint1);
Breakpoint globalBreakpoint2 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build();
debugger.install(globalBreakpoint2);
Breakpoint globalBreakpoint3 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build();
debugger.install(globalBreakpoint3);
Breakpoint globalBreakpoint4 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(8).build();
debugger.install(globalBreakpoint4);
// Breakpoints are in the install order:
List<Breakpoint> breakpoints = debugger.getBreakpoints();
Assert.assertEquals(4, breakpoints.size());
Assert.assertTrue(breakpoints.get(0).getLocationDescription().contains("line=2"));
Assert.assertTrue(breakpoints.get(1).getLocationDescription().contains("line=4"));
Assert.assertTrue(breakpoints.get(2).getLocationDescription().contains("line=6"));
DebuggerSession session1 = startSession();
// global breakpoints are not among session breakpoints
Assert.assertTrue(session1.getBreakpoints().isEmpty());
try (DebuggerSession session2 = startSession()) {
// global breakpoints are not among session breakpoints
Assert.assertTrue(session2.getBreakpoints().isEmpty());
startEval(source);
// Both sessions should break here:
expectSuspended((SuspendedEvent event) -> {
assertSame(session1, event.getSession());
checkState(event, 2, true, "STATEMENT").prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
assertSame(session2, event.getSession());
checkState(event, 2, true, "STATEMENT").prepareContinue();
});
// We close session2 after the next BP:
expectSuspended((SuspendedEvent event) -> {
assertSame(session1, event.getSession());
checkState(event, 4, true, "STATEMENT");
});
}
expectSuspended((SuspendedEvent event) -> {
assertNotSame(session1, event.getSession());
checkState(event, 4, true, "STATEMENT").prepareContinue();
});
// The last breakpoint is hit once only in the session1:
expectSuspended((SuspendedEvent event) -> {
assertSame(session1, event.getSession());
checkState(event, 6, true, "STATEMENT").prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
assertSame(session1, event.getSession());
checkState(event, 7, true, "STATEMENT");
session1.close();
event.prepareContinue();
});
// Breakpoint at line 8 was not hit at all, the session was closed right before continue
// from line 7.
expectDone();
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class BreakpointTest method testBreakSource.
@Test
public void testBreakSource() 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(getSourceImpl(source)).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());
}
Aggregations