Skip to content

Commit

Permalink
Fix issue with step into target with LOAD_METHOD. Fixes #661
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jul 16, 2021
1 parent 75e5058 commit b826f57
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ def on_BINARY_SUBSCR(self, instr):
on_BINARY_XOR = on_BINARY_SUBSCR

def on_LOAD_METHOD(self, instr):
# ceval sets the top and pushes an additional... the
# final result is simply one additional instruction.
self.on_POP_TOP(instr) # Remove the previous as we're loading something from it.
self._stack.append(instr)

def on_MAKE_FUNCTION(self, instr):
Expand Down Expand Up @@ -688,7 +687,11 @@ def _get_smart_step_into_targets(code):
pydev_log.exception('Exception computing step into targets (handled).')

ret.extend(stack.function_calls)
ret.extend(stack.load_attrs.values())
# No longer considering attr loads as calls (while in theory sometimes it's possible
# that something as `some.attr` can turn out to be a property which could be stepped
# in, it's not that common in practice and can be surprising for users, so, disabling
# step into from stepping into properties).
# ret.extend(stack.load_attrs.values())

return ret

Expand Down
20 changes: 13 additions & 7 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ def write_list_threads(self):
def wait_for_terminated(self):
return self.wait_for_json_message(TerminatedEvent)

def wait_for_thread_stopped(self, reason='breakpoint', line=None, file=None, name=None):
def wait_for_thread_stopped(self, reason='breakpoint', line=None, file=None, name=None, preserve_focus_hint=None):
'''
:param file:
utf-8 bytes encoded file or unicode
'''
stopped_event = self.wait_for_json_message(StoppedEvent)
assert stopped_event.body.reason == reason
if preserve_focus_hint is not None:
assert stopped_event.body.preserveFocusHint == preserve_focus_hint
json_hit = self.get_stack_as_json_hit(stopped_event.body.threadId)
if file is not None:
path = json_hit.stack_trace_response.body.stackFrames[0]['source']['path']
Expand Down Expand Up @@ -5572,7 +5574,8 @@ def do_something(): # break here
json_facade.write_set_function_breakpoints(['do_something'])
json_facade.write_make_initial_run()

hit = json_facade.wait_for_thread_stopped('function breakpoint', line=bp)
json_facade.wait_for_thread_stopped(
'function breakpoint', line=bp, preserve_focus_hint=False)
json_facade.write_continue()

writer.finished_ok = True
Expand All @@ -5588,7 +5591,8 @@ def test_function_breakpoints_async(case_setup):
json_facade.write_set_function_breakpoints(['gen'])
json_facade.write_make_initial_run()

hit = json_facade.wait_for_thread_stopped('function breakpoint', line=bp)
json_facade.wait_for_thread_stopped(
'function breakpoint', line=bp, preserve_focus_hint=False)
json_facade.write_continue()

writer.finished_ok = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def function():
found = collect_smart_step_into_variants(
frame, 0, 99999, base=function.__code__.co_firstlineno)

check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('yyy', 3), ('call', 5)])
check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('call', 5)])


def test_smart_step_into_bytecode_info_003():
Expand All @@ -140,7 +140,7 @@ def function():
found = collect_smart_step_into_variants(
frame, 0, 99999, base=function.__code__.co_firstlineno)

check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('yyy', 3), ('call', 5)])
check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('call', 5)])


def test_smart_step_into_bytecode_info_004():
Expand All @@ -158,7 +158,7 @@ def function():
found = collect_smart_step_into_variants(
frame, 0, 99999, base=function.__code__.co_firstlineno)

check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('yyy', 3), ('call', 5)])
check_name_and_line(found, [('_getframe', 1), ('bar', 2), ('Something', 3), ('call', 5)])


def test_smart_step_into_bytecode_info_005():
Expand All @@ -177,7 +177,7 @@ def function():
frame, 0, 99999, base=function.__code__.co_firstlineno)

check_name_and_line(found, [
('_getframe', 1), ('bar', 2), ('Something', 3), ('yyy', 3), ('call', 5)])
('_getframe', 1), ('bar', 2), ('Something', 3), ('call', 5)])


def test_smart_step_into_bytecode_info_006():
Expand Down Expand Up @@ -993,6 +993,32 @@ async def function():
''', [('lock', 1), ('foo', 2)])


def test_smart_step_into_bytecode_info_056():
check_names_from_func_str('''
def function(mask_path):
wc = some_func(
parsed_content,
np.array(
Image.open(mask_path)
)
)
''', [('some_func', 1), ('array', 3), ('open', 4)])


def test_smart_step_into_bytecode_info_057():
check_names_from_func_str('''
def function(mask_path):
wc = some_func(
parsed_content,
np.array(
my.pack.Image.open(mask_path)
)
)
''', [('some_func', 1), ('array', 3), ('open', 4)])


def test_get_smart_step_into_variant_from_frame_offset():
from _pydevd_bundle.pydevd_bytecode_utils import Variant

Expand Down

0 comments on commit b826f57

Please sign in to comment.