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

Commit

Permalink
Send continued event when all threads resume. Fixes #1530. (#1554)
Browse files Browse the repository at this point in the history
* Send continued event when all threads resume. Fixes #1530.

* Don't hide exception if connect_with_new_session fails.

* Don't send resumed event if we haven't initialized first (fix test_reattach).
  • Loading branch information
fabioz authored Jul 3, 2019
1 parent 9666eac commit 27e6388
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ def __init__(
# https://github.com/Microsoft/VSDebugAdapterHost/wiki/Differences-between-Visual-Studio-Code-and-the-Visual-Studio-Debug-Adapter-Host # noqa
# VS expects a single stopped event in a multi-threaded scenario.
self._client_id = None
self._initialize_received = False

# adapter state
self.start_reason = None
Expand Down Expand Up @@ -730,6 +731,7 @@ def handle_exiting(self, exitcode=None, wait=None):
def on_initialize(self, request, args):
self._client_id = args.get('clientID', None)
self._restart_debugger = False
self._initialize_received = True
self.send_response(request, **INITIALIZE_RESPONSE)
self.send_event('initialized')

Expand Down Expand Up @@ -1312,10 +1314,17 @@ def on_pydevd_thread_suspend_single_notification(self, seq, args):

@pydevd_events.handler(pydevd_comm_constants.CMD_THREAD_RESUME_SINGLE_NOTIFICATION)
def on_pydevd_thread_resume_single_notification(self, seq, args):
tid = args['body']['threadId']

if os.getenv('PTVSD_USE_CONTINUED'):
self.send_event('continued', threadId=tid)
if not self._initialize_received:
return # This may happen when we disconnect and later reconnect too fast.
body = args['body']
if self._client_id not in ('visualstudio', 'vsformac'):
# In visual studio any step/continue action already marks all the
# threads as running until a suspend, so, the continued is not
# needed (and can in fact break the UI in some cases -- see:
# https://github.com/microsoft/ptvsd/issues/1358).
# It is however needed in vscode -- see:
# https://github.com/microsoft/ptvsd/issues/1530.
self.send_event('continued', **body)

@pydevd_events.handler(pydevd_comm.CMD_WRITE_TO_CONSOLE)
def on_pydevd_cmd_write_to_console2(self, seq, args):
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def func():
target=(run_as, code_to_debug),
start_method=start_method,
ignore_unobserved=[Event('continued')],
env={'PTVSD_USE_CONTINUED': '1'},
client_id='vscode',
)
session.set_breakpoints(code_to_debug, [line_numbers['inner1']])
session.start_debugging()
Expand Down
3 changes: 2 additions & 1 deletion tests/func/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


def test_tracing(pyfile, start_method, run_as):

@pyfile
def code_to_debug():
from dbgimporter import import_and_enable_debugger
Expand Down Expand Up @@ -61,7 +62,7 @@ def inner2():
target=(run_as, code_to_debug),
start_method=start_method,
ignore_unobserved=[Event('continued')],
env={'PTVSD_USE_CONTINUED': '1'},
client_id='vscode',
)

session.set_breakpoints(code_to_debug, line_numbers.values())
Expand Down
11 changes: 10 additions & 1 deletion tests/helpers/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(self, start_method='launch', ptvsd_port=None, pid=None):

print('New debug session with method %r' % str(start_method))

# Note: with 'visualstudio' we don't send continued events.
self.client_id = 'visualstudio'

self.target = ('code', 'print("OK")')
self.start_method = start_method
self.start_method_args = {}
Expand Down Expand Up @@ -271,6 +274,8 @@ def initialize(self, **kwargs):
print('Initializing debug session for ptvsd#%d' % self.ptvsd_port)
dbg_argv = []
usr_argv = []
if 'client_id' in kwargs:
self.client_id = kwargs['client_id']
if self.start_method == 'launch':
self._listen()
dbg_argv += self._get_argv_for_launch()
Expand Down Expand Up @@ -523,7 +528,10 @@ def handshake(self):
to finalize the configuration stage, and start running code.
"""

self.send_request('initialize', {'adapterID': 'test'}).wait_for_response()
self.send_request(
'initialize',
{'adapterID': 'test', 'clientID': self.client_id}
).wait_for_response()
self.wait_for_next(Event('initialized', {}))

request = 'launch' if self.start_method == 'launch' else 'attach'
Expand Down Expand Up @@ -729,5 +737,6 @@ def connect_with_new_session(self, **kwargs):
ns.handshake()
except:
ns.close()
raise
else:
return ns

0 comments on commit 27e6388

Please sign in to comment.