use of com.oracle.truffle.api.debug.SuspendedCallback in project graal by oracle.
the class DebuggerTesterSnippets method testDebugging.
// BEGIN: DebuggerTesterSnippets.testDebugging
public void testDebugging() {
try (DebuggerTester tester = new DebuggerTester()) {
// use your guest language source here
Source source = null;
try (DebuggerSession session = tester.startSession()) {
session.suspendNextExecution();
tester.startEval(source);
tester.expectSuspended(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
// assert suspended event is proper here
event.prepareStepInto(1);
}
});
tester.expectSuspended(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
// assert another suspended event is proper here
event.prepareContinue();
}
});
// expect no more suspended events
tester.expectDone();
}
}
}
use of com.oracle.truffle.api.debug.SuspendedCallback 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.SuspendedCallback 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.SuspendedCallback in project graal by oracle.
the class DebuggerThreadsTest method testGetStartedThreads.
@Test
public void testGetStartedThreads() throws Exception {
Engine engine = Engine.create();
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
CountDownLatch latch = new CountDownLatch(1);
DebuggerSession[] sessionPtr = new DebuggerSession[1];
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
latch.countDown();
sessionPtr[0].setThreadsListener(threadsListener, true);
assertEquals(events.toString(), 2, events.size());
assertTrue(events.get(0).isNew);
assertNotNull(events.get(0).context);
assertTrue(events.get(1).isNew);
assertEquals(events.get(0).context, events.get(1).context);
assertNotEquals(events.get(0).thread, events.get(1).thread);
}
})) {
session.suspendNextExecution();
sessionPtr[0] = session;
try (Context context = Context.newBuilder().engine(engine).allowCreateThread(true).build()) {
Source source = testSource("ROOT(DEFINE(f1, EXPRESSION), SPAWN(f1), JOIN())");
context.eval(source);
source = testSource("ROOT(DEFINE(foo, STATEMENT), SPAWN(foo))");
context.eval(source);
latch.await();
context.eval(testSource("JOIN()"));
assertEquals(events.toString(), 3, events.size());
assertFalse(events.get(2).isNew);
assertTrue(events.get(0).thread == events.get(2).thread || events.get(1).thread == events.get(2).thread);
}
assertEquals(4, events.size());
}
}
Aggregations