use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebuggerThreadsTest method testContextThreads.
@Test
public void testContextThreads() throws Exception {
Engine engine = Engine.create();
final Source source = testSource("STATEMENT()");
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
int numThreads = 10;
Thread[] threads = new Thread[numThreads];
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(null)) {
session.setThreadsListener(threadsListener, false);
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread() {
@Override
public void run() {
try (Context context = Context.newBuilder().engine(engine).build()) {
context.eval(source);
}
}
};
}
for (int i = 0; i < numThreads; i++) {
threads[i].start();
}
for (int i = 0; i < numThreads; i++) {
threads[i].join();
}
}
assertEquals(2 * numThreads, events.size());
List<ThreadEvent> startEvents = new ArrayList<>(numThreads);
for (ThreadEvent event : events) {
if (event.isNew) {
startEvents.add(event);
}
}
assertEquals(numThreads, startEvents.size());
// Verify that we got all threads in the events:
Set<Thread> allThreads = new HashSet<>(Arrays.asList(threads));
for (int i = 0; i < numThreads; i++) {
assertTrue(allThreads.remove(startEvents.get(i).thread));
}
assertTrue(allThreads.toString(), allThreads.isEmpty());
// Verify that we got 'numThreads' number of contexts:
Set<DebugContext> distinctContexts = new HashSet<>();
for (ThreadEvent event : events) {
distinctContexts.add(event.context);
}
assertEquals(numThreads, distinctContexts.size());
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebuggerThreadsTest method testGetStartedThreads.
@Test
public void testGetStartedThreads() throws Exception {
Engine engine = Engine.create();
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
CountDownLatch latch = new CountDownLatch(1);
DebuggerSession[] sessionPtr = new DebuggerSession[1];
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
latch.countDown();
sessionPtr[0].setThreadsListener(threadsListener, true);
assertEquals(events.toString(), 2, events.size());
assertTrue(events.get(0).isNew);
assertNotNull(events.get(0).context);
assertTrue(events.get(1).isNew);
assertEquals(events.get(0).context, events.get(1).context);
assertNotEquals(events.get(0).thread, events.get(1).thread);
}
})) {
session.suspendNextExecution();
sessionPtr[0] = session;
try (Context context = Context.newBuilder().engine(engine).allowCreateThread(true).build()) {
Source source = testSource("ROOT(DEFINE(f1, EXPRESSION), SPAWN(f1), JOIN())");
context.eval(source);
source = testSource("ROOT(DEFINE(foo, STATEMENT), SPAWN(foo))");
context.eval(source);
latch.await();
context.eval(testSource("JOIN()"));
assertEquals(events.toString(), 3, events.size());
assertFalse(events.get(2).isNew);
assertTrue(events.get(0).thread == events.get(2).thread || events.get(1).thread == events.get(2).thread);
}
assertEquals(4, events.size());
}
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class DebugSpeedBench method beforeTesting.
@Setup
public void beforeTesting() throws IOException {
source = Source.newBuilder("instrumentation-test-language", CODE_STEP, "StepTest.instr").build();
context = Context.create();
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
session = debugger.startSession(this);
session.suspendNextExecution();
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class BreakpointTest method testGlobalBreakpoints.
@Test
// auto-closeable resource session is never referenced in body of
@SuppressWarnings("try")
public // corresponding try statement
void testGlobalBreakpoints() throws Throwable {
try {
Class.forName("java.beans.PropertyChangeListener");
} catch (ClassNotFoundException ex) {
// skip the test if running only with java.base JDK9 module
return;
}
final Source source = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
Debugger debugger = getDebugger();
assertTrue(debugger.getBreakpoints().isEmpty());
Breakpoint globalBreakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
boolean[] notified = new boolean[] { false };
BreakpointListener newBPListener = BreakpointListener.register(notified, debugger, globalBreakpoint);
debugger.install(globalBreakpoint);
Assert.assertTrue(notified[0]);
Assert.assertEquals(1, debugger.getBreakpoints().size());
Breakpoint newBP = debugger.getBreakpoints().get(0);
Assert.assertTrue(globalBreakpoint.isModifiable());
Assert.assertFalse(newBP.isModifiable());
try {
newBP.dispose();
Assert.fail("Public dispose must not be possible for global breakpoints.");
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setCondition("Something");
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setCondition(null);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setEnabled(false);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
try {
newBP.setIgnoreCount(10);
Assert.fail();
} catch (IllegalStateException ex) {
// O.K.
}
Assert.assertNull(newBP.getCondition());
Assert.assertEquals(0, newBP.getHitCount());
Assert.assertTrue(newBP.isEnabled());
Assert.assertFalse(newBP.isDisposed());
Assert.assertFalse(newBP.isResolved());
try (DebuggerSession session = startSession()) {
// global breakpoint is not among session breakpoints
Assert.assertTrue(session.getBreakpoints().isEmpty());
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
assertEquals(1, event.getBreakpoints().size());
Breakpoint eventBP = event.getBreakpoints().get(0);
try {
eventBP.dispose();
Assert.fail("Public dispose must not be possible for global breakpoints.");
} catch (IllegalStateException ex) {
// O.K.
}
Assert.assertTrue(eventBP.isResolved());
event.prepareContinue();
});
}
assertFalse(newBP.isDisposed());
assertFalse(newBP.isResolved());
expectDone();
try (DebuggerSession session = startSession()) {
startEval(source);
expectSuspended((SuspendedEvent event) -> {
checkState(event, 2, true, "STATEMENT");
event.prepareContinue();
});
}
expectDone();
newBPListener.unregister();
notified[0] = false;
BreakpointDisposeListener.register(notified, debugger, globalBreakpoint);
globalBreakpoint.dispose();
Assert.assertTrue(notified[0]);
Assert.assertEquals(0, debugger.getBreakpoints().size());
}
use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.
the class TruffleDebugger method doEnable.
private void doEnable() {
Debugger tdbg = context.getEnv().lookup(context.getEnv().getInstruments().get("debugger"), Debugger.class);
ds = tdbg.startSession(new SuspendedCallbackImpl());
ds.setSteppingFilter(SuspensionFilter.newBuilder().ignoreLanguageContextInitialization(true).includeInternal(false).build());
slh = context.getScriptsHandler();
bph = new BreakpointsHandler(ds, slh, () -> eventHandler);
}
Aggregations