Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Fix #1093: breakpoint are not hit when debugger is attached to remote…
Browse files Browse the repository at this point in the history
… target (#1137)

Do not allow 'setBreakpoints' request until either 'launch' or 'attach' request is received.

Wait for 'launch' or 'attach' request to process path mappings before handling 'setBreakpoints'.
  • Loading branch information
int19h authored Feb 1, 2019
1 parent 5acbb39 commit 07dc5e4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,15 +1213,15 @@ def on_attach(self, request, args):
multiproc.root_start_request = request
self.start_reason = 'attach'
self._set_debug_options(args)
self._handle_attach(request, args)
self._handle_launch_or_attach(request, args)
self.send_response(request)

def on_launch(self, request, args):
multiproc.root_start_request = request
self.start_reason = 'launch'
self._set_debug_options(args)
self._notify_launch()
self._handle_launch(request, args)
self._handle_launch_or_attach(request, args)
self.send_response(request)

def on_disconnect(self, request, args):
Expand Down Expand Up @@ -1302,10 +1302,7 @@ def _process_debug_options(self, opts):
def _handle_configurationDone(self, request, args):
pass

def _handle_attach(self, request, args):
pass

def _handle_launch(self, request, args):
def _handle_launch_or_attach(self, request, args):
pass

def _handle_detach(self):
Expand Down Expand Up @@ -1356,6 +1353,8 @@ def __init__(self, socket, pydevd_notify, pydevd_request,
# adapter state
self.path_casing = PathUnNormcase()
self._detached = False
self._path_mappings_received = False
self._path_mappings_applied = False

def _start_event_loop(self):
self.loop = futures.EventLoop()
Expand Down Expand Up @@ -1609,6 +1608,8 @@ def _initialize_path_maps(self, args):
if len(self._path_mappings) > 0:
pydevd_file_utils.setup_client_server_paths(self._path_mappings)

self._path_mappings_applied = True

def _send_cmd_version_command(self):
cmd = pydevd_comm.CMD_VERSION
default_os_type = 'WINDOWS' if platform.system() == 'Windows' else 'UNIX'
Expand All @@ -1618,18 +1619,9 @@ def _send_cmd_version_command(self):
return self.pydevd_request(cmd, msg)

@async_handler
def _handle_attach(self, request, args):
self.pydevd_request(pydevd_comm.CMD_SET_PROTOCOL, 'json')
yield self._send_cmd_version_command()

pydevd_request = copy.deepcopy(request)
del pydevd_request['seq'] # A new seq should be created for pydevd.
yield self.pydevd_request(-1, pydevd_request, is_json=True)

self._initialize_path_maps(args)
def _handle_launch_or_attach(self, request, args):
self._path_mappings_received = True

@async_handler
def _handle_launch(self, request, args):
self.pydevd_request(pydevd_comm.CMD_SET_PROTOCOL, 'json')
yield self._send_cmd_version_command()

Expand Down Expand Up @@ -2276,6 +2268,15 @@ def _get_bp_type(self, path):

@async_handler
def on_setBreakpoints(self, request, args):
if not self._path_mappings_received:
self.send_error_response(request, "'setBreakpoints' request must be issued after 'launch' or 'attach' request.")
return

# There might be a concurrent 'launch' or 'attach' request in flight that hasn't
# gotten to processing path mappings yet. If so, spin until it finishes that.
while not self._path_mappings_applied:
yield self.sleep()

pydevd_request = copy.deepcopy(request)
del pydevd_request['seq'] # A new seq should be created for pydevd.
_, _, resp_args = yield self.pydevd_request(
Expand Down

0 comments on commit 07dc5e4

Please sign in to comment.