Search in sources :

Example 1 with LoadScriptListener

use of com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener 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 2 with LoadScriptListener

use of com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener 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)

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2 LoadScriptListener (com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)2 SourceSection (com.oracle.truffle.api.source.SourceSection)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 Location (com.oracle.truffle.tools.chromeinspector.types.Location)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1