use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebugStackFrameTest method testFrameValidity.
@Test
public void testFrameValidity() throws Throwable {
final Source source = testSource("ROOT(\n" + " VARIABLE(a, 42), \n" + " VARIABLE(b, 43), \n" + " VARIABLE(c, 44), \n" + " STATEMENT(),\n" + " STATEMENT()\n" + ")\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
class SharedData {
DebugStackFrame frame;
DebugValue stackValueWithGetValue;
DebugValue stackValueWithIterator;
Iterator<DebugStackFrame> frameIterator2;
DebugValue heapValue;
}
SharedData data = new SharedData();
expectSuspended((SuspendedEvent event) -> {
data.frame = event.getTopStackFrame();
Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
assertSame(data.frame, frameIterator.next());
assertFalse(frameIterator.hasNext());
checkStack(data.frame, "a", "42", "b", "43", "c", "44");
// values for verifying state checks
data.frameIterator2 = event.getStackFrames().iterator();
data.stackValueWithGetValue = data.frame.getScope().getDeclaredValue("a");
data.stackValueWithIterator = data.frame.getScope().getDeclaredValues().iterator().next();
// should dynamically create a local variable
data.heapValue = data.frame.eval("VARIABLE(d, 45)");
// should render all pointers invalid
event.prepareStepInto(1);
});
expectSuspended((SuspendedEvent event) -> {
// next event everything should be invalidated except heap values
assertInvalidFrame(data.frame);
assertInvalidIterator(data.frameIterator2);
assertInvalidDebugValue(data.stackValueWithGetValue);
assertInvalidDebugValue(data.stackValueWithIterator);
assertEquals("45", data.heapValue.as(String.class));
assertFalse(data.heapValue.isWritable());
assertTrue(data.heapValue.isReadable());
try {
data.heapValue.set(data.heapValue);
fail();
} catch (IllegalStateException e) {
}
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebuggerSession 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.DebuggerSession 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.DebuggerSession in project graal by oracle.
the class DebuggerContextsTest method testInnerContext.
@Test
public void testInnerContext() {
final Source source = testSource("ROOT(STATEMENT(), CONTEXT(STATEMENT()))");
TestContextsListener contextsListener = new TestContextsListener();
List<ContextEvent> events = contextsListener.events;
try (DebuggerSession session = startSession()) {
session.setContextsListener(contextsListener, false);
startEval(source);
expectDone();
assertEquals(8, events.size());
assertTrue(events.get(0).created);
assertTrue(events.get(1).languageInitialized);
assertNotEquals(events.get(1).context, events.get(2).context);
assertEquals(events.get(1).context, events.get(2).context.getParent());
assertTrue(events.get(2).created);
assertNull(events.get(2).language);
assertTrue(events.get(3).created);
assertNotNull(events.get(3).language);
assertTrue(events.get(4).languageInitialized);
assertTrue(events.get(5).languageFinalized);
assertFalse(events.get(6).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(6).language.getId());
assertFalse(events.get(7).created);
assertNull(events.get(7).language);
assertEquals(events.get(2).context, events.get(7).context);
closeEngine();
}
assertEquals(11, events.size());
assertTrue(events.get(8).languageFinalized);
assertEquals(events.get(0).context, events.get(8).context);
assertFalse(events.get(9).created);
assertEquals(InstrumentationTestLanguage.ID, events.get(9).language.getId());
assertFalse(events.get(10).created);
assertNull(events.get(10).language);
assertEquals(events.get(0).context, events.get(10).context);
}
use of com.oracle.truffle.api.debug.DebuggerSession 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();
}
Aggregations