Search in sources :

Example 1 with FunctionBreakpoint

use of com.oracle.truffle.tools.dap.types.FunctionBreakpoint in project graal by oracle.

the class BreakpointsHandler method setFunctionBreakpoints.

public List<com.oracle.truffle.tools.dap.types.Breakpoint> setFunctionBreakpoints(SetFunctionBreakpointsArguments args) {
    Map<FunctionBreakpoint, Integer> toAdd = new HashMap<>();
    Map<FunctionBreakpoint, Integer> toRemove = functionBreakpoints.getAndSet(toAdd);
    List<com.oracle.truffle.tools.dap.types.Breakpoint> breakpoints = new ArrayList<>(args.getBreakpoints().size());
    for (FunctionBreakpoint functionBreakpoint : args.getBreakpoints()) {
        Integer id;
        Breakpoint bp;
        SourceSection section;
        String message = null;
        synchronized (bp2IDs) {
            id = toRemove != null ? toRemove.remove(functionBreakpoint) : null;
        }
        if (id == null) {
            Breakpoint.Builder builder = Breakpoint.newBuilder((Source) null).sourceElements(SourceElement.ROOT);
            bp = builder.resolveListener(resolvedHandler).build();
            if (functionBreakpoint.getCondition() != null && !functionBreakpoint.getCondition().isEmpty()) {
                bp.setCondition(functionBreakpoint.getCondition());
            }
            String[] hitCondition = null;
            if (functionBreakpoint.getHitCondition() != null) {
                String trimmedHitCondition = functionBreakpoint.getHitCondition().trim();
                if (!trimmedHitCondition.isEmpty()) {
                    Matcher matcher = HITCONDITION_REGEXP.matcher(trimmedHitCondition);
                    if (matcher.matches() && matcher.groupCount() == 2) {
                        if (matcher.group(0) == null) {
                            builder.ignoreCount(Integer.parseInt(matcher.group(2)));
                        } else {
                            hitCondition = new String[] { matcher.group(1), matcher.group(2) };
                        }
                    } else {
                        message = "Invalid hit condition: " + trimmedHitCondition;
                    }
                }
            }
            bp = debuggerSession.install(bp);
            synchronized (bp2IDs) {
                id = ++lastId;
                bp2IDs.put(bp, id);
                id2Bps.put(id, bp);
                if (hitCondition != null) {
                    hitConditions.put(bp, hitCondition);
                }
                functionNames.put(bp, functionBreakpoint.getName());
            }
        } else {
            bp = id2Bps.get(id);
        }
        synchronized (bp2IDs) {
            toAdd.put(functionBreakpoint, id);
            section = resolvedBreakpoints.get(bp);
        }
        if (section != null) {
            breakpoints.add(// 
            com.oracle.truffle.tools.dap.types.Breakpoint.create(message == null).setId(id).setMessage(message).setLine(context.debuggerToClientLine(section.getStartLine())).setColumn(// 
            context.debuggerToClientColumn(section.getStartColumn())).setEndLine(context.debuggerToClientLine(section.getEndLine())).setEndColumn(context.debuggerToClientColumn(section.getEndColumn())));
        } else {
            breakpoints.add(com.oracle.truffle.tools.dap.types.Breakpoint.create(false).setId(id).setMessage(message));
        }
    }
    if (toRemove != null) {
        for (Integer id : toRemove.values()) {
            synchronized (bp2IDs) {
                Breakpoint bp = id2Bps.remove(id);
                if (bp != null) {
                    bp.dispose();
                    bp2IDs.remove(bp);
                    logMessages.remove(bp);
                    hitConditions.remove(bp);
                    resolvedBreakpoints.remove(bp);
                    functionNames.remove(bp);
                }
            }
        }
    }
    return breakpoints;
}
Also used : SourceBreakpoint(com.oracle.truffle.tools.dap.types.SourceBreakpoint) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) FunctionBreakpoint(com.oracle.truffle.tools.dap.types.FunctionBreakpoint) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Source(com.oracle.truffle.api.source.Source) FunctionBreakpoint(com.oracle.truffle.tools.dap.types.FunctionBreakpoint) SourceSection(com.oracle.truffle.api.source.SourceSection)

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 Source (com.oracle.truffle.api.source.Source)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 FunctionBreakpoint (com.oracle.truffle.tools.dap.types.FunctionBreakpoint)1 SourceBreakpoint (com.oracle.truffle.tools.dap.types.SourceBreakpoint)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1