Remove DEF_VEC_P (varobj_p)
[deliverable/binutils-gdb.git] / gdb / inflow.c
index a96d4fc4a513ad75cd469337f206e9ba7a527c7a..7c49246b6f2ad2fcc44db865f52b8c65af6995e2 100644 (file)
@@ -91,6 +91,35 @@ static serial_ttystate initial_gdb_ttystate;
 
 static struct terminal_info *get_inflow_inferior_data (struct inferior *);
 
+/* RAII class used to ignore SIGTTOU in a scope.  */
+
+class scoped_ignore_sigttou
+{
+public:
+  scoped_ignore_sigttou ()
+  {
+#ifdef SIGTTOU
+    if (job_control)
+      m_osigttou = signal (SIGTTOU, SIG_IGN);
+#endif
+  }
+
+  ~scoped_ignore_sigttou ()
+  {
+#ifdef SIGTTOU
+    if (job_control)
+      signal (SIGTTOU, m_osigttou);
+#endif
+  }
+
+  DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou);
+
+private:
+#ifdef SIGTTOU
+  sighandler_t m_osigttou = NULL;
+#endif
+};
+
 #ifdef HAVE_TERMIOS_H
 
 /* Return the process group of the current inferior.  */
@@ -165,7 +194,7 @@ gdb_has_a_terminal (void)
    before we actually run the inferior.  */
 
 void
-child_terminal_init_with_pgrp (int pgrp)
+child_terminal_init (struct target_ops *self)
 {
   struct inferior *inf = current_inferior ();
   struct terminal_info *tinfo = get_inflow_inferior_data (inf);
@@ -173,8 +202,10 @@ child_terminal_init_with_pgrp (int pgrp)
 #ifdef HAVE_TERMIOS_H
   /* Store the process group even without a terminal as it is used not
      only to reset the tty foreground process group, but also to
-     interrupt the inferior.  */
-  tinfo->process_group = pgrp;
+     interrupt the inferior.  A child we spawn should be a process
+     group leader (PGID==PID) at this point, though that may not be
+     true if we're attaching to an existing process.  */
+  tinfo->process_group = inf->pid;
 #endif
 
   if (gdb_has_a_terminal ())
@@ -204,20 +235,6 @@ gdb_save_tty_state (void)
     }
 }
 
-void
-child_terminal_init (struct target_ops *self)
-{
-#ifdef HAVE_TERMIOS_H
-  /* This is for Lynx, and should be cleaned up by having Lynx be a
-     separate debugging target with a version of target_terminal::init
-     which passes in the process group to a generic routine which does
-     all the work (and the non-threaded child_terminal_init can just
-     pass in inferior_ptid to the same routine).  */
-  /* We assume INFERIOR_PID is also the child's process group.  */
-  child_terminal_init_with_pgrp (ptid_get_pid (inferior_ptid));
-#endif /* HAVE_TERMIOS_H */
-}
-
 /* Put the inferior's terminal settings into effect.
    This is preparation for starting or resuming the inferior.
 
@@ -244,10 +261,6 @@ child_terminal_inferior (struct target_ops *self)
       int result;
 
 #ifdef F_GETFL
-      /* Is there a reason this is being done twice?  It happens both
-         places we use F_SETFL, so I'm inclined to think perhaps there
-         is some reason, however perverse.  Perhaps not though...  */
-      result = fcntl (0, F_SETFL, tinfo->tflags);
       result = fcntl (0, F_SETFL, tinfo->tflags);
       OOPSY ("fcntl F_SETFL");
 #endif
@@ -345,17 +358,11 @@ child_terminal_ours_1 (int output_only)
     return;
   else
     {
-#ifdef SIGTTOU
-      /* Ignore this signal since it will happen when we try to set the
-         pgrp.  */
-      sighandler_t osigttou = NULL;
-#endif
       int result ATTRIBUTE_UNUSED;
 
-#ifdef SIGTTOU
-      if (job_control)
-       osigttou = signal (SIGTTOU, SIG_IGN);
-#endif
+      /* Ignore SIGTTOU since it will happen when we try to set the
+        terminal's pgrp.  */
+      scoped_ignore_sigttou ignore_sigttou;
 
       xfree (tinfo->ttystate);
       tinfo->ttystate = serial_get_tty_state (stdin_serial);
@@ -388,11 +395,6 @@ child_terminal_ours_1 (int output_only)
 #endif /* termios */
        }
 
-#ifdef SIGTTOU
-      if (job_control)
-       signal (SIGTTOU, osigttou);
-#endif
-
       if (!job_control)
        {
          signal (SIGINT, sigint_ours);
@@ -403,11 +405,6 @@ child_terminal_ours_1 (int output_only)
 
 #ifdef F_GETFL
       tinfo->tflags = fcntl (0, F_GETFL, 0);
-
-      /* Is there a reason this is being done twice?  It happens both
-         places we use F_SETFL, so I'm inclined to think perhaps there
-         is some reason, however perverse.  Perhaps not though...  */
-      result = fcntl (0, F_SETFL, our_terminal_info.tflags);
       result = fcntl (0, F_SETFL, our_terminal_info.tflags);
 #endif
     }
@@ -488,7 +485,7 @@ copy_terminal_info (struct inferior *to, struct inferior *from)
 }
 
 void
-info_terminal_command (char *arg, int from_tty)
+info_terminal_command (const char *arg, int from_tty)
 {
   target_terminal::info (arg, from_tty);
 }
@@ -624,12 +621,10 @@ new_tty (void)
   tty = open ("/dev/tty", O_RDWR);
   if (tty > 0)
     {
-      sighandler_t osigttou;
+      scoped_ignore_sigttou ignore_sigttou;
 
-      osigttou = signal (SIGTTOU, SIG_IGN);
       ioctl (tty, TIOCNOTTY, 0);
       close (tty);
-      signal (SIGTTOU, osigttou);
     }
 #endif
 
This page took 0.024971 seconds and 4 git commands to generate.