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 @@ -169,6 +169,21 @@ def _get_bootstrap_frame(depth: int) -> Tuple[Optional[FrameType], bool]:
return f_bootstrap, is_bootstrap_frame_internal


# fmt: off
# IFDEF CYTHON
# cdef _clear_unhandled_exception_frame():
# ELSE
def _clear_unhandled_exception_frame():
# ENDIF
# fmt: on
# Invalidate the cache to prevent bugs on id reuse
try:
del _thread_local_info.f_unhandled_frame
del _thread_local_info.f_unhandled_exc_id
except AttributeError:
pass


# fmt: off
# IFDEF CYTHON
# cdef _get_unhandled_exception_frame(exc, int depth):
Expand All @@ -178,11 +193,10 @@ def _get_unhandled_exception_frame(exc, depth: int) -> Optional[FrameType]:
# fmt: on
try:
# Unhandled frame has to be from the same exception.
if _thread_local_info.f_unhandled_exc is exc:
if _thread_local_info.f_unhandled_exc_id == id(exc):
return _thread_local_info.f_unhandled_frame
else:
del _thread_local_info.f_unhandled_frame
del _thread_local_info.f_unhandled_exc
_clear_unhandled_exception_frame()
raise AttributeError('Not the same exception')
except:
f_unhandled = _getframe(depth)
Expand Down Expand Up @@ -222,7 +236,7 @@ def _get_unhandled_exception_frame(exc, depth: int) -> Optional[FrameType]:

if f_unhandled is not None:
_thread_local_info.f_unhandled_frame = f_unhandled
_thread_local_info.f_unhandled_exc = exc
_thread_local_info.f_unhandled_exc_id = id(exc)
return _thread_local_info.f_unhandled_frame

return f_unhandled
Expand Down Expand Up @@ -984,6 +998,16 @@ def _raise_event(code, instruction, exc):
handle_exception(py_db, thread_info.thread, frame, arg, EXCEPTION_TYPE_HANDLED)


# fmt: off
# IFDEF CYTHON
# cdef _raise_event_uncaught(code, instruction, exc):
# ELSE
def _raise_event_uncaught(code, instruction, exc):
# ENDIF
# fmt: on
_clear_unhandled_exception_frame()


# fmt: off
# IFDEF CYTHON
# cdef str get_func_name(frame):
Expand Down Expand Up @@ -1869,13 +1893,13 @@ def update_monitor_events(suspend_requested: Optional[bool]=None) -> None:
# print('track RAISE')
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
elif break_on_uncaught_exceptions:
required_events |= monitor.events.RAISE | monitor.events.PY_UNWIND
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event_uncaught)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
else:
if break_on_uncaught_exceptions:
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.RAISE, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, None)
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, None)
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
Loading