Implement breakpointLocations DAP request handler to prevent DAP queue deadlocks#326
Open
mcollard0 wants to merge 1 commit into
Open
Implement breakpointLocations DAP request handler to prevent DAP queue deadlocks#326mcollard0 wants to merge 1 commit into
mcollard0 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When debugging Python applications using IDEs like VS Code, the IDE will eagerly issue a
breakpointLocationsrequest upon launch, even if the debugger officially declares"supportsBreakpointLocationsRequest": Falsein its initialization response.Because
pydevdlacked a handler forbreakpointLocations, the internalPyDevJsonCommandProcessorsilently caught the missing attribute, loggedUnhandled: on_breakpointlocations_request not available, and returnedNone. Because no DAP response (not even an error response) was ever formulated or dispatched back to the IDE, the IDE's DAP message queue locked up indefinitely waiting for it. This prevented all subsequent commands, including critical user interactions likepauserequests, from ever reachingpydevd.Solution
This PR introduces the missing
on_breakpointlocations_requesthandler withinpydevd_process_net_command_json.py.The handler leverages Python's built-in
astmodule to dynamically parse the target source file (if available locally) and walk the AST to extract all valid executable line numbers (lineno) within the requested boundaries.Features of the fix:
breakpointLocationsrequest, immediately unblocking the strict, serial DAP queues.astparser encounters a syntax error (or an exceptionally complex file), it gracefully falls back to returning an empty array{"breakpoints": []}. This is the minimum necessary response to satisfy the IDE without crashing the debugger thread.Testing
Tested manually by wrapping a large target script via
debugpylauncher and simulating raw JSON-RPC DAP interactions. Before this patch, the IDE queue stalled after thebreakpointLocationsrequest. After this patch,pydevdrapidly parsed a ~4,000-line AST, successfully returned the array of valid lines, and seamlessly handled trailingpauseevents.