use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DebugValueTest method testNumValue.
@Test
public void testNumValue() throws Throwable {
final Source source = testSource("ROOT(\n" + " VARIABLE(a, 42), \n" + " VARIABLE(inf, infinity), \n" + " STATEMENT()\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugValue value42 = frame.getScope().getDeclaredValue("a");
assertEquals("a", value42.getName());
assertFalse(value42.isArray());
assertNull(value42.getArray());
assertNull(value42.getProperties());
assertEquals("Integer", value42.getMetaObject().as(String.class));
assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
SourceSection integerSS = value42.getSourceLocation();
assertEquals("source integer", integerSS.getCharacters());
SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
assertEquals("source infinity", infinitySS.getCharacters());
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DebugValueTest method testValueAttributes.
/**
* Test of {@link DebugValue#isReadable()}, {@link DebugValue#isWritable()} and
* {@link DebugValue#isInternal()}.
*/
@Test
public void testValueAttributes() throws Throwable {
final Source source = testSource("DEFINE(function, ROOT(\n" + " ARGUMENT(a), \n" + " STATEMENT()\n" + "))\n");
Context context = Context.create();
context.eval(source);
Value functionValue = context.getBindings(InstrumentationTestLanguage.ID).getMember("function");
assertNotNull(functionValue);
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
// Test of the default attribute values:
NoAttributesTruffleObject nao = new NoAttributesTruffleObject();
boolean[] suspended = new boolean[] { false };
DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
assertFalse(suspended[0]);
DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
assertNotNull(value);
DebugValue attributesTOValue = value.getProperties().iterator().next();
assertEquals("property", attributesTOValue.getName());
// Property is readable by default
assertTrue(attributesTOValue.isReadable());
// Property is writable by default
assertTrue(attributesTOValue.isWritable());
// Property is not internal by default
assertFalse(attributesTOValue.isInternal());
event.prepareContinue();
suspended[0] = true;
});
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
functionValue.execute(nao);
session.close();
assertTrue(suspended[0]);
// Test of the modified attribute values:
suspended[0] = false;
final ModifiableAttributesTruffleObject mao = new ModifiableAttributesTruffleObject();
session = debugger.startSession((SuspendedEvent event) -> {
assertFalse(suspended[0]);
DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
assertNotNull(value);
DebugValue attributesTOValue = value.getProperties().iterator().next();
assertEquals("property", attributesTOValue.getName());
// All false initially
assertFalse(attributesTOValue.isReadable());
assertFalse(attributesTOValue.isWritable());
assertFalse(attributesTOValue.isInternal());
mao.setIsReadable(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isReadable());
mao.setIsWritable(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isWritable());
mao.setIsInternal(true);
attributesTOValue = value.getProperties().iterator().next();
assertTrue(attributesTOValue.isInternal());
event.prepareContinue();
suspended[0] = true;
});
session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
functionValue.execute(mao);
session.close();
assertTrue(suspended[0]);
}
use of com.oracle.truffle.api.debug.SuspendedEvent in project graal by oracle.
the class DebuggerContextsTest method testSingleContext.
@Test
public void testSingleContext() {
final Source source = testSource("STATEMENT()");
TestContextsListener contextsListener = new TestContextsListener();
List<ContextEvent> events = contextsListener.events;
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
session.setContextsListener(contextsListener, false);
startEval(source);
expectSuspended((SuspendedEvent event) -> {
assertEquals(2, events.size());
assertTrue(events.get(0).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(0).language.getId());
assertNotNull(events.get(0).context);
assertTrue(events.get(1).languageInitialized);
});
expectDone();
closeEngine();
assertEquals(5, events.size());
assertTrue(events.get(2).languageFinalized);
assertEquals(InstrumentationTestLanguage.ID, events.get(2).language.getId());
assertEquals(events.get(0).context, events.get(2).context);
assertFalse(events.get(3).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(3).language.getId());
assertEquals(events.get(0).context, events.get(3).context);
assertFalse(events.get(4).created);
assertNull(events.get(4).language);
assertEquals(events.get(0).context, events.get(4).context);
}
events.clear();
}
use of com.oracle.truffle.api.debug.SuspendedEvent 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.SuspendedEvent 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();
}
Aggregations