Fix -Wuh and -Wnhu options so that they work.
[deliverable/binutils-gdb.git] / gdb / inflow.c
index 095614215d93f0337cf2fe5f8e9c578a6c0a0a71..6ce7721a93b2779f6abe5804234e0d75678ff661 100644 (file)
@@ -1,5 +1,5 @@
 /* Low level interface to ptrace, for GDB when running under Unix.
-   Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1986-87, 1989, 1991-92, 1995, 1998 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -15,7 +15,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "frame.h"
@@ -25,24 +25,26 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "serial.h"
 #include "terminal.h"
 #include "target.h"
-#include "thread.h"
+#include "gdbthread.h"
 
+#include "gdb_string.h"
 #include <signal.h>
 #include <fcntl.h>
-
-#if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY) && !defined (__GO32__)
-#define HAVE_SGTTY
-#endif
-
-#if defined (HAVE_TERMIOS)
-#include <termios.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
 
 #ifdef HAVE_TERMIOS
 #define PROCESS_GROUP_TYPE pid_t
 #endif
 
+#ifdef HAVE_TERMIO
+#define PROCESS_GROUP_TYPE int
+#endif
+
 #ifdef HAVE_SGTTY
 #ifdef SHORT_PGRP
 /* This is only used for the ultra.  Does it have pid_t?  */
@@ -52,6 +54,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 #endif /* sgtty */
 
+#if defined (SIGIO) && defined (FASYNC) && defined (FD_SET) && defined (F_SETOWN)
+static void
+handle_sigio PARAMS ((int));
+#endif
+
+extern void _initialize_inflow PARAMS ((void));
+
+static void
+pass_signal PARAMS ((int));
+
 static void
 kill_command PARAMS ((char *, int));
 
@@ -87,6 +99,7 @@ PROCESS_GROUP_TYPE inferior_process_group;
    inferior only.  If we have job control, that takes care of it.  If not,
    we save our handlers in these two variables and set SIGINT and SIGQUIT
    to SIG_IGN.  */
+
 static void (*sigint_ours) ();
 static void (*sigquit_ours) ();
 
@@ -99,7 +112,7 @@ static char *inferior_thisrun_terminal;
    inferior's settings are in effect.  Ignored if !gdb_has_a_terminal
    ().  */
 
-static int terminal_is_ours;
+int terminal_is_ours;
 
 enum {yes, no, have_not_checked} gdb_has_a_terminal_flag = have_not_checked;
 
@@ -134,6 +147,9 @@ gdb_has_a_terminal ()
 #ifdef HAVE_TERMIOS
              our_process_group = tcgetpgrp (0);
 #endif
+#ifdef HAVE_TERMIO
+             our_process_group = getpgrp ();
+#endif
 #ifdef HAVE_SGTTY
              ioctl (0, TIOCGPGRP, &our_process_group);
 #endif
@@ -160,7 +176,8 @@ static void terminal_ours_1 PARAMS ((int));
    before we actually run the inferior.  */
 
 void
-terminal_init_inferior ()
+terminal_init_inferior_with_pgrp (pgrp)
+     int pgrp;
 {
   if (gdb_has_a_terminal ())
     {
@@ -169,18 +186,9 @@ terminal_init_inferior ()
       if (inferior_ttystate)
        free (inferior_ttystate);
       inferior_ttystate = SERIAL_GET_TTY_STATE (stdin_serial);
+
 #ifdef PROCESS_GROUP_TYPE
-#ifdef PIDGET
-      /* This is for Lynx, and should be cleaned up by having Lynx be
-        a separate debugging target with a version of
-        target_terminal_init_inferior which passes in the process
-        group to a generic routine which does all the work (and the
-        non-threaded child_terminal_init_inferior can just pass in
-        inferior_pid to the same routine).  */
-      inferior_process_group = PIDGET (inferior_pid);
-#else
-      inferior_process_group = inferior_pid;
-#endif
+      inferior_process_group = pgrp;
 #endif
 
       /* Make sure that next time we call terminal_inferior (which will be
@@ -190,6 +198,20 @@ terminal_init_inferior ()
     }
 }
 
+void
+terminal_init_inferior ()
+{
+#ifdef PROCESS_GROUP_TYPE
+  /* This is for Lynx, and should be cleaned up by having Lynx be a separate
+     debugging target with a version of target_terminal_init_inferior which
+     passes in the process group to a generic routine which does all the work
+     (and the non-threaded child_terminal_init_inferior can just pass in
+     inferior_pid to the same routine).  */
+  /* We assume INFERIOR_PID is also the child's process group.  */
+  terminal_init_inferior_with_pgrp (PIDGET (inferior_pid));
+#endif /* PROCESS_GROUP_TYPE */
+}
+
 /* Put the inferior's terminal settings into effect.
    This is preparation for starting or resuming the inferior.  */
 
@@ -219,7 +241,9 @@ terminal_inferior ()
       if (!job_control)
        {
          sigint_ours = (void (*) ()) signal (SIGINT, SIG_IGN);
+#ifdef SIGQUIT
          sigquit_ours = (void (*) ()) signal (SIGQUIT, SIG_IGN);
+#endif
        }
 
       /* If attach_flag is set, we don't know whether we are sharing a
@@ -312,6 +336,9 @@ terminal_ours_1 (output_only)
 #ifdef HAVE_TERMIOS
       inferior_process_group = tcgetpgrp (0);
 #endif
+#ifdef HAVE_TERMIO
+      inferior_process_group = getpgrp ();
+#endif
 #ifdef HAVE_SGTTY
       ioctl (0, TIOCGPGRP, &inferior_process_group);
 #endif
@@ -361,7 +388,9 @@ terminal_ours_1 (output_only)
       if (!job_control)
        {
          signal (SIGINT, sigint_ours);
+#ifdef SIGQUIT
          signal (SIGQUIT, sigquit_ours);
+#endif
        }
 
 #ifdef F_GETFL
@@ -483,7 +512,7 @@ new_tty ()
 
   if (inferior_thisrun_terminal == 0)
     return;
-#if !defined(__GO32__)
+#if !defined(__GO32__) && !defined(_WIN32)
 #ifdef TIOCNOTTY
   /* Disconnect the child process from our controlling terminal.  On some
      systems (SVR4 for example), this may cause a SIGTTOU, so temporarily
@@ -522,7 +551,7 @@ new_tty ()
     { close (2); dup (tty); }
   if (tty > 2)
     close(tty);
-#endif /* !go32 */
+#endif /* !go32 && !win32*/
 }
 \f
 /* Kill the inferior process.  Make us have no inferior.  */
@@ -533,7 +562,10 @@ kill_command (arg, from_tty)
      char *arg;
      int from_tty;
 {
-  /* Shouldn't this be target_has_execution?  FIXME.  */
+  /* FIXME:  This should not really be inferior_pid (or target_has_execution).
+     It should be a distinct flag that indicates that a target is active, cuz
+     some targets don't have processes! */
+
   if (inferior_pid == 0)
     error ("The program is not being run.");
   if (!query ("Kill the program being debugged? "))
@@ -561,7 +593,9 @@ static void
 pass_signal (signo)
     int signo;
 {
-  kill (inferior_pid, SIGINT);
+#ifndef _WIN32
+  kill (PIDGET (inferior_pid), SIGINT);
+#endif
 }
 
 static void (*osig)();
@@ -569,16 +603,22 @@ static void (*osig)();
 void
 set_sigint_trap()
 {
-  osig = (void (*) ()) signal (SIGINT, pass_signal);
+  if (attach_flag || inferior_thisrun_terminal)
+    {
+      osig = (void (*) ()) signal (SIGINT, pass_signal);
+    }
 }
 
 void
 clear_sigint_trap()
 {
-  signal (SIGINT, osig);
+  if (attach_flag || inferior_thisrun_terminal)
+    {
+      signal (SIGINT, osig);
+    }
 }
 \f
-#if defined (SIGIO) && defined (FASYNC) && defined (FD_SET)
+#if defined (SIGIO) && defined (FASYNC) && defined (FD_SET) && defined (F_SETOWN)
 static void (*old_sigio) ();
 
 static void
@@ -595,8 +635,10 @@ handle_sigio (signo)
   numfds = select (target_activity_fd + 1, &readfds, NULL, NULL, NULL);
   if (numfds >= 0 && FD_ISSET (target_activity_fd, &readfds))
     {
+#ifndef _WIN32
       if ((*target_activity_function) ())
        kill (inferior_pid, SIGINT);
+#endif
     }
 }
 
@@ -656,8 +698,7 @@ gdb_setpgid ()
 
   if (job_control)
     {
-#if defined (NEED_POSIX_SETPGID) || defined (HAVE_TERMIOS)
-      /* Do all systems with termios have setpgid?  I hope so.  */
+#if defined (NEED_POSIX_SETPGID) || (defined (HAVE_TERMIOS) && defined (HAVE_SETPGID))
       /* setpgid (0, 0) is supposed to work and mean the same thing as
         this, but on Ultrix 4.2A it fails with EPERM (and
         setpgid (getpid (), getpid ()) succeeds).  */
@@ -697,9 +738,13 @@ _initialize_inflow ()
 #ifdef _POSIX_JOB_CONTROL
   job_control = 1;
 #else
+#ifdef _SC_JOB_CONTROL
   job_control = sysconf (_SC_JOB_CONTROL);
-#endif
-#endif /* termios */
+#else
+  job_control = 0;     /* have to assume the worst */
+#endif /* _SC_JOB_CONTROL */
+#endif /* _POSIX_JOB_CONTROL */
+#endif /* HAVE_TERMIOS */
 
 #ifdef HAVE_SGTTY
 #ifdef TIOCGPGRP
This page took 0.02762 seconds and 4 git commands to generate.