Skip to content

Commit

Permalink
Merge pull request #43517 from NipunaRanasinghe/debugger-fixes
Browse files Browse the repository at this point in the history
Fix intermittent exceptions in debugger on breakpoint hits and step-over commands
  • Loading branch information
NipunaRanasinghe authored Oct 23, 2024
2 parents 5b06398 + 68e12c3 commit 7b0d3e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand All @@ -68,7 +68,7 @@ public class BreakpointProcessor {

private final ExecutionContext context;
private final JDIEventProcessor jdiEventProcessor;
private final Map<String, LinkedHashMap<Integer, BalBreakpoint>> userBreakpoints = new HashMap<>();
private final Map<String, LinkedHashMap<Integer, BalBreakpoint>> userBreakpoints = new ConcurrentHashMap<>();
private static final Logger LOGGER = LoggerFactory.getLogger(BreakpointProcessor.class);

public BreakpointProcessor(ExecutionContext context, JDIEventProcessor jdiEventProcessor) {
Expand All @@ -77,7 +77,7 @@ public BreakpointProcessor(ExecutionContext context, JDIEventProcessor jdiEventP
}

public Map<String, LinkedHashMap<Integer, BalBreakpoint>> getUserBreakpoints() {
return Map.copyOf(userBreakpoints);
return userBreakpoints;
}

/**
Expand Down Expand Up @@ -250,8 +250,10 @@ void activateDynamicBreakPoints(int threadId, DynamicBreakpointMode mode) {
}
} catch (JdiProxyException e) {
LOGGER.error(e.getMessage());
int stepType = ((StepRequest) jdiEventProcessor.getStepRequests().get(0)).depth();
jdiEventProcessor.sendStepRequest(threadId, stepType);
if (!jdiEventProcessor.getStepRequests().isEmpty()) {
int stepType = ((StepRequest) jdiEventProcessor.getStepRequests().get(0)).depth();
jdiEventProcessor.sendStepRequest(threadId, stepType);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,27 @@ public CompletableFuture<SetBreakpointsResponse> setBreakpoints(SetBreakpointsAr
breakpointsMap.put(bp.getLine(), bp);
}

SetBreakpointsResponse breakpointsResponse = new SetBreakpointsResponse();
SetBreakpointsResponse bpResponse = new SetBreakpointsResponse();
String sourcePathUri = args.getSource().getPath();
Optional<String> qualifiedClassName = getQualifiedClassName(context, sourcePathUri);
qualifiedClassName.ifPresent(className -> {
eventProcessor.enableBreakpoints(className, breakpointsMap);
BreakpointProcessor breakpointProcessor = eventProcessor.getBreakpointProcessor();
Breakpoint[] breakpoints = breakpointProcessor.getUserBreakpoints().get(qualifiedClassName.get())
.values().stream()
.map(BalBreakpoint::getAsDAPBreakpoint)
.toArray(Breakpoint[]::new);
breakpointsResponse.setBreakpoints(breakpoints);
});
return breakpointsResponse;
if (qualifiedClassName.isEmpty()) {
LOGGER.warn("Failed to set breakpoints. Source path is not a valid Ballerina source: " + sourcePathUri);
return bpResponse;
}

eventProcessor.enableBreakpoints(qualifiedClassName.get(), breakpointsMap);
BreakpointProcessor bpProcessor = eventProcessor.getBreakpointProcessor();
Map<Integer, BalBreakpoint> userBpMap = bpProcessor.getUserBreakpoints().get(qualifiedClassName.get());
if (userBpMap == null) {
LOGGER.warn("Failed to set breakpoints for source: " + sourcePathUri);
return bpResponse;
}

Breakpoint[] breakpoints = userBpMap.values().stream()
.map(BalBreakpoint::getAsDAPBreakpoint)
.toArray(Breakpoint[]::new);
bpResponse.setBreakpoints(breakpoints);
return bpResponse;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;

import static org.ballerinalang.debugadapter.BreakpointProcessor.DynamicBreakpointMode;
import static org.ballerinalang.debugadapter.JBallerinaDebugServer.isBalStackFrame;
Expand All @@ -55,7 +56,7 @@ public class JDIEventProcessor {
private final ExecutionContext context;
private final BreakpointProcessor breakpointProcessor;
private boolean isRemoteVmAttached = false;
private final List<EventRequest> stepRequests = new ArrayList<>();
private final List<EventRequest> stepRequests = new CopyOnWriteArrayList<>();
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);

JDIEventProcessor(ExecutionContext context) {
Expand Down

0 comments on commit 7b0d3e9

Please sign in to comment.