use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class DebuggerTesterSnippets method assertBreakpointsBreakEverywhere.
/**
* Utility method that tests if a breakpoint submitted to any location in the source code
* suspends the execution. A two-pass test is performed. In the first pass, line breakpoints are
* submitted to every line. In the second pass, breakpoints are submitted to every line and
* column combination, even outside the source scope. It is expected that the breakpoints
* resolve to a nearest suspendable location and it is checked that all breakpoints are hit.
*
* @param source a source to evaluate with breakpoints submitted everywhere
* @since 0.33
*/
public void assertBreakpointsBreakEverywhere(Source source) {
int numLines = source.getLineCount();
int numColumns = 0;
for (int i = 1; i <= numLines; i++) {
int ll = source.getLineLength(i);
if (ll > numColumns) {
numColumns = ll;
}
}
com.oracle.truffle.api.source.Source tsource = DebuggerTester.getSourceImpl(source);
final List<Breakpoint> breakpoints = new ArrayList<>();
final Set<Breakpoint> breakpointsResolved = new HashSet<>();
final List<Breakpoint> breakpointsHit = new ArrayList<>();
Breakpoint.ResolveListener resolveListener = new Breakpoint.ResolveListener() {
@Override
public void breakpointResolved(Breakpoint breakpoint, SourceSection section) {
Assert.assertFalse(breakpointsResolved.contains(breakpoint));
breakpointsResolved.add(breakpoint);
}
};
// Test all line breakpoints
for (int l = 1; l < (numLines + 5); l++) {
Breakpoint breakpoint = Breakpoint.newBuilder(tsource).lineIs(l).oneShot().resolveListener(resolveListener).build();
breakpoints.add(breakpoint);
}
assertBreakpoints(source, breakpoints, breakpointsResolved, breakpointsHit);
breakpoints.clear();
breakpointsResolved.clear();
breakpointsHit.clear();
// Test all line/column breakpoints
for (int l = 1; l < (numLines + 5); l++) {
for (int c = 1; c < (numColumns + 5); c++) {
Breakpoint breakpoint = Breakpoint.newBuilder(tsource).lineIs(l).columnIs(c).oneShot().resolveListener(resolveListener).build();
breakpoints.add(breakpoint);
}
}
assertBreakpoints(source, breakpoints, breakpointsResolved, breakpointsHit);
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class DebuggerTesterSnippets method assertBreakpoints.
private void assertBreakpoints(Source source, List<Breakpoint> breakpoints, Set<Breakpoint> breakpointsResolved, List<Breakpoint> breakpointsHit) {
try (DebuggerSession session = startSession()) {
for (Breakpoint breakpoint : breakpoints) {
session.install(breakpoint);
}
startEval(source);
while (breakpointsHit.size() != breakpoints.size()) {
expectSuspended((SuspendedEvent event) -> {
breakpointsHit.addAll(event.getBreakpoints());
event.prepareContinue();
});
}
expectDone();
}
Assert.assertEquals(breakpoints.size(), breakpointsResolved.size());
Assert.assertEquals(breakpoints.size(), breakpointsHit.size());
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class SLDebugTest method testUnwindAndReenter.
@Test
public void testUnwindAndReenter() {
final Source source = 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(source)).lineIs(6).build());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
for (int i = 0; i < 5; i++) {
frames.next();
}
event.prepareUnwindFrame(frames.next());
});
expectSuspended((SuspendedEvent event) -> {
assertEquals(8, event.getTopStackFrame().getSourceSection().getStartLine());
assertEquals("7", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
assertEquals(5, event.getTopStackFrame().getSourceSection().getStartLine());
assertEquals("6", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
event.prepareContinue();
});
expectSuspended((SuspendedEvent event) -> {
// The breakpoint hit again
assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class DebuggerTesterSnippets method assertLineBreakpointsResolution.
/**
* Utility method that checks proper resolution of line breakpoints. Breakpoints are submitted
* to every line of the source and their resolution location is checked.
* <p>
* The source need to contain resolution marks in the form of
* "<code>R<line number>_</code>" where <line number> is line number of the original
* breakpoint position and <code>R</code> is the resolved mark name. These marks need to be
* placed at the proper breakpoint resolution line/column position, for a breakpoint submitted
* to every line. When several submitted breakpoints resolve to the same position, an interval
* can be specified in the form of
* "<code>R<line start number>-<line end number>_</code>", where both start and end
* line numbers are inclusive. The marks are stripped off before execution.
* <p>
* The guest language code with marks may look like:
*
* <pre>
* // test
* function test(n) {
* if (R1-3_n <= 1) {
* return R4_2 * n;
* }
* return R5-7_n - 1;
* }
* </pre>
*
* @param sourceWithMarks a source text, which contains the resolution marks
* @param resolvedMarkName the mark name. It is used in a regular expression, therefore the mark
* must not have a special meaning in a regular expression.
* @param language the source language
* @since 0.33
*/
public void assertLineBreakpointsResolution(String sourceWithMarks, String resolvedMarkName, String language) throws IOException {
Pattern br = Pattern.compile("(" + resolvedMarkName + "\\d+_|" + resolvedMarkName + "\\d+-\\d+_)");
Map<Integer, Integer> bps = new HashMap<>();
String sourceString = sourceWithMarks;
Matcher bm = br.matcher(sourceString);
while (bm.find()) {
String bg = bm.group();
int index = bm.start();
int bn1;
int bn2;
String bpNums = bg.substring(1, bg.length() - 1);
int rangeIndex = bpNums.indexOf('-');
if (rangeIndex > 0) {
bn1 = Integer.parseInt(bpNums.substring(0, rangeIndex));
bn2 = Integer.parseInt(bpNums.substring(rangeIndex + 1));
} else {
bn1 = bn2 = Integer.parseInt(bpNums);
}
for (int bn = bn1; bn <= bn2; bn++) {
Integer bp = bps.get(bn);
if (bp == null) {
bps.put(bn, index + 1);
} else {
Assert.fail(bg + " specified more than once.");
}
}
sourceString = bm.replaceFirst("");
bm.reset(sourceString);
}
if (TRACE) {
trace("sourceString = '" + sourceString + "'");
}
final Source source = Source.newBuilder(language, sourceString, "testMisplacedLineBreakpoint." + language).build();
com.oracle.truffle.api.source.Source tsource = DebuggerTester.getSourceImpl(source);
for (int l = 1; l < source.getLineCount(); l++) {
if (!bps.containsKey(l)) {
Assert.fail("Line " + l + " is missing.");
}
}
for (Map.Entry<Integer, Integer> bentry : bps.entrySet()) {
int line = bentry.getKey();
int indexResolved = bentry.getValue();
int lineResolved = source.getLineNumber(indexResolved - 1);
if (TRACE) {
trace("TESTING breakpoint '" + line + "' => " + lineResolved + ":");
}
try (DebuggerSession session = startSession()) {
startEval(source);
int[] resolvedIndexPtr = new int[] { 0 };
Breakpoint breakpoint = session.install(Breakpoint.newBuilder(tsource).lineIs(line).oneShot().resolveListener(new Breakpoint.ResolveListener() {
@Override
public void breakpointResolved(Breakpoint brkp, SourceSection section) {
resolvedIndexPtr[0] = section.getCharIndex() + 1;
if (TRACE) {
trace("BREAKPOINT resolved to " + section.getStartLine() + ":" + section.getStartColumn());
}
}
}).build());
expectSuspended((SuspendedEvent event) -> {
Assert.assertEquals("Expected " + line + " => " + lineResolved, lineResolved, event.getSourceSection().getStartLine());
Assert.assertSame(breakpoint, event.getBreakpoints().iterator().next());
event.prepareContinue();
});
expectDone();
Assert.assertEquals("Expected resolved " + line + " => " + indexResolved, indexResolved, resolvedIndexPtr[0]);
}
}
}
use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.
the class NestedContextTest method testNestedStepping.
private void testNestedStepping(int depth) {
if (depth == 0) {
return;
}
Source testSource = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
pushContext();
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
session.suspendNextExecution();
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
assertEquals(0, event.getBreakpoints().size());
testNestedStepping(depth - 1);
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
assertSame(breakpoint3, event.getBreakpoints().iterator().next());
testNestedStepping(depth - 1);
event.prepareStepInto(1);
});
expectDone();
}
popContext();
}
Aggregations