use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class ValueLanguageTest method testValueLanguage.
@Test
public void testValueLanguage() {
Source source1 = Source.create(ValuesLanguage1.ID, "i=10\n" + "s=test\n" + "a=null\n" + "b={}\n" + "b.a={}\n" + "b.j=100\n" + "b.k=200\n");
Source source2 = Source.create(ValuesLanguage2.ID, "j=20\n" + "s=test2\n" + "d=null\n" + "e={}\n" + "b.c={}\n" + "e.d={}\n" + "e.k=200\n");
try (DebuggerSession session = startSession()) {
Breakpoint bp1 = Breakpoint.newBuilder(getSourceImpl(source1)).lineIs(7).build();
session.install(bp1);
startEval(source1);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugValue value = frame.getScope().getDeclaredValue("i");
assertNull(value.getOriginalLanguage());
assertEquals("L1:10", value.as(String.class));
value = frame.getScope().getDeclaredValue("s");
assertNull(value.getOriginalLanguage());
assertEquals("L1:test", value.as(String.class));
value = frame.getScope().getDeclaredValue("a");
assertNull(value.getOriginalLanguage());
assertEquals("null", value.as(String.class));
value = frame.getScope().getDeclaredValue("b");
LanguageInfo lang = value.getOriginalLanguage();
assertNotNull(lang);
assertEquals(ValuesLanguage1.NAME, lang.getName());
assertEquals("{a={}, j=100}", value.as(String.class));
event.prepareContinue();
});
expectDone();
Breakpoint bp2 = Breakpoint.newBuilder(getSourceImpl(source2)).lineIs(7).build();
session.install(bp2);
startEval(source2);
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame frame = event.getTopStackFrame();
DebugValue value = frame.getScope().getDeclaredValue("j");
assertNull(value.getOriginalLanguage());
assertEquals("L2:20", value.as(String.class));
value = frame.getScope().getDeclaredValue("s");
assertNull(value.getOriginalLanguage());
assertEquals("L2:test2", value.as(String.class));
value = frame.getScope().getDeclaredValue("e");
LanguageInfo lang2 = value.getOriginalLanguage();
assertNotNull(lang2);
assertEquals(ValuesLanguage2.NAME, lang2.getName());
assertEquals("{d={}}", value.as(String.class));
value = frame.getScope().getDeclaredValue("b");
LanguageInfo lang1 = value.getOriginalLanguage();
assertNotNull(lang1);
assertNotEquals(lang1, lang2);
assertEquals(ValuesLanguage1.NAME, lang1.getName());
// info from current lang2:
assertEquals("Object", value.as(String.class));
assertEquals("L2:Object", value.getMetaObject().as(String.class));
// info from original lang1:
value = value.asInLanguage(lang1);
assertEquals("{a={}, j=100, k=200, c={}}", value.as(String.class));
assertEquals("L1:Map", value.getMetaObject().as(String.class));
assertEquals("L2:Map", value.getMetaObject().asInLanguage(lang2).as(String.class));
// Properties are always in the original language:
value = frame.getScope().getDeclaredValue("b");
DebugValue a = value.getProperties().iterator().next();
assertEquals(lang1, a.getOriginalLanguage());
Iterator<DebugValue> it = value.getProperties().iterator();
it.next();
it.next();
it.next();
DebugValue c = it.next();
assertEquals(lang2, c.getOriginalLanguage());
value = value.asInLanguage(lang2);
a = value.getProperties().iterator().next();
assertEquals(lang1, a.getOriginalLanguage());
it = value.getProperties().iterator();
it.next();
it.next();
it.next();
c = it.next();
assertEquals(lang2, c.getOriginalLanguage());
value = frame.getScope().getDeclaredValue("j");
assertNull(value.getSourceLocation());
value = value.asInLanguage(lang1);
assertEquals("L1:20", value.as(String.class));
assertNull(value.getSourceLocation());
value = frame.getScope().getDeclaredValue("d");
assertEquals("null", value.as(String.class));
value = value.asInLanguage(lang1);
assertEquals("null", value.as(String.class));
value = frame.getScope().getDeclaredValue("e");
assertEquals(getSourceImpl(source2).createSection(4, 3, 2), value.getSourceLocation());
value = value.asInLanguage(lang1);
assertNull(value.getSourceLocation());
event.prepareContinue();
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugScopeTest method testTopScope.
// Local scopes are well tested by DebugStackFrameTest and others.
@Test
public void testTopScope() {
final Source source = testSource("ROOT(DEFINE(function1,ROOT(\n" + " EXPRESSION()\n" + " )\n" + "),\n" + "DEFINE(g,ROOT(\n" + " EXPRESSION()\n" + " )\n" + "),\n" + "STATEMENT())\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
DebugScope topScope = session.getTopScope(event.getSourceSection().getSource().getLanguage());
assertNotNull(topScope);
DebugValue function1 = topScope.getDeclaredValue("function1");
assertNotNull(function1);
assertTrue(function1.as(String.class).contains("Function"));
DebugValue functionType = function1.getMetaObject();
assertEquals("Function", functionType.as(String.class));
assertEquals(function1.getOriginalLanguage(), functionType.getOriginalLanguage());
DebugValue g = topScope.getDeclaredValue("g");
assertNotNull(g);
assertTrue(g.as(String.class).contains("Function"));
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugValue in project graal by oracle.
the class DebugStackFrameTest method testEvalAndSideEffects.
@Test
public void testEvalAndSideEffects() throws Throwable {
final Source source = testSource("ROOT(DEFINE(a,ROOT( \n" + " VARIABLE(a, 42), \n" + " VARIABLE(b, 43), \n" + " VARIABLE(c, 44), \n" + // will start stepping here
" STATEMENT(),\n" + " STATEMENT())\n" + "), \n" + "VARIABLE(a, 42), VARIABLE(b, 43), VARIABLE(c, 44), \n" + "CALL(a))\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
expectSuspended((SuspendedEvent event) -> {
Iterator<DebugStackFrame> stackFrames = event.getStackFrames().iterator();
// assert changes to the current frame
DebugStackFrame frame = stackFrames.next();
assertDynamicFrame(frame);
DebugValue aValue = frame.getScope().getDeclaredValue("a");
String aStringValue = aValue.as(String.class);
// assert changes to a parent frame
frame = stackFrames.next();
assertDynamicFrame(frame);
// assign from one stack frame to another one
frame.getScope().getDeclaredValue("a").set(aValue);
assertEquals(aStringValue, frame.getScope().getDeclaredValue("a").as(String.class));
event.prepareContinue();
});
expectDone();
}
}
use of com.oracle.truffle.api.debug.DebugValue 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.DebugValue in project graal by oracle.
the class TruffleRuntime method evaluate.
@Override
public Params evaluate(String expression, String objectGroup, boolean includeCommandLineAPI, boolean silent, int contextId, boolean returnByValue, boolean awaitPromise) throws CommandProcessException {
if (expression == null) {
throw new CommandProcessException("An expression required.");
}
JSONObject json = new JSONObject();
DebuggerSuspendedInfo suspendedInfo = context.getSuspendedInfo();
if (suspendedInfo != null) {
try {
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
JSONObject result;
DebugValue value = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(expression);
if (returnByValue) {
result = RemoteObject.createJSONResultValue(value, context.getErr());
} else {
RemoteObject ro = new RemoteObject(value, context.getErr());
context.getRemoteObjectsHandler().register(ro);
result = ro.toJSON();
}
json.put("result", result);
return null;
}
});
} catch (NoSuspendedThreadException ex) {
JSONObject exceptionDetails = new JSONObject();
exceptionDetails.put("text", ex.getLocalizedMessage());
json.put("exceptionDetails", exceptionDetails);
} catch (GuestLanguageException ex) {
fillExceptionDetails(json, ex);
}
} else {
JSONObject exceptionDetails = new JSONObject();
exceptionDetails.put("text", "<Not suspended>");
json.put("exceptionDetails", exceptionDetails);
}
return new Params(json);
}
Aggregations