use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerContextsTest method testGetActiveContexts.
@Test
public void testGetActiveContexts() {
final DebuggerSession[] sessionPtr = new DebuggerSession[1];
try (Engine engine = Engine.create()) {
TestContextsListener contextsListener = new TestContextsListener();
List<ContextEvent> events = contextsListener.events;
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
sessionPtr[0].setContextsListener(contextsListener, true);
assertEquals(3, events.size());
assertTrue(events.get(0).created);
assertNull(events.get(0).language);
assertTrue(events.get(1).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(1).language.getId());
assertTrue(events.get(2).languageInitialized);
}
})) {
session.setContextsListener(contextsListener, true);
try (Context context = Context.newBuilder().engine(engine).build()) {
context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
assertEquals(3, events.size());
// Have creation of polyglot context and a language
assertTrue(events.get(0).created);
assertNotNull(events.get(0).context);
assertNull(events.get(0).language);
assertTrue(events.get(1).created);
assertNotNull(events.get(1).language);
assertTrue(events.get(2).languageInitialized);
}
assertEquals(6, events.size());
session.setContextsListener(null, true);
events.clear();
// Contexts created and closed:
try (Context context = Context.newBuilder().engine(engine).build()) {
context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
context.eval(Source.create(InstrumentationTestLanguage.ID, "CONTEXT(STATEMENT())"));
}
assertEquals(0, events.size());
sessionPtr[0] = session;
session.suspendNextExecution();
Context context = Context.newBuilder().engine(engine).build();
context.eval(Source.create(InstrumentationTestLanguage.ID, "ROOT(CONTEXT(EXPRESSION()), CONTEXT(STATEMENT))"));
}
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerSessionTest method testClosing2.
@Test
public void testClosing2() throws Exception {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
Context context = Context.create();
final AtomicBoolean suspend = new AtomicBoolean();
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
DebuggerSession session = debugger.startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
suspend.set(true);
}
});
context.eval(testSource);
context.close();
// if the engine disposes the session should still work
session.suspendNextExecution();
suspend(session, Thread.currentThread());
suspendAll(session);
session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
resume(session, Thread.currentThread());
session.resumeAll();
session.getDebugger();
session.getBreakpoints();
// after closing the session none of these methods should work
session.close();
try {
session.suspendNextExecution();
Assert.fail();
} catch (IllegalStateException e) {
}
try {
suspend(session, Thread.currentThread());
Assert.fail();
} catch (IllegalStateException e) {
}
try {
suspendAll(session);
Assert.fail();
} catch (IllegalStateException e) {
}
try {
session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
Assert.fail();
} catch (IllegalStateException e) {
}
try {
resume(session, Thread.currentThread());
Assert.fail();
} catch (IllegalStateException e) {
}
try {
session.resumeAll();
Assert.fail();
} catch (IllegalStateException e) {
}
try {
session.getBreakpoints();
Assert.fail();
} catch (IllegalStateException e) {
}
// still works after closing
session.getDebugger();
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerSessionTest method testSuspendAll2.
@Test
public void testSuspendAll2() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
suspendAll(session);
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareContinue();
});
// prepareContinue should be ignored here as suspenions counts higher
suspendAll(session);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT").prepareContinue();
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerSessionTest method testSuspendAll3.
@Test
public void testSuspendAll3() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
suspendAll(session);
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareKill();
});
// For prepareKill additional suspensions should be ignored
suspendAll(session);
expectKilled();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerSessionTest method testSuspendThread2.
@Test
public void testSuspendThread2() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
suspend(session, getEvalThread());
startEval(testSource);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT").prepareContinue();
});
// prepareContinue should be ignored here as suspensions counts more
suspend(session, getEvalThread());
expectSuspended((SuspendedEvent event) -> {
checkState(event, 3, true, "STATEMENT").prepareContinue();
});
expectDone();
}
}
Aggregations