Tue Dec 15 10:05:56 1992 Ian Lance Taylor (ian@cygnus.com)
[deliverable/binutils-gdb.git] / gdb / inflow.c
index 35aad977e865be178e5c73c07e0d14a3fd0da0ae..8d9a6aac1534a75f6031fc802f49bb5970dd1618 100644 (file)
@@ -1,5 +1,5 @@
 /* Low level interface to ptrace, for GDB when running under Unix.
-   Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -17,7 +17,6 @@ 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.  */
 
-#include <stdio.h>
 #include "defs.h"
 #include "frame.h"
 #include "inferior.h"
@@ -35,10 +34,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <fcntl.h>
 
 #include <sys/param.h>
-#include <sys/dir.h>
 #include <signal.h>
 
-extern char *strerror();               /* strings corresponding to errno */
+static void
+kill_command PARAMS ((char *, int));
+
+static void
+terminal_ours_1 PARAMS ((int));
 
 extern struct target_ops child_ops;
 
@@ -52,10 +54,10 @@ int attach_flag;
 
 /* Does GDB have a terminal (on stdin)?  */
 int gdb_has_a_terminal;
-
+#if !defined(__GO32__)
 static TERMINAL sg_inferior;
 static TERMINAL sg_ours;
-
+#endif
 static int tflags_inferior;
 static int tflags_ours;
 
@@ -78,11 +80,11 @@ static int lmode_ours;
 # ifdef SHORT_PGRP
 static short pgrp_inferior;
 static short pgrp_ours;
-# else
+# else /* not def SHORT_PGRP */
 static int pgrp_inferior;
 static int pgrp_ours;
-# endif
-#else
+# endif /* not def SHORT_PGRP */
+#else /* not def TIOCGPGRP */
 static void (*sigint_ours) ();
 static void (*sigquit_ours) ();
 #endif /* TIOCGPGRP */
@@ -112,6 +114,7 @@ static void terminal_ours_1 ();
 void
 terminal_init_inferior ()
 {
+#if !defined(__GO32__)
   sg_inferior = sg_ours;
   tflags_inferior = tflags_ours;
 
@@ -130,7 +133,7 @@ terminal_init_inferior ()
 #ifdef TIOCGPGRP
   pgrp_inferior = inferior_pid;
 #endif /* TIOCGPGRP */
-
+#endif
   terminal_is_ours = 1;
 }
 
@@ -140,6 +143,7 @@ terminal_init_inferior ()
 void
 terminal_inferior ()
 {
+#if !defined(__GO32__)
   int result;
 
   if (gdb_has_a_terminal && terminal_is_ours && inferior_thisrun_terminal == 0)
@@ -165,12 +169,18 @@ terminal_inferior ()
 
 #ifdef TIOCGPGRP
       result = ioctl (0, TIOCSPGRP, &pgrp_inferior);
-      OOPSY ("ioctl TIOCSPGRP");
+      /* If we attached to the process, we might or might not be sharing
+        a terminal.  Avoid printing error msg if we are unable to set our
+        terminal's process group to his process group ID.  */
+      if (!attach_flag) {
+       OOPSY ("ioctl TIOCSPGRP");
+      }
 #else
       sigint_ours = (void (*) ()) signal (SIGINT, SIG_IGN);
       sigquit_ours = (void (*) ()) signal (SIGQUIT, SIG_IGN);
 #endif /* TIOCGPGRP */
     }
+#endif
   terminal_is_ours = 0;
 }
 
@@ -202,6 +212,7 @@ static void
 terminal_ours_1 (output_only)
      int output_only;
 {
+#if !defined(__GO32__)
   int result;
 #ifdef TIOCGPGRP
   /* Ignore this signal since it will happen when we try to set the pgrp.  */
@@ -274,6 +285,9 @@ terminal_ours_1 (output_only)
 #else /* not HAVE_TERMIO */
   sg_ours.sg_flags &= ~RAW & ~CBREAK;
 #endif /* not HAVE_TERMIO */
+
+  result = result;     /* lint */
+#endif
 }
 
 /* ARGSUSED */
@@ -297,11 +311,13 @@ child_terminal_info (args, from_tty)
     printf_filtered ("This GDB does not control a terminal.\n");
     return;
   }
-
+#if !defined(__GO32__)
+#ifdef TIOCGPGRP
   printf_filtered ("Inferior's terminal status (currently saved by GDB):\n");
 
   printf_filtered ("owner pgrp = %d, fcntl flags = 0x%x.\n",
          pgrp_inferior, tflags_inferior);
+#endif /* TIOCGPGRP */
 
 #ifdef HAVE_TERMIO
 
@@ -337,6 +353,10 @@ child_terminal_info (args, from_tty)
 #ifdef TIOCLGET
   printf_filtered ("lmode:  0x%x\n", lmode_inferior);
 #endif
+#else
+  printf_filtered("This is a DOS machine; there is no terminal state\n");
+#endif
+
 }
 \f
 /* NEW_TTY_PREFORK is called before forking a new child process,
@@ -361,17 +381,22 @@ void
 new_tty ()
 {
   register int tty;
+  void (*osigttou) ();
 
   if (inferior_thisrun_terminal == 0)
     return;
-
+#if !defined(__GO32__)
 #ifdef TIOCNOTTY
-  /* Disconnect the child process from our controlling terminal.  */
+  /* Disconnect the child process from our controlling terminal.  On some
+     systems (SVR4 for example), this may cause a SIGTTOU, so temporarily
+     ignore SIGTTOU. */
   tty = open("/dev/tty", O_RDWR);
   if (tty > 0)
     {
+      osigttou = (void (*)()) signal(SIGTTOU, SIG_IGN);
       ioctl(tty, TIOCNOTTY, 0);
       close(tty);
+      (void) signal(SIGTTOU, osigttou);
     }
 #endif
 
@@ -397,6 +422,7 @@ new_tty ()
     { close (2); dup (tty); }
   if (tty > 2)
     close(tty);
+#endif /* !go32*/o
 }
 \f
 /* Kill the inferior process.  Make us have no inferior.  */
@@ -411,7 +437,7 @@ kill_command (arg, from_tty)
     error ("The program is not being run.");
   if (!query ("Kill the inferior process? "))
     error ("Not confirmed.");
-  target_kill (arg, from_tty);
+  target_kill ();
 
   /* Killing off the inferior can leave us with a core file.  If so,
      print the state we are left in.  */
@@ -486,8 +512,8 @@ try_writing_regs_command (arg, from_tty)
     {
       QUIT;
       errno = 0;
-      value = call_ptrace (3, inferior_pid, i, 0);
-      call_ptrace (6, inferior_pid, i, value);
+      value = call_ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) i, 0);
+      call_ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) i, value);
       if (errno == 0)
        {
          printf (" Succeeded with address 0x%x; value 0x%x (%d).\n",
@@ -521,8 +547,8 @@ Report which ones can be written.");
   /* Get all the current tty settings (including whether we have a tty at
      all!).  */
 
+#if !defined(__GO32__)
   tflags_ours = fcntl (0, F_GETFL, 0);
-  OOPSY ("fcntl F_GETFL");             /* Should always work */
 
   result = ioctl (0, TIOCGETP, &sg_ours);
   if (result == 0) {
@@ -543,6 +569,10 @@ Report which ones can be written.");
   } else {
     gdb_has_a_terminal = 0;
   }
+#else
+  gdb_has_a_terminal = 0;
+#endif
+
 
   terminal_is_ours = 1;
 }
This page took 0.025237 seconds and 4 git commands to generate.