@@ -2392,6 +2392,51 @@ def do_stop_on_unhandled_exception(self, thread, frame, frames_byid, arg):
23922392 remove_exception_from_frame (frame )
23932393 frame = None
23942394
2395+ def post_mortem (self , excinfo , as_uncaught = True ):
2396+ """
2397+ Triggers post-mortem debugging as if handling an uncaught exception.
2398+
2399+ If as_uncaught is True (default), respects exception breakpoint configuration and applies breakpoint filters.
2400+
2401+ :param excinfo: A tuple of (exc_type, exc_value, exc_traceback).
2402+ """
2403+ if not as_uncaught :
2404+ exctype , value , tb = excinfo
2405+
2406+ # Walk traceback to build frames list and find user frame
2407+ frames = []
2408+ user_frame = None
2409+ while tb is not None :
2410+ frame = tb .tb_frame
2411+ # Skip debugger-internal frames, use last user frame
2412+ if self .get_file_type (frame ) is None :
2413+ user_frame = frame
2414+ frames .append (frame )
2415+ tb = tb .tb_next
2416+
2417+ if user_frame is None :
2418+ pydev_log .debug ("post_mortem: no user frame found in traceback" )
2419+ return
2420+
2421+ frames_byid = dict ([(id (frame ), frame ) for frame in frames ])
2422+
2423+ if PYDEVD_USE_SYS_MONITORING :
2424+ saved_sys_monitoring_trace = pydevd_sys_monitoring .suspend_current_thread_tracing ()
2425+ thread = threading .current_thread ()
2426+ additional_info = self .set_additional_thread_info (thread )
2427+ additional_info .is_tracing += 1
2428+
2429+ try :
2430+ if as_uncaught :
2431+ self .stop_on_unhandled_exception (self , thread , additional_info , excinfo )
2432+ else :
2433+ self .do_stop_on_unhandled_exception (thread , user_frame , frames_byid , excinfo )
2434+ finally :
2435+ if PYDEVD_USE_SYS_MONITORING :
2436+ if saved_sys_monitoring_trace :
2437+ pydevd_sys_monitoring .resume_current_thread_tracing ()
2438+ additional_info .is_tracing -= 1
2439+
23952440 def set_trace_for_frame_and_parents (self , thread_ident : Optional [int ], frame , ** kwargs ):
23962441 disable = kwargs .pop ("disable" , False )
23972442 assert not kwargs
0 commit comments