in com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetDataBreakpointsRequestHandler.java [54:116]
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
if (context.getDebugSession() == null) {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Empty debug session.");
}
if (!registered) {
registered = true;
registerWatchpointHandler(context);
}
SetDataBreakpointsArguments dataBpArgs = (SetDataBreakpointsArguments) arguments;
IWatchpoint[] requestedWatchpoints = (dataBpArgs.breakpoints == null) ? new Watchpoint[0] : new Watchpoint[dataBpArgs.breakpoints.length];
for (int i = 0; i < requestedWatchpoints.length; i++) {
DataBreakpoint dataBreakpoint = dataBpArgs.breakpoints[i];
if (dataBreakpoint.dataId != null) {
String[] segments = dataBreakpoint.dataId.split("#");
if (segments.length == 2 && StringUtils.isNotBlank(segments[0]) && StringUtils.isNotBlank(segments[1])) {
int hitCount = 0;
try {
hitCount = Integer.parseInt(dataBreakpoint.hitCondition);
} catch (NumberFormatException e) {
hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition.
}
String accessType = dataBreakpoint.accessType != null ? dataBreakpoint.accessType.label() : null;
requestedWatchpoints[i] = context.getDebugSession().createWatchPoint(segments[0], segments[1], accessType,
dataBreakpoint.condition, hitCount);
}
}
}
IWatchpoint[] currentWatchpoints = context.getBreakpointManager().setWatchpoints(requestedWatchpoints);
List<Breakpoint> breakpoints = new ArrayList<>();
for (int i = 0; i < currentWatchpoints.length; i++) {
if (currentWatchpoints[i] == null) {
breakpoints.add(new Breakpoint(false));
continue;
}
// If the requested watchpoint exists in the watchpoint manager, it will reuse the cached watchpoint object.
// Otherwise add the requested watchpoint to the cache.
// So if the returned watchpoint from the manager is same as the requested wantchpoint, this means it's a new watchpoint, need install it.
if (currentWatchpoints[i] == requestedWatchpoints[i]) {
currentWatchpoints[i].install().thenAccept(wp -> {
BreakpointEvent bpEvent = new BreakpointEvent("new", convertDebuggerWatchpointToClient(wp));
context.getProtocolServer().sendEvent(bpEvent);
});
} else {
if (currentWatchpoints[i].getHitCount() != requestedWatchpoints[i].getHitCount()) {
currentWatchpoints[i].setHitCount(requestedWatchpoints[i].getHitCount());
}
if (!Objects.equals(currentWatchpoints[i].getCondition(), requestedWatchpoints[i].getCondition())) {
currentWatchpoints[i].setCondition(requestedWatchpoints[i].getCondition());
}
}
breakpoints.add(convertDebuggerWatchpointToClient(currentWatchpoints[i]));
}
response.body = new Responses.SetDataBreakpointsResponseBody(breakpoints);
return CompletableFuture.completedFuture(response);
}