use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class InstrumentLookupTest method testCanAccessDebugger.
@Test
@SuppressWarnings("deprecation")
public void testCanAccessDebugger() {
com.oracle.truffle.api.vm.PolyglotRuntime runtime = com.oracle.truffle.api.vm.PolyglotRuntime.newBuilder().build();
com.oracle.truffle.api.vm.PolyglotRuntime.Instrument debuggerInstrument = runtime.getInstruments().get("debugger");
assertNotNull(debuggerInstrument);
com.oracle.truffle.api.vm.PolyglotRuntime.Instrument accessDebuggerInstrument = runtime.getInstruments().get("testAccessInstrument");
Debugger debugger = accessDebuggerInstrument.lookup(DebuggerProvider.class).getDebugger();
assertNotNull(debugger);
assertEquals(debugger, debuggerInstrument.lookup(Debugger.class));
}
use of com.oracle.truffle.api.debug.Debugger 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.Debugger in project graal by oracle.
the class SLDebugTest method testTimeboxing.
@Test(expected = PolyglotException.class)
public void testTimeboxing() throws Throwable {
final Source endlessLoop = slCode("function main() {\n" + " i = 1; \n" + " while(i > 0) {\n" + " i = i + 1;\n" + " }\n" + " return i; \n" + "}\n");
final Context context = Context.create("sl");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
context.getEngine().getInstruments().get("debugger").lookup(Debugger.class).startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
event.prepareKill();
}
}).suspendNextExecution();
}
}, 1000);
context.eval(endlessLoop);
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class SLDebugTest method testStackInterop.
@Test
public void testStackInterop() {
final Source stackSource = slCode("function fac(n, multiply) {\n" + " if (n <= 1) {\n" + " debugger;\n" + " return 1;\n" + " }\n" + " return multiply.multiply(n, fac, n - 1);\n" + "}\n");
Context context = Context.create("sl");
context.eval(stackSource);
Value fac = context.getBindings("sl").getMember("fac");
Object multiply = new Multiply();
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
boolean[] done = new boolean[1];
try (DebuggerSession session = debugger.startSession((event) -> {
Iterator<DebugStackFrame> sfIt = event.getStackFrames().iterator();
assertTrue(sfIt.hasNext());
DebugStackFrame dsf = sfIt.next();
assertEquals("fac", dsf.getName());
assertEquals(3, dsf.getSourceSection().getStartLine());
assertFalse(dsf.isInternal());
int numStacksAt6 = 10 - 1;
int numInteropStacks = 0;
for (int i = 0; i < numStacksAt6; ) {
assertTrue(sfIt.hasNext());
dsf = sfIt.next();
boolean inFac = dsf.getName() != null && !dsf.isInternal();
if (inFac) {
// Frame in fac function
assertEquals("fac", dsf.getName());
assertEquals(6, dsf.getSourceSection().getStartLine());
assertFalse(dsf.isInternal());
i++;
} else {
// Frame in an interop method, internal
assertNull(dsf.getSourceSection());
assertTrue(dsf.isInternal());
numInteropStacks++;
}
}
// There were at least as many interop internal frames as frames in fac function:
assertTrue("numInteropStacks = " + numInteropStacks, numInteropStacks >= numStacksAt6);
// Some more internal frames remain
while (sfIt.hasNext()) {
dsf = sfIt.next();
assertNull(dsf.getSourceSection());
assertTrue(dsf.isInternal());
}
done[0] = true;
})) {
Assert.assertNotNull(session);
Value ret = fac.execute(10, multiply);
assertNumber(ret.asLong(), 3628800L);
}
assertTrue(done[0]);
}
use of com.oracle.truffle.api.debug.Debugger 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());
}
Aggregations