Search in sources :

Example 1 with Debugger

use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.

the class NestedContextTest method testRecursiveEval.

@Test
public void testRecursiveEval() throws Exception {
    final Source testSource = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    final Context context = Context.create();
    final AtomicInteger suspensionCount = new AtomicInteger(0);
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {

        public void onSuspend(SuspendedEvent event) {
            checkState(event, 3, true, "STATEMENT");
            // recursive evaluation should not trigger a suspended event
            context.eval(testSource);
            suspensionCount.incrementAndGet();
        }
    })) {
        session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        context.eval(testSource);
    }
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 2 with Debugger

use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.

the class TimeBoxingTest method testTimeBoxing.

@Test
public void testTimeBoxing() throws Exception {
    final Context context = Context.create();
    Source source = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(LOOP(infinity,STATEMENT))", "NotEnoughTime").buildLiteral();
    new Timer().schedule(new TimerTask() {

        @Override
        public void run() {
            Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
            debugger.startSession(new SuspendedCallback() {

                public void onSuspend(SuspendedEvent event) {
                    event.prepareKill();
                }
            }).suspendNextExecution();
        }
    }, 1000);
    try {
        // throws KillException, wrapped by PolyglotException
        context.eval(source);
        Assert.fail();
    } catch (PolyglotException pex) {
        Assert.assertEquals("com.oracle.truffle.api.debug.KillException", pex.getMessage());
    }
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) Timer(java.util.Timer) TimerTask(java.util.TimerTask) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) PolyglotException(org.graalvm.polyglot.PolyglotException) Source(org.graalvm.polyglot.Source) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 3 with Debugger

use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.

the class DebuggerContextsTest method testMultipleContexts.

@Test
public void testMultipleContexts() {
    Source source = Source.create(InstrumentationTestLanguage.ID, "STATEMENT()");
    Engine engine = Engine.create();
    TestContextsListener contextsListener = new TestContextsListener();
    List<ContextEvent> events = contextsListener.events;
    int numContexts = 5;
    Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
    try (DebuggerSession session = debugger.startSession(null)) {
        session.setContextsListener(contextsListener, false);
        for (int i = 0; i < numContexts; i++) {
            try (Context context = Context.newBuilder().engine(engine).build()) {
                assertEquals(6 * i + 1, events.size());
                context.eval(source);
            }
            assertEquals(6 * i + 6, events.size());
        }
        assertEquals(6 * numContexts, events.size());
        DebugContext lastContext = null;
        for (int i = 0; i < numContexts; i++) {
            int ci = 6 * i;
            assertTrue(events.get(ci).created);
            assertNull(events.get(ci).language);
            assertNotEquals(lastContext, events.get(ci).context);
            lastContext = events.get(ci).context;
            assertTrue(events.get(ci + 1).created);
            assertNotNull(events.get(ci + 1).language);
            assertEquals(lastContext, events.get(ci + 1).context);
            assertTrue(events.get(ci + 2).languageInitialized);
            assertTrue(events.get(ci + 3).languageFinalized);
            assertNotNull(events.get(ci + 4).language);
            assertNull(events.get(ci + 5).language);
        }
        engine.close();
    }
    // No more events
    assertEquals(6 * numContexts, events.size());
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugContext(com.oracle.truffle.api.debug.DebugContext) Source(org.graalvm.polyglot.Source) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 4 with Debugger

use of com.oracle.truffle.api.debug.Debugger 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());
        }
    }
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) DebugContext(com.oracle.truffle.api.debug.DebugContext) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Example 5 with Debugger

use of com.oracle.truffle.api.debug.Debugger in project graal by oracle.

the class InstrumentLookupTest method testCanAccessDebuggerPolyglot.

@Test
public void testCanAccessDebuggerPolyglot() {
    Engine engine = Engine.create();
    Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
    Debugger debugger2 = Debugger.find(engine);
    assertSame(debugger, debugger2);
    assertNotNull(debugger);
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Aggregations

Debugger (com.oracle.truffle.api.debug.Debugger)20 Test (org.junit.Test)17 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)14 Context (org.graalvm.polyglot.Context)13 Source (org.graalvm.polyglot.Source)13 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)11 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)6 Engine (org.graalvm.polyglot.Engine)6 DebugContext (com.oracle.truffle.api.debug.DebugContext)5 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)4 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 Value (org.graalvm.polyglot.Value)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1