Skip to content

Commit

Permalink
Provide full string when evaluating clipboard. Fixes microsoft#110
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 12, 2020
1 parent a7282e9 commit fa5224e
Show file tree
Hide file tree
Showing 8 changed files with 2,471 additions and 635 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def update_class_to_generate_register_dec(classes_to_generate, class_to_generate
command = classes_to_generate[request_name]['properties'].get('command')
else:
if response_name == 'ErrorResponse':
command = {'enum' : ['error']}
command = {'enum': ['error']}
else:
raise AssertionError('Unhandled: %s' % (response_name,))

Expand Down Expand Up @@ -398,7 +398,8 @@ def update_class_to_generate_init(class_to_generate):
ref = prop['type']
ref_data = ref.ref_data
if ref_data.get('is_enum', False):
init_body.append(' assert %s in %s.VALID_VALUES' % (prop_name, str(ref)))
init_body.append(' if %s is not None:' % (prop_name,))
init_body.append(' assert %s in %s.VALID_VALUES' % (prop_name, str(ref)))
init_body.append(' self.%(prop_name)s = %(prop_name)s' % dict(
prop_name=prop_name))
else:
Expand Down

Large diffs are not rendered by default.

2,486 changes: 1,954 additions & 532 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,17 @@ def __create_frame():
return

variable = frame_tracker.obtain_as_variable(expression, eval_result, frame=frame)
var_data = variable.get_var_data(fmt=fmt)

safe_repr_custom_attrs = {}
if context == 'clipboard':
safe_repr_custom_attrs = dict(
maxstring_outer=2 ** 64,
maxstring_inner=2 ** 64,
maxother_outer=2 ** 64,
maxother_inner=2 ** 64,
)

var_data = variable.get_var_data(fmt=fmt, **safe_repr_custom_attrs)

body = pydevd_schema.EvaluateResponseBody(
result=var_data['value'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def on_initialize_request(self, py_db, request):
supportsLogPoints=True,
supportsSetExpression=True,
supportsTerminateRequest=True,
supportsClipboardContext=True,

exceptionBreakpointFilters=[
{'filter': 'raised', 'label': 'Raised Exceptions', 'default': False},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_value(self):
def get_variable_reference(self):
return id(self.value)

def get_var_data(self, fmt=None):
def get_var_data(self, fmt=None, **safe_repr_custom_attrs):
'''
:param dict fmt:
Format expected by the DAP (keys: 'hex': bool, 'rawString': bool)
Expand All @@ -44,6 +44,8 @@ def get_var_data(self, fmt=None):
if fmt is not None:
safe_repr.convert_to_hex = fmt.get('hex', False)
safe_repr.raw_value = fmt.get('rawString', False)
for key, val in safe_repr_custom_attrs.items():
setattr(safe_repr, key, val)

type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details(
self.value, to_string=safe_repr)
Expand Down
60 changes: 60 additions & 0 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,66 @@ def test_evaluate_block_repl(case_setup):
writer.finished_ok = True


def test_evaluate_block_clipboard(case_setup, pyfile):

@pyfile
def target():
MAX_LIMIT = 65538

class SomeObj(object):

def __str__(self):
return var1

__repr__ = __str__

var1 = 'a' * 80000
var2 = 20000
var3 = SomeObj()

print('TEST SUCEEDED') # Break here

def verify(evaluate_response):
# : :type evaluate_response: EvaluateResponse
assert len(evaluate_response.body.result) >= 80000
assert '...' not in evaluate_response.body.result
assert set(evaluate_response.body.result).issubset(set(['a', "'"]))

with case_setup.test_file(target) as writer:
json_facade = JsonFacade(writer)
json_facade.write_launch(justMyCode=False)
json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here'))
json_facade.write_make_initial_run()

json_hit = json_facade.wait_for_thread_stopped()
json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id)

evaluate_response = json_facade.evaluate(
'var1',
frameId=json_hit.frame_id,
context='clipboard',
)
verify(evaluate_response)

evaluate_response = json_facade.evaluate(
'var2',
frameId=json_hit.frame_id,
context='clipboard',
fmt={'hex': True}
)
assert evaluate_response.body.result == "0x4e20"

evaluate_response = json_facade.evaluate(
'var3',
frameId=json_hit.frame_id,
context='clipboard',
)
verify(evaluate_response)

json_facade.write_continue()
writer.finished_ok = True


@pytest.mark.skipif(IS_PY26, reason='__dir__ not customizable on Python 2.6')
def test_exception_on_dir(case_setup):
with case_setup.test_file('_debugger_case_dir_exception.py') as writer:
Expand Down
1 change: 1 addition & 0 deletions src/debugpy/adapter/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def initialize_request(self, request):
"supportsValueFormattingOptions": True,
"supportsTerminateDebuggee": True,
"supportsGotoTargetsRequest": True,
"supportsClipboardContext": True,
"exceptionBreakpointFilters": exception_breakpoint_filters,
}

Expand Down

0 comments on commit fa5224e

Please sign in to comment.