use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class ConcurrentDebuggingTest method testConcurrentBreakpoints.
@Test
public void testConcurrentBreakpoints() {
int numThreads = 100;
String code = "ROOT(DEFINE(foo,\n" + " STATEMENT\n" + "),\n" + "LOOP(" + numThreads + ", SPAWN(foo)),\n" + "JOIN())";
final Source source = Source.create(InstrumentationTestLanguage.ID, code);
Breakpoint breakpoint = Breakpoint.newBuilder(source.getURI()).lineIs(2).build();
Context context = Context.newBuilder().allowCreateThread(true).build();
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
AtomicInteger hits = new AtomicInteger(0);
try (DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
assertEquals(1, event.getBreakpoints().size());
assertEquals(breakpoint, event.getBreakpoints().get(0));
hits.incrementAndGet();
})) {
session.install(breakpoint);
context.eval(source);
}
assertEquals(numThreads, hits.get());
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebugScopeTest method testArguments.
@Test
public void testArguments() {
final Source source = testSource("DEFINE(function, ROOT(\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);
boolean[] suspended = new boolean[] { false };
DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
assertFalse(suspended[0]);
Iterable<DebugValue> arguments = event.getTopStackFrame().getScope().getArguments();
assertNotNull(arguments);
Iterator<DebugValue> iterator = arguments.iterator();
assertTrue(iterator.hasNext());
DebugValue arg = iterator.next();
assertEquals("0", arg.getName());
assertEquals("true", arg.as(String.class));
assertTrue(iterator.hasNext());
arg = iterator.next();
assertEquals("1", arg.getName());
assertEquals("10", arg.as(String.class));
assertFalse(iterator.hasNext());
event.prepareContinue();
suspended[0] = true;
});
session.suspendNextExecution();
functionValue.execute(true, 10);
session.close();
assertTrue(suspended[0]);
}
use of com.oracle.truffle.api.debug.Debugger 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.Debugger 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.Debugger 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