Search in sources :

Example 1 with Location

use of com.oracle.truffle.tools.chromeinspector.types.Location in project graal by oracle.

the class TruffleDebugger method getPossibleBreakpoints.

@Override
public Params getPossibleBreakpoints(Location start, Location end, boolean restrictToFunction) throws CommandProcessException {
    int scriptId = start.getScriptId();
    if (scriptId != end.getScriptId()) {
        throw new CommandProcessException("Different location scripts: " + scriptId + ", " + end.getScriptId());
    }
    Script script = slh.getScript(scriptId);
    if (script == null) {
        throw new CommandProcessException("Unknown scriptId: " + scriptId);
    }
    Source source = script.getSource();
    int o1 = source.getLineStartOffset(start.getLine());
    if (start.getColumn() > 0) {
        o1 += start.getColumn() - 1;
    }
    int o2;
    if (end.getLine() > source.getLineCount()) {
        o2 = source.getLength();
    } else {
        o2 = source.getLineStartOffset(end.getLine());
        if (end.getColumn() > 0) {
            o2 += end.getColumn() - 1;
        }
    }
    SourceSection range = source.createSection(o1, o2 - o1);
    Iterable<SourceSection> locations = SuspendableLocationFinder.findSuspendableLocations(range, restrictToFunction, context.getEnv());
    JSONObject json = new JSONObject();
    JSONArray arr = new JSONArray();
    for (SourceSection ss : locations) {
        arr.put(new Location(scriptId, ss.getStartLine(), ss.getStartColumn()).toJSON());
    }
    json.put("locations", arr);
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Source(com.oracle.truffle.api.source.Source) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

Example 2 with Location

use of com.oracle.truffle.tools.chromeinspector.types.Location in project graal by oracle.

the class BreakpointsHandler method createURLBreakpoint.

Params createURLBreakpoint(Object url, int line, int column, String condition) {
    JSONArray locations = new JSONArray();
    long id;
    LoadScriptListener scriptListener;
    synchronized (bpIDs) {
        id = ++lastID;
        scriptListener = script -> {
            if (url instanceof Pattern ? ((Pattern) url).matcher(script.getUrl()).matches() : url.equals(script.getUrl())) {
                Breakpoint bp = createBuilder(script.getSource(), line, column).resolveListener(resolvedHandler).build();
                if (condition != null && !condition.isEmpty()) {
                    bp.setCondition(condition);
                }
                bp = ds.install(bp);
                synchronized (bpIDs) {
                    bpIDs.put(bp, id);
                    SourceSection section = resolvedBreakpoints.remove(bp);
                    if (section != null) {
                        Location resolvedLocation = new Location(script.getId(), section.getStartLine(), section.getStartColumn());
                        locations.put(resolvedLocation.toJSON());
                    }
                }
            }
        };
        scriptListeners.put(id, scriptListener);
    }
    slh.addLoadScriptListener(scriptListener);
    JSONObject json = new JSONObject();
    json.put("breakpointId", Long.toString(id));
    json.put("locations", locations);
    return new Params(json);
}
Also used : Pattern(java.util.regex.Pattern) 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) LoadScriptListener(com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

Example 3 with Location

use of com.oracle.truffle.tools.chromeinspector.types.Location 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)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 Location (com.oracle.truffle.tools.chromeinspector.types.Location)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 Script (com.oracle.truffle.tools.chromeinspector.types.Script)2 Source (com.oracle.truffle.api.source.Source)1 LoadScriptListener (com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)1 Pattern (java.util.regex.Pattern)1