use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class NestedContextTest method testRecursiveEval.
@Test
public void testRecursiveEval() throws Exception {
final Source testSource = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
final Context context = Context.create();
final AtomicInteger suspensionCount = new AtomicInteger(0);
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
checkState(event, 3, true, "STATEMENT");
// recursive evaluation should not trigger a suspended event
context.eval(testSource);
suspensionCount.incrementAndGet();
}
})) {
session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
context.eval(testSource);
}
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class TimeBoxingTest method testTimeBoxing.
@Test
public void testTimeBoxing() throws Exception {
final Context context = Context.create();
Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(LOOP(infinity,STATEMENT))", "NotEnoughTime").buildLiteral();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
debugger.startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
event.prepareKill();
}
}).suspendNextExecution();
}
}, 1000);
try {
// throws KillException, wrapped by PolyglotException
context.eval(source);
Assert.fail();
} catch (PolyglotException pex) {
Assert.assertEquals("com.oracle.truffle.api.debug.KillException", pex.getMessage());
}
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebuggerContextsTest method testMultipleContexts.
@Test
public void testMultipleContexts() {
Source source = Source.create(InstrumentationTestLanguage.ID, "STATEMENT()");
Engine engine = Engine.create();
TestContextsListener contextsListener = new TestContextsListener();
List<ContextEvent> events = contextsListener.events;
int numContexts = 5;
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(null)) {
session.setContextsListener(contextsListener, false);
for (int i = 0; i < numContexts; i++) {
try (Context context = Context.newBuilder().engine(engine).build()) {
assertEquals(6 * i + 1, events.size());
context.eval(source);
}
assertEquals(6 * i + 6, events.size());
}
assertEquals(6 * numContexts, events.size());
DebugContext lastContext = null;
for (int i = 0; i < numContexts; i++) {
int ci = 6 * i;
assertTrue(events.get(ci).created);
assertNull(events.get(ci).language);
assertNotEquals(lastContext, events.get(ci).context);
lastContext = events.get(ci).context;
assertTrue(events.get(ci + 1).created);
assertNotNull(events.get(ci + 1).language);
assertEquals(lastContext, events.get(ci + 1).context);
assertTrue(events.get(ci + 2).languageInitialized);
assertTrue(events.get(ci + 3).languageFinalized);
assertNotNull(events.get(ci + 4).language);
assertNull(events.get(ci + 5).language);
}
engine.close();
}
// No more events
assertEquals(6 * numContexts, events.size());
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebuggerContextsTest method testInContextEval.
@Test
public void testInContextEval() {
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(null)) {
session.setContextsListener(contextsListener, false);
Context context = Context.newBuilder().engine(engine).build();
assert context != null;
assertEquals(1, events.size());
assertTrue(events.get(0).created);
DebugContext dc = events.get(0).context;
assertNotNull(dc);
assertNull(events.get(0).language);
// "Global" evaluation in the brand new context
DebugValue result = dc.evaluate("VARIABLE(a, 10)", InstrumentationTestLanguage.ID);
assertEquals(3, events.size());
assertTrue(events.get(1).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(1).language.getId());
assertTrue(events.get(2).languageInitialized);
String type = dc.runInContext(() -> {
assertEquals("10", result.as(String.class));
DebugValue metaObj = result.getMetaObject();
return metaObj.as(String.class);
});
assertEquals("Integer", type);
assertEquals(3, events.size());
}
}
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class InstrumentLookupTest method testCanAccessDebuggerPolyglot.
@Test
public void testCanAccessDebuggerPolyglot() {
Engine engine = Engine.create();
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
Debugger debugger2 = Debugger.find(engine);
assertSame(debugger, debugger2);
assertNotNull(debugger);
}
Aggregations