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

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