Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,19 @@ def _unwind_event(code, instruction, exc):
# threads may still want it...
return

has_caught_exception_breakpoint_in_pydb = (
py_db.break_on_caught_exceptions or py_db.break_on_user_uncaught_exceptions or py_db.has_plugin_exception_breaks
)
break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions

if (
not has_caught_exception_breakpoint_in_pydb
and not break_on_uncaught_exceptions
and thread_info.additional_info.pydev_step_cmd == -1
):
# Without exception breakpoints this event is only tracked for stepping (see update_monitor_events).
return

func_code_info: FuncCodeInfo = _get_func_code_info(code, 1)
if func_code_info.always_skip_code:
return
Expand All @@ -941,10 +954,6 @@ def _unwind_event(code, instruction, exc):
frame = _getframe(1)
arg = (type(exc), exc, exc.__traceback__)

has_caught_exception_breakpoint_in_pydb = (
py_db.break_on_caught_exceptions or py_db.break_on_user_uncaught_exceptions or py_db.has_plugin_exception_breaks
)

if has_caught_exception_breakpoint_in_pydb:
_should_stop, frame, user_uncaught_exc_info = should_stop_on_exception(
py_db, thread_info.additional_info, frame, thread_info.thread, arg, None, is_unwind=True
Expand All @@ -962,9 +971,10 @@ def _unwind_event(code, instruction, exc):

if is_unhandled:
handle_exception(py_db, thread_info.thread, frame, user_uncaught_exc_info[0], EXCEPTION_TYPE_USER_UNHANDLED)
# The user may have requested a step while stopped at the exception.
_unwind_stepping(py_db, thread_info, frame)
return

break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions
if break_on_uncaught_exceptions:
if frame is _get_unhandled_exception_frame(exc, 1):
_thread_local_info.f_reported_unhandled_exc_tag = _thread_local_info.f_unhandled_exc_tag
Expand All @@ -973,6 +983,45 @@ def _unwind_event(code, instruction, exc):
stop_on_unhandled_exception(py_db, thread_info.thread, thread_info.additional_info, arg)
return

_unwind_stepping(py_db, thread_info, frame)


# fmt: off
# IFDEF CYTHON
# cdef _unwind_stepping(py_db, ThreadInfo thread_info, frame):
# cdef PyDBAdditionalThreadInfo info
# cdef int step_cmd
# ELSE
def _unwind_stepping(py_db, thread_info, frame):
# ENDIF
# fmt: on
"""
A frame left by an exception gets PY_UNWIND and never PY_RETURN, so a step that would be
finished or handed on in `_return_event` when the frame returns has to be handled here
(otherwise it would stay bound to a frame that no longer runs and never stop).
"""
info = thread_info.additional_info
step_cmd = info.pydev_step_cmd
if step_cmd == -1 or info.suspend_type != PYTHON_SUSPEND or info.pydev_state == STATE_SUSPEND:
return

stop_frame = info.pydev_step_stop
if step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE, CMD_SMART_STEP_INTO):
if _is_same_frame(info, stop_frame, frame):
# Same as in `_return_event`: stop in the caller.
_stop_on_return(py_db, thread_info, info, step_cmd, frame, None)

elif step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE):
if stop_frame is frame and not info.pydev_use_scoped_step_frame:
# Stop in the next line that runs (i.e.: the `except` or `finally` that handles the exception
# in a caller), the same as the `sys.settrace` tracer does.
if step_cmd == CMD_STEP_OVER:
info.pydev_step_cmd = CMD_STEP_INTO
else:
info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE
info.pydev_step_stop = None
_enable_code_tracing_for_frame_and_parents(thread_info, frame.f_back)


# fmt: off
# IFDEF CYTHON
Expand Down Expand Up @@ -1977,7 +2026,13 @@ def update_monitor_events(suspend_requested: Optional[bool]=None) -> None:
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
else:
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, None)
if suspend_requested:
# A thread is suspended or stepping: a step must not be lost when its frame is left
# by an exception (which sends PY_UNWIND and no PY_RETURN).
required_events |= monitor.events.PY_UNWIND
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
else:
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, None)

has_breaks = py_db.has_plugin_line_breaks
if not has_breaks:
Expand Down
Loading