Skip to content

Commit b4a60df

Browse files
committed
apply review
1 parent 826df54 commit b4a60df

2 files changed

Lines changed: 88 additions & 38 deletions

File tree

src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -980,29 +980,54 @@ def _raise_event(code, instruction, exc):
980980
if func_code_info.always_skip_code:
981981
return
982982

983-
_clear_unhandled_exception_frame()
983+
frame = _getframe(1)
984+
arg = (type(exc), exc, exc.__traceback__)
984985

985-
has_caught_exception_breakpoint_in_pydb = (
986-
py_db.break_on_caught_exceptions or py_db.break_on_user_uncaught_exceptions or py_db.has_plugin_exception_breaks
986+
# Compute the previous exception info (if any). We use it to check if the exception
987+
# should be stopped
988+
prev_exc_info = _thread_local_info._user_uncaught_exc_info if hasattr(_thread_local_info, "_user_uncaught_exc_info") else None
989+
should_stop, frame, _user_uncaught_exc_info = should_stop_on_exception(
990+
py_db, thread_info.additional_info, frame, thread_info.thread, arg, prev_exc_info
987991
)
988992

989-
if has_caught_exception_breakpoint_in_pydb:
990-
frame = _getframe(1)
991-
arg = (type(exc), exc, exc.__traceback__)
992-
993-
# Compute the previous exception info (if any). We use it to check if the exception
994-
# should be stopped
995-
prev_exc_info = _thread_local_info._user_uncaught_exc_info if hasattr(_thread_local_info, "_user_uncaught_exc_info") else None
996-
should_stop, frame, _user_uncaught_exc_info = should_stop_on_exception(
997-
py_db, thread_info.additional_info, frame, thread_info.thread, arg, prev_exc_info
998-
)
993+
# Save the current exception info for the next raise event.
994+
_thread_local_info._user_uncaught_exc_info = _user_uncaught_exc_info
999995

1000-
# Save the current exception info for the next raise event.
1001-
_thread_local_info._user_uncaught_exc_info = _user_uncaught_exc_info
996+
# print('!!!! should_stop (in raise)', should_stop)
997+
if should_stop:
998+
handle_exception(py_db, thread_info.thread, frame, arg, EXCEPTION_TYPE_HANDLED)
1002999

1003-
# print('!!!! should_stop (in raise)', should_stop)
1004-
if should_stop:
1005-
handle_exception(py_db, thread_info.thread, frame, arg, EXCEPTION_TYPE_HANDLED)
1000+
1001+
# fmt: off
1002+
# IFDEF CYTHON
1003+
# cdef _raise_event_uncaught(code, instruction, exc):
1004+
# cdef ThreadInfo thread_info
1005+
# cdef FuncCodeInfo func_code_info
1006+
# ELSE
1007+
def _raise_event_uncaught(code, instruction, exc):
1008+
# ENDIF
1009+
# fmt: on
1010+
try:
1011+
thread_info = _thread_local_info.thread_info
1012+
except:
1013+
thread_info = _get_thread_info(True, 1)
1014+
if thread_info is None:
1015+
return
1016+
1017+
py_db: object = GlobalDebuggerHolder.global_dbg
1018+
if py_db is None or py_db.pydb_disposed:
1019+
return
1020+
1021+
if not thread_info.trace or not thread_info.is_thread_alive():
1022+
# For thread-related stuff we can't disable the code tracing because other
1023+
# threads may still want it...
1024+
return
1025+
1026+
func_code_info: FuncCodeInfo = _get_func_code_info(code, 1)
1027+
if func_code_info.always_skip_code:
1028+
return
1029+
1030+
_clear_unhandled_exception_frame()
10061031

10071032

10081033
# fmt: off
@@ -1892,7 +1917,7 @@ def update_monitor_events(suspend_requested: Optional[bool]=None) -> None:
18921917
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
18931918
elif break_on_uncaught_exceptions:
18941919
required_events |= monitor.events.RAISE | monitor.events.PY_UNWIND
1895-
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event)
1920+
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event_uncaught)
18961921
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
18971922
else:
18981923
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, None)

src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.pyx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -986,29 +986,54 @@ cdef _raise_event(code, instruction, exc):
986986
if func_code_info.always_skip_code:
987987
return
988988

989-
_clear_unhandled_exception_frame()
989+
frame = _getframe(1)
990+
arg = (type(exc), exc, exc.__traceback__)
990991

991-
has_caught_exception_breakpoint_in_pydb = (
992-
py_db.break_on_caught_exceptions or py_db.break_on_user_uncaught_exceptions or py_db.has_plugin_exception_breaks
992+
# Compute the previous exception info (if any). We use it to check if the exception
993+
# should be stopped
994+
prev_exc_info = _thread_local_info._user_uncaught_exc_info if hasattr(_thread_local_info, "_user_uncaught_exc_info") else None
995+
should_stop, frame, _user_uncaught_exc_info = should_stop_on_exception(
996+
py_db, thread_info.additional_info, frame, thread_info.thread, arg, prev_exc_info
993997
)
994998

995-
if has_caught_exception_breakpoint_in_pydb:
996-
frame = _getframe(1)
997-
arg = (type(exc), exc, exc.__traceback__)
998-
999-
# Compute the previous exception info (if any). We use it to check if the exception
1000-
# should be stopped
1001-
prev_exc_info = _thread_local_info._user_uncaught_exc_info if hasattr(_thread_local_info, "_user_uncaught_exc_info") else None
1002-
should_stop, frame, _user_uncaught_exc_info = should_stop_on_exception(
1003-
py_db, thread_info.additional_info, frame, thread_info.thread, arg, prev_exc_info
1004-
)
999+
# Save the current exception info for the next raise event.
1000+
_thread_local_info._user_uncaught_exc_info = _user_uncaught_exc_info
10051001

1006-
# Save the current exception info for the next raise event.
1007-
_thread_local_info._user_uncaught_exc_info = _user_uncaught_exc_info
1002+
# print('!!!! should_stop (in raise)', should_stop)
1003+
if should_stop:
1004+
handle_exception(py_db, thread_info.thread, frame, arg, EXCEPTION_TYPE_HANDLED)
10081005

1009-
# print('!!!! should_stop (in raise)', should_stop)
1010-
if should_stop:
1011-
handle_exception(py_db, thread_info.thread, frame, arg, EXCEPTION_TYPE_HANDLED)
1006+
1007+
# fmt: off
1008+
# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
1009+
cdef _raise_event_uncaught(code, instruction, exc):
1010+
cdef ThreadInfo thread_info
1011+
cdef FuncCodeInfo func_code_info
1012+
# ELSE
1013+
# def _raise_event_uncaught(code, instruction, exc):
1014+
# ENDIF
1015+
# fmt: on
1016+
try:
1017+
thread_info = _thread_local_info.thread_info
1018+
except:
1019+
thread_info = _get_thread_info(True, 1)
1020+
if thread_info is None:
1021+
return
1022+
1023+
py_db: object = GlobalDebuggerHolder.global_dbg
1024+
if py_db is None or py_db.pydb_disposed:
1025+
return
1026+
1027+
if not thread_info.trace or not thread_info.is_thread_alive():
1028+
# For thread-related stuff we can't disable the code tracing because other
1029+
# threads may still want it...
1030+
return
1031+
1032+
func_code_info: FuncCodeInfo = _get_func_code_info(code, 1)
1033+
if func_code_info.always_skip_code:
1034+
return
1035+
1036+
_clear_unhandled_exception_frame()
10121037

10131038

10141039
# fmt: off
@@ -1898,7 +1923,7 @@ def update_monitor_events(suspend_requested: Optional[bool]=None) -> None:
18981923
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
18991924
elif break_on_uncaught_exceptions:
19001925
required_events |= monitor.events.RAISE | monitor.events.PY_UNWIND
1901-
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event)
1926+
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, _raise_event_uncaught)
19021927
monitor.register_callback(DEBUGGER_ID, monitor.events.PY_UNWIND, _unwind_event)
19031928
else:
19041929
monitor.register_callback(DEBUGGER_ID, monitor.events.RAISE, None)

0 commit comments

Comments
 (0)