+ int trap_exit_value;
+ pid_t save_pgrp;
+ int save_pipe[2];
+
+ /* XXX - question: should the DEBUG trap inherit the RETURN trap? */
+ trap_exit_value = 0;
+ if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && ((sigmodes[DEBUG_TRAP] & SIG_IGNORED) == 0) && ((sigmodes[DEBUG_TRAP] & SIG_INPROGRESS) == 0))
+ {
+#if defined (JOB_CONTROL)
+ save_pgrp = pipeline_pgrp;
+ pipeline_pgrp = 0;
+ save_pipeline (1);
+# if defined (PGRP_PIPE)
+ save_pgrp_pipe (save_pipe, 1);
+# endif
+ stop_making_children ();
+#endif
+
+ trap_exit_value = _run_trap_internal (DEBUG_TRAP, "debug trap");
+
+#if defined (JOB_CONTROL)
+ pipeline_pgrp = save_pgrp;
+ restore_pipeline (1);
+# if defined (PGRP_PIPE)
+ close_pgrp_pipe ();
+ restore_pgrp_pipe (save_pipe);
+# endif
+ if (pipeline_pgrp > 0)
+ give_terminal_to (pipeline_pgrp, 1);
+ notify_and_cleanup ();
+#endif
+
+#if defined (DEBUGGER)
+ /* If we're in the debugger and the DEBUG trap returns 2 while we're in
+ a function or sourced script, we force a `return'. */
+ if (debugging_mode && trap_exit_value == 2 && return_catch_flag)
+ {
+ return_catch_value = trap_exit_value;
+ longjmp (return_catch, 1);
+ }
+#endif
+ }
+ return trap_exit_value;
+}
+
+void
+run_error_trap ()
+{
+ if ((sigmodes[ERROR_TRAP] & SIG_TRAPPED) && ((sigmodes[ERROR_TRAP] & SIG_IGNORED) == 0) && (sigmodes[ERROR_TRAP] & SIG_INPROGRESS) == 0)
+ _run_trap_internal (ERROR_TRAP, "error trap");
+}
+
+void
+run_return_trap ()
+{
+ int old_exit_value;
+
+#if 0
+ if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && (sigmodes[DEBUG_TRAP] & SIG_INPROGRESS))
+ return;
+#endif
+
+ if ((sigmodes[RETURN_TRAP] & SIG_TRAPPED) && ((sigmodes[RETURN_TRAP] & SIG_IGNORED) == 0) && (sigmodes[RETURN_TRAP] & SIG_INPROGRESS) == 0)
+ {
+ old_exit_value = last_command_exit_value;
+ _run_trap_internal (RETURN_TRAP, "return trap");
+ last_command_exit_value = old_exit_value;
+ }