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

Move more code to pydevd #1519

Merged
merged 3 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def _evaluate_response(py_db, request, result, error_message=''):
variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body})
py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True))
else:
body = pydevd_schema.EvaluateResponseBody(result='', variablesReference=0)
body = pydevd_schema.EvaluateResponseBody(result=result, variablesReference=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, reviewing this now it seems that result can be any Python object if py_db.suspended_frames_manager.get_frame_tracker(thread_id) returns None, in internal_evaluate_expression_json, which is unlikely but not impossible on a racing condition.

So, in that condition, when calling _evaluate_response, the result should be result='' and not the actual result from the evaluation.

i.e.: the line that calls this method after if frame_tracker is None: should be:

_evaluate_response(py_db, request, result='', error_message='Thread id: %s is not current thread id.' % (thread_id,))

variables_response = pydevd_base_schema.build_response(request, kwargs={
'body':body, 'success':False, 'message': error_message})
py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True))
Expand Down Expand Up @@ -926,7 +926,10 @@ def internal_evaluate_expression_json(py_db, request, thread_id):
pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=True)
except Exception as ex:
err = ''.join(traceback.format_exception_only(type(ex), ex))
_evaluate_response(py_db, request, result='', error_message=err)
# Currently there is an issue in VSC where returning success=false for an
# eval request, in repl context, VSC does not show the error response in
# the debug console. So return the error message in result as well.
_evaluate_response(py_db, request, result=err, error_message=err)
return
# No result on exec.
_evaluate_response(py_db, request, result='')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,20 +765,29 @@ def on_setvariable_request(self, py_db, request):
arguments = request.arguments # : :type arguments: SetVariableArguments
variables_reference = arguments.variablesReference

if arguments.name.startswith('(return) '):
response = pydevd_base_schema.build_response(
request,
kwargs={
'body': SetVariableResponseBody(''),
'success': False,
'message': 'Cannot change return value'
})
return NetCommand(CMD_RETURN, 0, response, is_json=True)

thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference(
variables_reference)
if thread_id is not None:
self.api.request_change_variable_json(py_db, request, thread_id)
else:
body = SetVariableResponseBody('')
variables_response = pydevd_base_schema.build_response(
response = pydevd_base_schema.build_response(
request,
kwargs={
'body': body,
'body': SetVariableResponseBody(''),
'success': False,
'message': 'Unable to find thread to evaluate variable reference.'
})
return NetCommand(CMD_RETURN, 0, variables_response, is_json=True)
return NetCommand(CMD_RETURN, 0, response, is_json=True)

def on_modules_request(self, py_db, request):
modules_manager = py_db.cmd_factory.modules_manager # : :type modules_manager: ModulesManager
Expand Down
38 changes: 2 additions & 36 deletions src/ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,45 +1109,11 @@ def on_scopes(self, request, args):
def on_variables(self, request, args):
self._forward_request_to_pydevd(request, args)

@async_handler
def on_setVariable(self, request, args):
"""Handles DAP SetVariableRequest."""
var_name = args['name']

if var_name.startswith('(return) '):
self.send_error_response(
request,
'Cannot change return value')
return

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

body = resp_args['body']
self.send_response(request, **body)
self._forward_request_to_pydevd(request, args)

@async_handler
def on_evaluate(self, request, args):
"""Handles DAP EvaluateRequest."""

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

body = resp_args['body']

# Currently there is an issue in VSC where returning success=false for a eval request,
# in repl context. VSC does not show the error response in the debug console.
if args.get('context', None) == 'repl' and not resp_args['success']:
body['result'] = resp_args['message']
self.send_response(request, **body)
self._forward_request_to_pydevd(request, args)

def on_setExpression(self, request, args):
self._forward_request_to_pydevd(request, args)
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ def code_to_debug():
assert resp.body == expected

session.send_request('continue').wait_for_response(freeze=False)
session.wait_for_exit()
session.wait_for_exit()