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