Blame SOURCES/gdb-rhbz1852580-terminal-woes.patch

be07d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
be07d7
From: Alan Hayward <alan.hayward@arm.com>
be07d7
Date: Tue, 28 May 2019 10:07:54 +0100
be07d7
Subject: gdb-rhbz1852580-terminal-woes.patch
be07d7
be07d7
;; Fix terminal problems when error() is called
be07d7
;; Alan Hayward (RH BZ 1852580)
be07d7
be07d7
Suppress SIGTTOU when handling errors
be07d7
be07d7
Calls to error () can cause SIGTTOU to send gdb to the background.
be07d7
be07d7
For example, on an Arm build:
be07d7
  (gdb) b main
be07d7
  Breakpoint 1 at 0x10774: file /build/gdb/testsuite/../../../src/binutils-gdb/gdb/testsuite/gdb.base/watchpoint.c, line 174.
be07d7
  (gdb) r
be07d7
  Starting program: /build/gdb/testsuite/outputs/gdb.base/watchpoint/watchpoint
be07d7
be07d7
  [1]+  Stopped                 ../gdb ./outputs/gdb.base/watchpoint/watchpoint
be07d7
  localhost$ fg
be07d7
  ../gdb ./outputs/gdb.base/watchpoint/watchpoint
be07d7
  Cannot parse expression `.L1199 4@r4'.
be07d7
  warning: Probes-based dynamic linker interface failed.
be07d7
  Reverting to original interface.
be07d7
be07d7
The SIGTTOU is raised whilst inside a syscall during the call to tcdrain.
be07d7
Fix is to use scoped_ignore_sigttou to ensure SIGTTOU is blocked.
be07d7
be07d7
In addition fix include comments - job_control is not included via terminal.h
be07d7
be07d7
gdb/ChangeLog:
be07d7
be07d7
	* event-top.c: Remove include comment.
be07d7
	* inflow.c (class scoped_ignore_sigttou): Move from here...
be07d7
	* inflow.h (class scoped_ignore_sigttou): ...to here.
be07d7
	* ser-unix.c (hardwire_drain_output): Block SIGTTOU during drain.
be07d7
	* top.c:  Remove include comment.
be07d7
be07d7
diff --git a/gdb/event-top.c b/gdb/event-top.c
be07d7
--- a/gdb/event-top.c
be07d7
+++ b/gdb/event-top.c
be07d7
@@ -24,7 +24,7 @@
be07d7
 #include "inferior.h"
be07d7
 #include "infrun.h"
be07d7
 #include "target.h"
be07d7
-#include "terminal.h"		/* for job_control */
be07d7
+#include "terminal.h"
be07d7
 #include "event-loop.h"
be07d7
 #include "event-top.h"
be07d7
 #include "interps.h"
be07d7
diff --git a/gdb/inflow.c b/gdb/inflow.c
be07d7
--- a/gdb/inflow.c
be07d7
+++ b/gdb/inflow.c
be07d7
@@ -103,35 +103,6 @@ static serial_ttystate initial_gdb_ttystate;
be07d7
 
be07d7
 static struct terminal_info *get_inflow_inferior_data (struct inferior *);
be07d7
 
be07d7
-/* RAII class used to ignore SIGTTOU in a scope.  */
be07d7
-
be07d7
-class scoped_ignore_sigttou
be07d7
-{
be07d7
-public:
be07d7
-  scoped_ignore_sigttou ()
be07d7
-  {
be07d7
-#ifdef SIGTTOU
be07d7
-    if (job_control)
be07d7
-      m_osigttou = signal (SIGTTOU, SIG_IGN);
be07d7
-#endif
be07d7
-  }
be07d7
-
be07d7
-  ~scoped_ignore_sigttou ()
be07d7
-  {
be07d7
-#ifdef SIGTTOU
be07d7
-    if (job_control)
be07d7
-      signal (SIGTTOU, m_osigttou);
be07d7
-#endif
be07d7
-  }
be07d7
-
be07d7
-  DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou);
be07d7
-
be07d7
-private:
be07d7
-#ifdef SIGTTOU
be07d7
-  sighandler_t m_osigttou = NULL;
be07d7
-#endif
be07d7
-};
be07d7
-
be07d7
 /* While the inferior is running, we want SIGINT and SIGQUIT to go to the
be07d7
    inferior only.  If we have job control, that takes care of it.  If not,
be07d7
    we save our handlers in these two variables and set SIGINT and SIGQUIT
be07d7
diff --git a/gdb/inflow.h b/gdb/inflow.h
be07d7
--- a/gdb/inflow.h
be07d7
+++ b/gdb/inflow.h
be07d7
@@ -21,5 +21,36 @@
be07d7
 #define INFLOW_H
be07d7
 
be07d7
 #include <unistd.h>
be07d7
+#include <signal.h>
be07d7
+#include "common/job-control.h"
be07d7
+
be07d7
+/* RAII class used to ignore SIGTTOU in a scope.  */
be07d7
+
be07d7
+class scoped_ignore_sigttou
be07d7
+{
be07d7
+public:
be07d7
+  scoped_ignore_sigttou ()
be07d7
+  {
be07d7
+#ifdef SIGTTOU
be07d7
+    if (job_control)
be07d7
+      m_osigttou = signal (SIGTTOU, SIG_IGN);
be07d7
+#endif
be07d7
+  }
be07d7
+
be07d7
+  ~scoped_ignore_sigttou ()
be07d7
+  {
be07d7
+#ifdef SIGTTOU
be07d7
+    if (job_control)
be07d7
+      signal (SIGTTOU, m_osigttou);
be07d7
+#endif
be07d7
+  }
be07d7
+
be07d7
+  DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou);
be07d7
+
be07d7
+private:
be07d7
+#ifdef SIGTTOU
be07d7
+  sighandler_t m_osigttou = NULL;
be07d7
+#endif
be07d7
+};
be07d7
 
be07d7
 #endif /* inflow.h */
be07d7
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
be07d7
--- a/gdb/ser-unix.c
be07d7
+++ b/gdb/ser-unix.c
be07d7
@@ -32,6 +32,7 @@
be07d7
 #include "gdbcmd.h"
be07d7
 #include "filestuff.h"
be07d7
 #include <termios.h>
be07d7
+#include "inflow.h"
be07d7
 
be07d7
 struct hardwire_ttystate
be07d7
   {
be07d7
@@ -164,6 +165,9 @@ hardwire_print_tty_state (struct serial *scb,
be07d7
 static int
be07d7
 hardwire_drain_output (struct serial *scb)
be07d7
 {
be07d7
+  /* Ignore SIGTTOU which may occur during the drain.  */
be07d7
+  scoped_ignore_sigttou ignore_sigttou;
be07d7
+
be07d7
   return tcdrain (scb->fd);
be07d7
 }
be07d7
 
be07d7
diff --git a/gdb/top.c b/gdb/top.c
be07d7
--- a/gdb/top.c
be07d7
+++ b/gdb/top.c
be07d7
@@ -34,8 +34,8 @@
be07d7
 #include "expression.h"
be07d7
 #include "value.h"
be07d7
 #include "language.h"
be07d7
-#include "terminal.h"		/* For job_control.  */
be07d7
-#include "job-control.h"
be07d7
+#include "terminal.h"
be07d7
+#include "common/job-control.h"
be07d7
 #include "annotate.h"
be07d7
 #include "completer.h"
be07d7
 #include "top.h"