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

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