Search in sources :

Example 1 with Callback

use of com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback in project graal by oracle.

the class DebuggerExampleTest method testStepOut.

@Test
@SuppressWarnings("hiding")
public void testStepOut() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(2, new Callback() {

        @Override
        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 2);
            debugger.stepOut(new Callback() {

                @Override
                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 6);
                    debugger.stepOver(new Callback() {

                        @Override
                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            throw new AssertionError();
                        }
                    });
                    allStepped.set(true);
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 2 with Callback

use of com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback in project graal by oracle.

the class DebuggerExampleTest method testStepInto.

@Test
@SuppressWarnings("hiding")
public void testStepInto() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(7, new Callback() {

        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 7);
            debugger.stepInto(new Callback() {

                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 4);
                    debugger.stepInto(new Callback() {

                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            assertLineAt(haltedAt, 5);
                            debugger.stepInto(new Callback() {

                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                    assertLineAt(haltedAt, 2);
                                    debugger.stepInto(new Callback() {

                                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                                            assertLineAt(haltedAt, 6);
                                            debugger.stepInto(new Callback() {

                                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                                    throw new AssertionError();
                                                }
                                            });
                                            allStepped.set(true);
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 3 with Callback

use of com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback in project graal by oracle.

the class DebuggerExampleTest method testStepOver.

@Test
@SuppressWarnings("hiding")
public void testStepOver() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(4, new Callback() {

        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 4);
            debugger.stepOver(new Callback() {

                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 5);
                    debugger.stepOver(new Callback() {

                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            assertLineAt(haltedAt, 6);
                            allStepped.set(true);
                            debugger.stepOver(new Callback() {

                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                    throw new AssertionError();
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 4 with Callback

use of com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback in project graal by oracle.

the class DebuggerExampleTest method testBreakpoint.

@Test
public void testBreakpoint() throws IOException {
    final AtomicBoolean breakpointHit = new AtomicBoolean();
    debugger.installBreakpoint(1, new Callback() {

        @Override
        public void halted(DebuggerController d, EventContext haltedAt) {
            Assert.assertEquals(1, haltedAt.getInstrumentedSourceSection().getStartLine());
            breakpointHit.set(true);
        }
    });
    run(lines("BLOCK(STATEMENT,", "STATEMENT,", "STATEMENT)"));
    Assert.assertTrue(breakpointHit.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Aggregations

EventContext (com.oracle.truffle.api.instrumentation.EventContext)4 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)4 Callback (com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.Test)4 Source (org.graalvm.polyglot.Source)3