use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebugALot method onCreate.
@Override
protected void onCreate(Env env) {
Boolean debugALot = env.getOptions().get(DebugALot);
failFast = env.getOptions().get(FailFast);
doEval = env.getOptions().get(Eval);
boolean isLogFile = env.getOptions().hasBeenSet(LogFile);
if (!(Boolean.TRUE.equals(debugALot) || failFast || doEval || isLogFile)) {
return;
}
if (isLogFile) {
String logFilePath = env.getOptions().get(LogFile);
try {
logger = new PrintWriter(new FileWriter(logFilePath));
} catch (IOException ioex) {
logger = new PrintWriter(env.out());
logger.print(ioex.getLocalizedMessage());
}
} else {
logger = new PrintWriter(env.out());
}
Debugger debugger = env.lookup(env.getInstruments().get("debugger"), Debugger.class);
DebuggerSession debuggerSession = debugger.startSession(this);
debuggerSession.suspendNextExecution();
debuggerSession.setSteppingFilter(SuspensionFilter.newBuilder().ignoreLanguageContextInitialization(true).build());
}
use of com.oracle.truffle.api.debug.DebuggerSession 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.DebuggerSession 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.DebuggerSession 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.DebuggerSession in project graal by oracle.
the class StepTest method testBlock.
@Test
public void testBlock() throws Throwable {
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
try (DebuggerSession session = startSession()) {
startEval(source);
// make javac happy and use the sessiononce.
session.getDebugger();
expectDone();
}
}
Aggregations