Skip to content

Commit 29500d6

Browse files
committed
Minor updates, improve thread suspension.
1 parent 37abaeb commit 29500d6

13 files changed

+7138
-7735
lines changed

_pydevd_bundle/pydevd_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def _current_frames():
180180
# Bug affecting Python 3.13.0 specifically makes some tests crash the interpreter!
181181
# Hopefully it'll be fixed in 3.13.1.
182182
IS_PY313_0 = sys.version_info[:3] == (3, 13, 0)
183+
IS_PY313_1 = sys.version_info[:3] == (3, 13, 1)
183184

184185
# Mark tests that need to be fixed with this.
185186
TODO_PY313_OR_GREATER = IS_PY313_OR_GREATER

_pydevd_bundle/pydevd_cython.c

Lines changed: 3027 additions & 3026 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_pydevd_bundle/pydevd_cython.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,11 @@ except ImportError:
359359
def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
360360
return None
361361

362+
362363
# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
363364
# ELSE
364365
# # Note: those are now inlined on cython.
366+
# 105 = 105
365367
# 107 = 107
366368
# 144 = 144
367369
# 109 = 109
@@ -445,6 +447,7 @@ cdef class _TryExceptContainerObj:
445447
#
446448
# try_except_infos = None
447449
#
450+
#
448451
# ENDIF
449452

450453

@@ -1131,7 +1134,7 @@ cdef class PyDBFrame:
11311134
if should_skip:
11321135
stop = False
11331136

1134-
elif step_cmd in (107, 144, 206):
1137+
elif step_cmd in (107, 144, 206, 105):
11351138
force_check_project_scope = step_cmd == 144
11361139
if is_line:
11371140
if not info.pydev_use_scoped_step_frame:

_pydevd_bundle/pydevd_frame.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
2626
return None
2727

28+
2829
# IFDEF CYTHON
30+
# cython_inline_constant: CMD_THREAD_SUSPEND = 105
2931
# cython_inline_constant: CMD_STEP_INTO = 107
3032
# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144
3133
# cython_inline_constant: CMD_STEP_RETURN = 109
@@ -40,6 +42,7 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
4042
# cython_inline_constant: STATE_SUSPEND = 2
4143
# ELSE
4244
# Note: those are now inlined on cython.
45+
CMD_THREAD_SUSPEND = 105
4346
CMD_STEP_INTO = 107
4447
CMD_STEP_INTO_MY_CODE = 144
4548
CMD_STEP_RETURN = 109
@@ -123,6 +126,7 @@ class _TryExceptContainerObj(object):
123126

124127
try_except_infos = None
125128

129+
126130
# ENDIF
127131

128132

@@ -809,7 +813,7 @@ def trace_dispatch(self, frame, event, arg):
809813
if should_skip:
810814
stop = False
811815

812-
elif step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE):
816+
elif step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_THREAD_SUSPEND):
813817
force_check_project_scope = step_cmd == CMD_STEP_INTO_MY_CODE
814818
if is_line:
815819
if not info.pydev_use_scoped_step_frame:

_pydevd_bundle/pydevd_thread_lifecycle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def pydevd_find_thread_by_id(thread_id):
2525
return None
2626

2727

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

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

37-
if info.pydev_step_cmd == -1:
37+
if not main_suspend:
38+
info.pydev_step_cmd = CMD_THREAD_SUSPEND
39+
info.pydev_step_stop = None
40+
elif info.pydev_step_cmd == -1:
3841
# If the step command is not specified, set it to step into
3942
# to make sure it'll break as soon as possible.
4043
info.pydev_step_cmd = CMD_STEP_INTO
@@ -91,7 +94,7 @@ def suspend_all_threads(py_db, except_thread):
9194
else:
9295
if t is except_thread:
9396
continue
94-
info = mark_thread_suspended(t, CMD_THREAD_SUSPEND)
97+
info = mark_thread_suspended(t, CMD_THREAD_SUSPEND, main_suspend=False)
9598
frame = info.get_topmost_frame(t)
9699

97100
# Reset the tracing as in this case as it could've set scopes to be untraced.

_pydevd_sys_monitoring/_pydevd_sys_monitoring.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
5959
_get_ident = threading.get_ident
6060
_thread_active = threading._active # noqa
6161

62+
63+
# IFDEF CYTHON
64+
# cython_inline_constant: CMD_THREAD_SUSPEND = 105
65+
# cython_inline_constant: CMD_STEP_INTO = 107
66+
# cython_inline_constant: CMD_STEP_OVER = 108
67+
# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144
68+
# cython_inline_constant: CMD_STEP_INTO_COROUTINE = 206
69+
# cython_inline_constant: CMD_SMART_STEP_INTO = 128
70+
# cython_inline_constant: can_skip: bool = True
71+
# cython_inline_constant: CMD_STEP_RETURN = 109
72+
# cython_inline_constant: CMD_STEP_OVER_MY_CODE = 159
73+
# cython_inline_constant: CMD_STEP_RETURN_MY_CODE = 160
74+
# cython_inline_constant: CMD_SET_BREAK = 111
75+
# cython_inline_constant: CMD_SET_FUNCTION_BREAK = 208
76+
# cython_inline_constant: STATE_RUN = 1
77+
# cython_inline_constant: STATE_SUSPEND = 2
78+
# ELSE
79+
# Note: those are now inlined on cython.
80+
CMD_THREAD_SUSPEND: int = 105
6281
CMD_STEP_INTO: int = 107
6382
CMD_STEP_OVER: int = 108
6483
CMD_STEP_INTO_MY_CODE: int = 144
@@ -72,6 +91,8 @@ def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
7291
CMD_SET_FUNCTION_BREAK: int = 208
7392
STATE_RUN: int = 1
7493
STATE_SUSPEND: int = 2
94+
# ENDIF
95+
7596

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

10891110
# Python line stepping
10901111
stop_frame = info.pydev_step_stop
1091-
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE):
1112+
if step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_INTO_COROUTINE, CMD_THREAD_SUSPEND):
10921113
force_check_project_scope = step_cmd == CMD_STEP_INTO_MY_CODE
10931114
if frame.f_back is not None and not info.pydev_use_scoped_step_frame:
10941115
back_func_code_info = _get_func_code_info(frame.f_back.f_code, frame.f_back)
@@ -1581,6 +1602,11 @@ def _internal_line_event(func_code_info, frame, line):
15811602
_do_wait_suspend(py_db, thread_info, frame, "line", None)
15821603
return
15831604

1605+
elif step_cmd == CMD_THREAD_SUSPEND:
1606+
py_db.set_suspend(thread_info.thread, step_cmd, original_step_cmd=info.pydev_original_step_cmd)
1607+
_do_wait_suspend(py_db, thread_info, frame, "line", None)
1608+
return
1609+
15841610
elif step_cmd == CMD_SMART_STEP_INTO:
15851611
stop = False
15861612
back = frame.f_back

0 commit comments

Comments
 (0)