use of com.oracle.truffle.api.debug.Breakpoint 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.Breakpoint in project graal by oracle.
the class BreakpointsHandler method createURLBreakpoint.
Params createURLBreakpoint(Object url, int line, int column, String condition) {
JSONArray locations = new JSONArray();
long id;
LoadScriptListener scriptListener;
synchronized (bpIDs) {
id = ++lastID;
scriptListener = script -> {
if (url instanceof Pattern ? ((Pattern) url).matcher(script.getUrl()).matches() : url.equals(script.getUrl())) {
Breakpoint bp = createBuilder(script.getSource(), line, column).resolveListener(resolvedHandler).build();
if (condition != null && !condition.isEmpty()) {
bp.setCondition(condition);
}
bp = ds.install(bp);
synchronized (bpIDs) {
bpIDs.put(bp, id);
SourceSection section = resolvedBreakpoints.remove(bp);
if (section != null) {
Location resolvedLocation = new Location(script.getId(), section.getStartLine(), section.getStartColumn());
locations.put(resolvedLocation.toJSON());
}
}
}
};
scriptListeners.put(id, scriptListener);
}
slh.addLoadScriptListener(scriptListener);
JSONObject json = new JSONObject();
json.put("breakpointId", Long.toString(id));
json.put("locations", locations);
return new Params(json);
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class BreakpointListener method propertyChange.
@Override
public void propertyChange(PropertyChangeEvent event) {
notified[0] = true;
Assert.assertEquals(Debugger.PROPERTY_BREAKPOINTS, event.getPropertyName());
Assert.assertEquals(debugger, event.getSource());
Assert.assertNull(event.getOldValue());
Assert.assertNotEquals(globalBreakpoint, event.getNewValue());
Breakpoint newBP = (Breakpoint) event.getNewValue();
try {
newBP.dispose();
Assert.fail("Public dispose must not be possible for global breakpoints.");
} catch (IllegalStateException ex) {
// O.K.
}
}
use of com.oracle.truffle.api.debug.Breakpoint 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.Breakpoint 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