Skip to content

Commit

Permalink
Minor updates, improve thread suspension.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jan 21, 2025
1 parent 37abaeb commit 1048810
Show file tree
Hide file tree
Showing 13 changed files with 7,132 additions and 7,729 deletions.
1 change: 1 addition & 0 deletions _pydevd_bundle/pydevd_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def _current_frames():
# Bug affecting Python 3.13.0 specifically makes some tests crash the interpreter!
# Hopefully it'll be fixed in 3.13.1.
IS_PY313_0 = sys.version_info[:3] == (3, 13, 0)
IS_PY313_1 = sys.version_info[:3] == (3, 13, 1)

# Mark tests that need to be fixed with this.
TODO_PY313_OR_GREATER = IS_PY313_OR_GREATER
Expand Down
6,053 changes: 3,027 additions & 3,026 deletions _pydevd_bundle/pydevd_cython.c

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion _pydevd_bundle/pydevd_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ except ImportError:
def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
return None


# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
# ELSE
# # Note: those are now inlined on cython.
# 105 = 105
# 107 = 107
# 144 = 144
# 109 = 109
Expand Down Expand Up @@ -445,6 +447,7 @@ cdef class _TryExceptContainerObj:
#
# try_except_infos = None
#
#
# ENDIF


Expand Down Expand Up @@ -1131,7 +1134,7 @@ cdef class PyDBFrame:
if should_skip:
stop = False

elif step_cmd in (107, 144, 206):
elif step_cmd in (107, 144, 206, 105):
force_check_project_scope = step_cmd == 144
if is_line:
if not info.pydev_use_scoped_step_frame:
Expand Down
6 changes: 5 additions & 1 deletion _pydevd_bundle/pydevd_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
return None


# IFDEF CYTHON
# cython_inline_constant: CMD_THREAD_SUSPEND = 105
# cython_inline_constant: CMD_STEP_INTO = 107
# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144
# cython_inline_constant: CMD_STEP_RETURN = 109
Expand All @@ -40,6 +42,7 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
# cython_inline_constant: STATE_SUSPEND = 2
# ELSE
# Note: those are now inlined on cython.
CMD_THREAD_SUSPEND = 105
CMD_STEP_INTO = 107
CMD_STEP_INTO_MY_CODE = 144
CMD_STEP_RETURN = 109
Expand Down Expand Up @@ -123,6 +126,7 @@ class _TryExceptContainerObj(object):

try_except_infos = None


# ENDIF


Expand Down Expand Up @@ -809,7 +813,7 @@ def trace_dispatch(self, frame, event, arg):
if should_skip:
stop = False

elif step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE):
elif step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_THREAD_SUSPEND):
force_check_project_scope = step_cmd == CMD_STEP_INTO_MY_CODE
if is_line:
if not info.pydev_use_scoped_step_frame:
Expand Down
9 changes: 6 additions & 3 deletions _pydevd_bundle/pydevd_thread_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pydevd_find_thread_by_id(thread_id):
return None


def mark_thread_suspended(thread, stop_reason: int, original_step_cmd: int = -1):
def mark_thread_suspended(thread, stop_reason: int, original_step_cmd: int=-1, main_suspend: bool=True):
info = set_additional_thread_info(thread)
info.suspend_type = PYTHON_SUSPEND
if original_step_cmd != -1:
Expand All @@ -34,7 +34,10 @@ def mark_thread_suspended(thread, stop_reason: int, original_step_cmd: int = -1)

# Note: don't set the 'pydev_original_step_cmd' here if unset.

if info.pydev_step_cmd == -1:
if not main_suspend:
info.pydev_step_cmd = CMD_THREAD_SUSPEND
info.pydev_step_stop = None
elif info.pydev_step_cmd == -1:
# If the step command is not specified, set it to step into
# to make sure it'll break as soon as possible.
info.pydev_step_cmd = CMD_STEP_INTO
Expand Down Expand Up @@ -91,7 +94,7 @@ def suspend_all_threads(py_db, except_thread):
else:
if t is except_thread:
continue
info = mark_thread_suspended(t, CMD_THREAD_SUSPEND)
info = mark_thread_suspended(t, CMD_THREAD_SUSPEND, main_suspend=False)
frame = info.get_topmost_frame(t)

# Reset the tracing as in this case as it could've set scopes to be untraced.
Expand Down
30 changes: 28 additions & 2 deletions _pydevd_sys_monitoring/_pydevd_sys_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
_get_ident = threading.get_ident
_thread_active = threading._active # noqa


# IFDEF CYTHON
# cython_inline_constant: CMD_THREAD_SUSPEND = 105
# cython_inline_constant: CMD_STEP_INTO = 107
# cython_inline_constant: CMD_STEP_OVER = 108
# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144
# cython_inline_constant: CMD_STEP_INTO_COROUTINE = 206
# cython_inline_constant: CMD_SMART_STEP_INTO = 128
# cython_inline_constant: can_skip: bool = True
# cython_inline_constant: CMD_STEP_RETURN = 109
# cython_inline_constant: CMD_STEP_OVER_MY_CODE = 159
# cython_inline_constant: CMD_STEP_RETURN_MY_CODE = 160
# cython_inline_constant: CMD_SET_BREAK = 111
# cython_inline_constant: CMD_SET_FUNCTION_BREAK = 208
# cython_inline_constant: STATE_RUN = 1
# cython_inline_constant: STATE_SUSPEND = 2
# ELSE
# Note: those are now inlined on cython.
CMD_THREAD_SUSPEND: int = 105
CMD_STEP_INTO: int = 107
CMD_STEP_OVER: int = 108
CMD_STEP_INTO_MY_CODE: int = 144
Expand All @@ -72,6 +91,8 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
CMD_SET_FUNCTION_BREAK: int = 208
STATE_RUN: int = 1
STATE_SUSPEND: int = 2
# ENDIF


IGNORE_EXCEPTION_TAG = re.compile("[^#]*#.*@IgnoreException")
DEBUG_START = ("pydevd.py", "run")
Expand Down Expand Up @@ -809,7 +830,7 @@ def _enable_code_tracing(py_db, additional_info, func_code_info: FuncCodeInfo, c
def _enable_step_tracing(py_db, code, step_cmd, info, frame):
# ENDIF
# fmt: on
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_SMART_STEP_INTO):
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_SMART_STEP_INTO, CMD_THREAD_SUSPEND):
# Stepping (must have line/return tracing enabled).
_enable_line_tracing(code)
_enable_return_tracing(code)
Expand Down Expand Up @@ -1088,7 +1109,7 @@ def _return_event(code, instruction, retval):

# Python line stepping
stop_frame = info.pydev_step_stop
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE):
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_THREAD_SUSPEND):
force_check_project_scope = step_cmd == CMD_STEP_INTO_MY_CODE
if frame.f_back is not None and not info.pydev_use_scoped_step_frame:
back_func_code_info = _get_func_code_info(frame.f_back.f_code, frame.f_back)
Expand Down Expand Up @@ -1581,6 +1602,11 @@ def _internal_line_event(func_code_info, frame, line):
_do_wait_suspend(py_db, thread_info, frame, "line", None)
return

elif step_cmd == CMD_THREAD_SUSPEND:
py_db.set_suspend(thread_info.thread, step_cmd, original_step_cmd=info.pydev_original_step_cmd)
_do_wait_suspend(py_db, thread_info, frame, "line", None)
return

elif step_cmd == CMD_SMART_STEP_INTO:
stop = False
back = frame.f_back
Expand Down
Loading

0 comments on commit 1048810

Please sign in to comment.