Blame SOURCES/gdb-6.8-quit-never-aborts.patch

2f9ed3
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2f9ed3
From: Fedora GDB patches <invalid@email.com>
2f9ed3
Date: Fri, 27 Oct 2017 21:07:50 +0200
2f9ed3
Subject: gdb-6.8-quit-never-aborts.patch
2f9ed3
2f9ed3
;; Make the GDB quit processing non-abortable to cleanup everything properly.
2f9ed3
;;=fedora: It was useful only after gdb-6.8-attach-signalled-detach-stopped.patch .
2f9ed3
2f9ed3
We may abort the process of detaching threads with multiple SIGINTs - which are
2f9ed3
being sent during a testcase terminating its child GDB.
2f9ed3
2f9ed3
Some of the threads may not be properly PTRACE_DETACHed which hurts if they
2f9ed3
should have been detached with SIGSTOP (as they are accidentally left running
2f9ed3
on the debugger termination).
2f9ed3
2f9ed3
diff --git a/gdb/defs.h b/gdb/defs.h
2f9ed3
--- a/gdb/defs.h
2f9ed3
+++ b/gdb/defs.h
2f9ed3
@@ -168,6 +168,10 @@ extern void default_quit_handler (void);
2f9ed3
 /* Flag that function quit should call quit_force.  */
2f9ed3
 extern volatile int sync_quit_force_run;
2f9ed3
 
2f9ed3
+#ifdef NEED_DETACH_SIGSTOP
2f9ed3
+extern int quit_flag_cleanup;
2f9ed3
+#endif
2f9ed3
+
2f9ed3
 extern void quit (void);
2f9ed3
 
2f9ed3
 /* Helper for the QUIT macro.  */
2f9ed3
diff --git a/gdb/extension.c b/gdb/extension.c
2f9ed3
--- a/gdb/extension.c
2f9ed3
+++ b/gdb/extension.c
2f9ed3
@@ -820,6 +820,11 @@ check_quit_flag (void)
2f9ed3
   int i, result = 0;
2f9ed3
   const struct extension_language_defn *extlang;
2f9ed3
 
2f9ed3
+#ifdef NEED_DETACH_SIGSTOP
2f9ed3
+  if (quit_flag_cleanup)
2f9ed3
+    return 0;
2f9ed3
+#endif
2f9ed3
+
2f9ed3
   ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang)
2f9ed3
     {
2f9ed3
       if (extlang->ops->check_quit_flag != NULL)
2f9ed3
diff --git a/gdb/top.c b/gdb/top.c
2f9ed3
--- a/gdb/top.c
2f9ed3
+++ b/gdb/top.c
2f9ed3
@@ -1626,7 +1626,13 @@ quit_force (int *exit_arg, int from_tty)
2f9ed3
 
2f9ed3
   qt.from_tty = from_tty;
2f9ed3
 
2f9ed3
+#ifndef NEED_DETACH_SIGSTOP
2f9ed3
   /* We want to handle any quit errors and exit regardless.  */
2f9ed3
+#else
2f9ed3
+  /* We want to handle any quit errors and exit regardless but we should never
2f9ed3
+     get user-interrupted to properly detach the inferior.  */
2f9ed3
+  quit_flag_cleanup = 1;
2f9ed3
+#endif
2f9ed3
 
2f9ed3
   /* Get out of tfind mode, and kill or detach all inferiors.  */
2f9ed3
   TRY
2f9ed3
diff --git a/gdb/utils.c b/gdb/utils.c
2f9ed3
--- a/gdb/utils.c
2f9ed3
+++ b/gdb/utils.c
2f9ed3
@@ -100,6 +100,13 @@ static std::chrono::steady_clock::duration prompt_for_continue_wait_time;
2f9ed3
 
2f9ed3
 static int debug_timestamp = 0;
2f9ed3
 
2f9ed3
+#ifdef NEED_DETACH_SIGSTOP
2f9ed3
+/* Nonzero means we are already processing the quitting cleanups and we should
2f9ed3
+   no longer get aborted.  */
2f9ed3
+
2f9ed3
+int quit_flag_cleanup;
2f9ed3
+#endif
2f9ed3
+
2f9ed3
 /* Nonzero means that strings with character values >0x7F should be printed
2f9ed3
    as octal escapes.  Zero means just print the value (e.g. it's an
2f9ed3
    international character, and the terminal or window can cope.)  */