Search in sources :

Example 16 with Breakpoint

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

the class BreakpointTest method testNotStepIntoBreakpointCondition.

@Test
public void testNotStepIntoBreakpointCondition() {
    Source defineSource = testSource("ROOT(DEFINE(test, ROOT(\n" + "STATEMENT(EXPRESSION),\n" + "CONSTANT(true))))");
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        startEval(defineSource);
        expectDone();
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        breakpoint.setCondition("CALL(test)");
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(2, event.getSourceSection().getStartLine());
            assertEquals(0, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        assertEquals(0, breakpoint.getHitCount());
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(3, event.getSourceSection().getStartLine());
            assertEquals(1, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        assertEquals(1, breakpoint.getHitCount());
        expectSuspended((SuspendedEvent event) -> {
            assertEquals("STATEMENT", event.getSourceSection().getCharacters());
            assertEquals(4, event.getSourceSection().getStartLine());
            assertEquals(0, event.getBreakpoints().size());
            event.prepareStepInto(1);
        });
        expectDone();
        assertEquals(1, breakpoint.getHitCount());
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 17 with Breakpoint

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

the class BreakpointTest method testBreakURI2.

@Test
public void testBreakURI2() throws Throwable {
    File testFile = testFile("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(testFile.toURI()).lineIs(4).build());
        session.suspendNextExecution();
        startEval(Source.newBuilder(InstrumentationTestLanguage.ID, testFile).build());
        for (int i = 0; i < 3; i++) {
            expectSuspended((SuspendedEvent event) -> {
                checkState(event, 4, true, "STATEMENT").prepareContinue();
            });
        }
        Assert.assertEquals(3, breakpoint.getHitCount());
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) File(java.io.File) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 18 with Breakpoint

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

the class BreakpointTest method testBreakpointConditionExecutedOnce.

@Test
public void testBreakpointConditionExecutedOnce() {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT,\n" + "STATEMENT)");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        breakpoint.setCondition("ROOT(PRINT(OUT, Hi), CONSTANT(true))");
        // Breakpoint only:
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertNull(event.getBreakpointConditionException(breakpoint));
        });
        assertEquals(1, breakpoint.getHitCount());
        expectDone();
        assertEquals("Hi", getOutput());
        // Breakpoint with step and an other breakpoint:
        Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(2, event.getBreakpoints().size());
            assertTrue(event.getBreakpoints().contains(breakpoint));
            assertTrue(event.getBreakpoints().contains(breakpoint2));
            assertNull(event.getBreakpointConditionException(breakpoint));
            assertNull(event.getBreakpointConditionException(breakpoint2));
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOver(1);
        });
        expectDone();
        assertEquals("HiHi", getOutput());
        assertEquals(2, breakpoint.getHitCount());
        assertEquals(1, breakpoint2.getHitCount());
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 19 with Breakpoint

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

the class SLDebugTest method testBreakpoint.

@Test
public void testBreakpoint() throws Throwable {
    /*
         * Wrappers need to remain inserted for recursive functions to work for debugging. Like in
         * this test case when the breakpoint is in the exit condition and we want to step out.
         */
    final Source factorial = slCode("function main() {\n" + "  return fac(5);\n" + "}\n" + "function fac(n) {\n" + "  if (n <= 1) {\n" + // break
    "    return 1;\n" + "  }\n" + "  return n * fac(n - 1);\n" + "}\n");
    try (DebuggerSession session = startSession()) {
        startEval(factorial);
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(factorial)).lineIs(6).build());
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 6, true, "return 1", "n", "1");
            checkArgs(event.getTopStackFrame(), "n", "1");
            Iterator<DebugStackFrame> sfi = event.getStackFrames().iterator();
            for (int i = 1; i <= 5; i++) {
                checkArgs(sfi.next(), "n", Integer.toString(i));
            }
            // main
            checkArgs(sfi.next());
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "2");
            checkArgs(event.getTopStackFrame(), "n", "2");
            assertEquals("1", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "3");
            assertEquals("2", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "4");
            assertEquals("6", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "fac", 8, false, "fac(n - 1)", "n", "5");
            assertEquals("24", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, "main", 2, false, "fac(5)");
            checkArgs(event.getTopStackFrame());
            assertEquals("120", event.getReturnValue().as(String.class));
            assertTrue(event.getBreakpoints().isEmpty());
            event.prepareStepOut(1);
        });
        assertEquals("120", expectDone());
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Test(org.junit.Test)

Example 20 with Breakpoint

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

the class DebuggerTesterSnippets method assertColumnBreakpointsResolution.

/**
 * Utility method that checks proper resolution of column breakpoints. Breakpoints are submitted
 * to marked positions and their resolution location is checked.
 * <p>
 * The source need to contain both breakpoint submission marks in the form of "B&lt;number&gt;_"
 * and breakpoint resolution marks in the form of "R&lt;number&gt;_" where &lt;number&gt; is an
 * identification of the breakpoint. These marks need to be placed at the proper breakpoint
 * submission/resolution line/column position. When several submitted breakpoints resolve to the
 * same position, an interval can be specified in the form of "R&lt;start number&gt;-&lt;end
 * number&gt;_", where both start and end line numbers are inclusive. The marks are stripped off
 * before execution.
 * <p>
 * The guest language code with marks may look like:
 *
 * <pre>
 * // B1_test
 * function B2_test(n) {B3_
 *   if (R1-4_n &lt;= B4_1) {B5_
 *     return R5_2 * n;
 *   }
 *   return R6_n - 1;
 * B6_}
 * </pre>
 *
 * @param sourceWithMarks a source text, which contains the resolution marks
 * @param breakpointMarkName the breakpoint submission mark name. It is used in a regular
 *            expression, therefore the mark must not have a special meaning in a regular
 *            expression.
 * @param resolvedMarkName the resolved mark name. It is used in a regular expression, therefore
 *            the mark must not have a special meaning in a regular expression.
 * @param language the source language
 * @since 0.33
 */
public void assertColumnBreakpointsResolution(String sourceWithMarks, String breakpointMarkName, String resolvedMarkName, String language) throws IOException {
    Pattern br = Pattern.compile("([" + breakpointMarkName + resolvedMarkName + "]\\d+_|" + resolvedMarkName + "\\d+-\\d+_)");
    Map<Integer, int[]> bps = new HashMap<>();
    String sourceString = sourceWithMarks;
    Matcher bm = br.matcher(sourceString);
    while (bm.find()) {
        String bg = bm.group();
        int index = bm.start();
        int state = (bg.charAt(0) == 'B') ? 0 : 1;
        String bpNums = bg.substring(1, bg.length() - 1);
        int bn1;
        int bn2;
        int rangeIndex = bpNums.indexOf('-');
        if (rangeIndex > 0) {
            bn1 = Integer.parseInt(bpNums.substring(0, rangeIndex));
            bn2 = Integer.parseInt(bpNums.substring(rangeIndex + 1));
        } else {
            bn1 = bn2 = Integer.parseInt(bpNums);
        }
        for (int bn = bn1; bn <= bn2; bn++) {
            int[] bp = bps.get(bn);
            if (bp == null) {
                bp = new int[2];
                bps.put(bn, bp);
            }
            if (bp[state] > 0) {
                Assert.fail(bg + " specified more than once.");
            }
            bp[state] = index + 1;
        }
        sourceString = bm.replaceFirst("");
        bm.reset(sourceString);
    }
    if (TRACE) {
        trace("sourceString = '" + sourceString + "'");
    }
    final Source source = Source.newBuilder(language, sourceString, "testMisplacedColumnBreakpoint." + language).build();
    for (Map.Entry<Integer, int[]> bentry : bps.entrySet()) {
        int bpId = bentry.getKey();
        int[] bp = bentry.getValue();
        Assert.assertTrue(Integer.toString(bpId), bp[0] > 0);
        Assert.assertTrue(Integer.toString(bpId), bp[1] > 0);
        int line = source.getLineNumber(bp[0] - 1);
        int column = source.getColumnNumber(bp[0] - 1);
        if (TRACE) {
            trace("TESTING BP_" + bpId + ": " + bp[0] + " (" + line + ":" + column + ") => " + bp[1] + ":");
        }
        try (DebuggerSession session = startSession()) {
            startEval(source);
            int[] resolvedIndexPtr = new int[] { 0 };
            Breakpoint breakpoint = session.install(Breakpoint.newBuilder(DebuggerTester.getSourceImpl(source)).lineIs(line).columnIs(column).oneShot().resolveListener(new Breakpoint.ResolveListener() {

                @Override
                public void breakpointResolved(Breakpoint brkp, SourceSection section) {
                    resolvedIndexPtr[0] = section.getCharIndex() + 1;
                    if (TRACE) {
                        trace("  resolved: " + (resolvedIndexPtr[0]));
                    }
                }
            }).build());
            expectSuspended((SuspendedEvent event) -> {
                Assert.assertEquals("Expected " + bp[0] + " => " + bp[1] + ", resolved at " + resolvedIndexPtr[0], bp[1], event.getSourceSection().getCharIndex() + 1);
                Assert.assertSame(breakpoint, event.getBreakpoints().iterator().next());
                event.prepareContinue();
            });
            expectDone();
            Assert.assertEquals("Expected resolved " + bp[0] + " => " + bp[1], bp[1], resolvedIndexPtr[0]);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Source(org.graalvm.polyglot.Source) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SourceSection(com.oracle.truffle.api.source.SourceSection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)44 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)36 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)36 Source (org.graalvm.polyglot.Source)35 Test (org.junit.Test)33 SourceSection (com.oracle.truffle.api.source.SourceSection)7 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)4 Debugger (com.oracle.truffle.api.debug.Debugger)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Pattern (java.util.regex.Pattern)3 DebugValue (com.oracle.truffle.api.debug.DebugValue)2 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)2 LoadScriptListener (com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)2 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)2 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 Location (com.oracle.truffle.tools.chromeinspector.types.Location)2 Script (com.oracle.truffle.tools.chromeinspector.types.Script)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2