22# Signal handling routines
33#
44# Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2010,
5- # 2011 Rocky Bernstein <[email protected] >5+ # 2011, 2023 Rocky Bernstein <[email protected] >66#
77# This program is free software; you can redistribute it and/or
88# modify it under the terms of the GNU General Public License as
@@ -32,6 +32,11 @@ typeset -i _Dbg_QUIT_ON_QUIT=0
3232# Return code that debugged program reports
3333typeset -i _Dbg_program_exit_code=0
3434
35+ # 1 if we we running post-mortem in exit handler?
36+ typeset -i _Dbg_in_exit_handler=0
37+ # Allow Quit and things like that to signal a final quit.
38+ typeset -i _Dbg_exit_from_exit_handler=0
39+
3540# ###########################################################
3641# # Signal arrays: These are indexed by the signal number. ##
3742# ###########################################################
@@ -109,39 +114,15 @@ _Dbg_subst_handler_var() {
109114# command loop
110115_Dbg_exit_handler () {
111116
112- # Consider putting the following line(s) in a routine.
113- # Ditto for the restore environment
114117 typeset -i _Dbg_debugged_exit_code=$?
115118
116119 # Turn off line and variable trace listing; allow unset parameter expansion.
117120 set +x +v +u
118121
119- if [[ ${_Dbg_sig_print[0]} == " print" ]] ; then
120- # Note: use the same message that gdb does for this.
121- _Dbg_msg " Program received signal EXIT (0)..."
122- if [[ ${_Dbg_sig_show_stack[0]} == " showstack" ]] ; then
123- _Dbg_do_backtrace 0
124- fi
125- fi
126-
127122 if [[ $_Dbg_old_EXIT_handler != ' ' ]] ; then
128123 eval $_Dbg_old_EXIT_handler
129124 fi
130125
131- # If we've set the QUIT signal handler not to stop, or we've in the
132- # middle of leaving so many (subshell) levels or we have set to
133- # leave quietly on termination, then do it!
134-
135- if [[ ${_Dbg_sig_stop[0]} != " stop" ]] \
136- || (( _Dbg_QUIT_LEVELS != 0 )) \
137- || (( _Dbg_QUIT_ON_QUIT )) ; then
138- _Dbg_do_quit
139- # We don't return from here.
140- fi
141-
142- # We've tested for all the quitting conditions above.
143- # Even though this is an exit handler, don't exit!
144-
145126 typeset term_msg=" normally"
146127 if [[ $_Dbg_debugged_exit_code != 0 ]] ; then
147128 term_msg=" with code $_Dbg_debugged_exit_code "
@@ -154,10 +135,16 @@ _Dbg_exit_handler() {
154135 " Debugged program terminated $term_msg . Use q to quit or R to restart."
155136
156137 _Dbg_running=0
138+ _Dbg_exit_from_exit_handler=0
139+ _Dbg_in_exit_handler=1
157140 while : ; do
158- _Dbg_process_commands
141+ _Dbg_process_commands
142+ if (( $_Dbg_exit_from_exit_handler != 0 )) ; then
143+ break
144+ fi
159145 done
160146 fi
147+ return $(( 128 + $_Dbg_debugged_exit_code ))
161148}
162149
163150# Generic signal handler. We consult global array _Dbg_sig_* for how
@@ -280,3 +267,7 @@ _Dbg_init_default_traps() {
280267 _Dbg_init_trap TERM " print" " showstack" " stop"
281268 # _Dbg_init_trap TRAP "print" "showstack" "stop"
282269}
270+
271+
272+ set -o localtraps
273+ trap ' _Dbg_exit_handler' EXIT
0 commit comments