Search in sources :

Example 41 with Breakpoint

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

the class BreakpointTest method testBreakSourceSection.

@Test
public void testBreakSourceSection() throws Throwable {
    final Source source = testSource("ROOT(STATEMENT, STATEMENT, STATEMENT)\n");
    try (DebuggerSession session = startSession()) {
        SourceSection sourceSection = getSourceImpl(source).createSection(16, 9);
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(sourceSection).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 1, true, "STATEMENT");
            Assert.assertEquals(sourceSection, event.getSourceSection());
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 42 with Breakpoint

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

the class BreakpointsHandler method createOneShotBreakpoint.

void createOneShotBreakpoint(Location location) throws CommandProcessException {
    Script script = slh.getScript(location.getScriptId());
    if (script == null) {
        throw new CommandProcessException("No script with id '" + location.getScriptId() + "'");
    }
    Breakpoint bp = createBuilder(script.getSource(), location.getLine(), location.getColumn()).oneShot().build();
    ds.install(bp);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Example 43 with Breakpoint

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

the class BreakpointsHandler method removeBreakpoint.

boolean removeBreakpoint(String idStr) {
    boolean bpRemoved = false;
    try {
        long id = Long.parseLong(idStr);
        synchronized (bpIDs) {
            Iterator<Map.Entry<Breakpoint, Long>> bpEntryIt = bpIDs.entrySet().iterator();
            while (bpEntryIt.hasNext()) {
                Map.Entry<Breakpoint, Long> bpEntry = bpEntryIt.next();
                if (id == bpEntry.getValue().longValue()) {
                    Breakpoint bp = bpEntry.getKey();
                    if (bp != null) {
                        bp.dispose();
                    }
                    bpEntryIt.remove();
                    bpRemoved = true;
                }
            }
            LoadScriptListener scriptListener = scriptListeners.remove(id);
            if (scriptListener != null) {
                slh.removeLoadScriptListener(scriptListener);
                bpRemoved = true;
            }
        }
    } catch (NumberFormatException nfex) {
    }
    return bpRemoved;
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) HashMap(java.util.HashMap) Map(java.util.Map) LoadScriptListener(com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)

Example 44 with Breakpoint

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

the class BreakpointsHandler method createBreakpoint.

Params createBreakpoint(Location location, String condition) throws CommandProcessException {
    Script script = slh.getScript(location.getScriptId());
    if (script == null) {
        throw new CommandProcessException("No script with id '" + location.getScriptId() + "'");
    }
    Breakpoint bp = createBuilder(script.getSource(), location.getLine(), location.getColumn()).resolveListener(resolvedHandler).build();
    if (condition != null && !condition.isEmpty()) {
        bp.setCondition(condition);
    }
    bp = ds.install(bp);
    JSONArray locations = new JSONArray();
    long id;
    synchronized (bpIDs) {
        id = ++lastID;
        bpIDs.put(bp, id);
        SourceSection section = resolvedBreakpoints.remove(bp);
        if (section != null) {
            Location resolvedLocation = new Location(location.getScriptId(), section.getStartLine(), section.getStartColumn());
            locations.put(resolvedLocation.toJSON());
        }
    }
    JSONObject json = new JSONObject();
    json.put("breakpointId", Long.toString(id));
    locations.put(location.toJSON());
    json.put("locations", locations);
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

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