Skip to content

Implement breakpointLocations DAP request handler to prevent DAP queue deadlocks#326

Open
mcollard0 wants to merge 1 commit into
fabioz:mainfrom
mcollard0:fix/dap-breakpoint-locations-deadlock
Open

Implement breakpointLocations DAP request handler to prevent DAP queue deadlocks#326
mcollard0 wants to merge 1 commit into
fabioz:mainfrom
mcollard0:fix/dap-breakpoint-locations-deadlock

Conversation

@mcollard0

Copy link
Copy Markdown

Problem

When debugging Python applications using IDEs like VS Code, the IDE will eagerly issue a breakpointLocations request upon launch, even if the debugger officially declares "supportsBreakpointLocationsRequest": False in its initialization response.

Because pydevd lacked a handler for breakpointLocations, the internal PyDevJsonCommandProcessor silently caught the missing attribute, logged Unhandled: on_breakpointlocations_request not available, and returned None. 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 like pause requests, from ever reaching pydevd.

Solution

This PR introduces the missing on_breakpointlocations_request handler within pydevd_process_net_command_json.py.

The handler leverages Python's built-in ast module 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:

  • Accurately identifies lines containing executable statements that can actually be broken on.
  • Satisfies the IDE's eager breakpointLocations request, immediately unblocking the strict, serial DAP queues.
  • Completely non-blocking and fault-tolerant: If the file cannot be read, or if the ast parser 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 debugpy launcher and simulating raw JSON-RPC DAP interactions. Before this patch, the IDE queue stalled after the breakpointLocations request. After this patch, pydevd rapidly parsed a ~4,000-line AST, successfully returned the array of valid lines, and seamlessly handled trailing pause events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant