use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class SLDebugTest method testArgumentsAndValues.
@Test
public void testArgumentsAndValues() throws Throwable {
// Test that after a re-enter, arguments are kept and variables are cleared.
final Source source = slCode("function main() {\n" + " i = 10;\n" + " return fnc(i = i + 1, 20);\n" + "}\n" + "function fnc(n, m) {\n" + " x = n + m;\n" + " n = m - n;\n" + " m = m / 2;\n" + " x = x + n * m;\n" + " return x;\n" + "}\n");
try (DebuggerSession session = startSession()) {
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
assertEquals(6, frame.getSourceSection().getStartLine());
checkArgs(frame, "n", "11", "m", "20");
checkStack(frame, "fnc", "n", "11", "m", "20");
event.prepareStepOver(4);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
assertEquals(10, frame.getSourceSection().getStartLine());
checkArgs(frame, "n", "11", "m", "20");
checkStack(frame, "fnc", "n", "9", "m", "10", "x", "121");
event.prepareUnwindFrame(frame);
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
assertEquals(3, frame.getSourceSection().getStartLine());
checkArgs(frame);
checkStack(frame, "main", "i", "11");
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
assertEquals(6, frame.getSourceSection().getStartLine());
checkArgs(frame, "n", "11", "m", "20");
checkStack(frame, "fnc", "n", "11", "m", "20");
});
assertEquals("121", expectDone());
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent 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.SuspendedEvent 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();
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class StepTest method testStepInto.
@Test
public void testStepInto() throws Throwable {
final Source source = testSource("ROOT(\n" + " DEFINE(bar, STATEMENT),\n" + " DEFINE(foo, ROOT(STATEMENT(CALL(bar)), \n" + " STATEMENT(CALL(bar)))),\n" + " STATEMENT(CALL(foo)),\n" + " STATEMENT(CALL(foo))\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, true, "STATEMENT(CALL(foo))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT(CALL(bar))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, false, "CALL(bar)").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT(CALL(bar))").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, false, "CALL(bar)").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 5, false, "CALL(foo)").prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
checkState(event, 6, true, "STATEMENT(CALL(foo))").prepareContinue();
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class StepTest method testStepBadArgStepOver.
@Test
public void testStepBadArgStepOver() throws Throwable {
final Source source = testSource("ROOT(\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession()) {
startEval(source);
session.suspendNextExecution();
expectSuspended((SuspendedEvent event) -> {
try {
checkState(event, 2, true, "STATEMENT").prepareStepOver(0);
fail("Exception expected");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Step count must be > 0", e.getMessage());
}
});
expectDone();
}
}
Aggregations