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);
}
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);
}
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);
}
Aggregations