* inftarg.c (child_thread_alive): New function to see if a
[deliverable/binutils-gdb.git] / gdb / inflow.c
index 55569d08fe549163d1d43618d3f6dfe8040c78b4..353c6c4ee3f417c72515397fdb3f257c5ef6ed4c 100644 (file)
@@ -25,6 +25,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "serial.h"
 #include "terminal.h"
 #include "target.h"
+#include "thread.h"
 
 #include <signal.h>
 #include <fcntl.h>
@@ -56,12 +57,6 @@ kill_command PARAMS ((char *, int));
 
 static void
 terminal_ours_1 PARAMS ((int));
-
-/* Nonzero if we are debugging an attached outside process
-   rather than an inferior.  */
-
-int attach_flag;
-
 \f
 /* Record terminal status separately for debugger and inferior.  */
 
@@ -140,12 +135,15 @@ gdb_has_a_terminal ()
              our_process_group = tcgetpgrp (0);
 #endif
 #ifdef HAVE_SGTTY
-             ioctl (scb->fd, TIOCGPGRP, &our_process_group);
+             ioctl (0, TIOCGPGRP, &our_process_group);
 #endif
            }
        }
 
       return gdb_has_a_terminal_flag == yes;
+    default:
+      /* "Can't happen".  */
+      return 0;
     }
 }
 
@@ -153,7 +151,7 @@ gdb_has_a_terminal ()
 
 #define        OOPSY(what)     \
   if (result == -1)    \
-    fprintf(stderr, "[%s failed in terminal_inferior: %s]\n", \
+    fprintf_unfiltered(gdb_stderr, "[%s failed in terminal_inferior: %s]\n", \
            what, strerror (errno))
 
 static void terminal_ours_1 PARAMS ((int));
@@ -172,7 +170,17 @@ terminal_init_inferior ()
        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
 #endif
 
       /* Make sure that next time we call terminal_inferior (which will be
@@ -235,7 +243,7 @@ terminal_inferior ()
 #endif
 
 #ifdef HAVE_SGTTY
-         result = ioctl (0, TIOCSPGRP, inferior_process_group);
+         result = ioctl (0, TIOCSPGRP, &inferior_process_group);
          if (!attach_flag)
            OOPSY ("TIOCSPGRP");
 #endif
@@ -305,12 +313,15 @@ terminal_ours_1 (output_only)
       inferior_process_group = tcgetpgrp (0);
 #endif
 #ifdef HAVE_SGTTY
-      ioctl (scb->fd, TIOCGPGRP, &inferior_process_group);
+      ioctl (0, TIOCGPGRP, &inferior_process_group);
 #endif
 
       /* Here we used to set ICANON in our ttystate, but I believe this
         was an artifact from before when we used readline.  Readline sets
-        the tty state when it needs to.  */
+        the tty state when it needs to.
+        FIXME-maybe: However, query() expects non-raw mode and doesn't
+        use readline.  Maybe query should use readline (on the other hand,
+        this only matters for HAVE_SGTTY, not termio or termios, I think).  */
 
       /* Set tty state to our_ttystate.  We don't change in our out of raw
         mode, to avoid flushing input.  We need to do the same thing
@@ -318,6 +329,7 @@ terminal_ours_1 (output_only)
         terminal_is_ours and terminal_is_ours_for_output flags.  It's OK,
         though, since readline will deal with raw mode when/if it needs to.
         */
+
       SERIAL_NOFLUSH_SET_TTY_STATE (stdin_serial, our_ttystate,
                                    inferior_ttystate);
 
@@ -325,12 +337,19 @@ terminal_ours_1 (output_only)
        {
 #ifdef HAVE_TERMIOS
          result = tcsetpgrp (0, our_process_group);
-         OOPSY ("tcsetpgrp");
+#if 0
+         /* This fails on Ultrix with EINVAL if you run the testsuite
+            in the background with nohup, and then log out.  GDB never
+            used to check for an error here, so perhaps there are other
+            such situations as well.  */
+         if (result == -1)
+           fprintf_unfiltered (gdb_stderr, "[tcsetpgrp failed in terminal_ours: %s]\n",
+                    strerror (errno));
 #endif
+#endif /* termios */
 
 #ifdef HAVE_SGTTY
-         result = ioctl (0, TIOCSPGRP, our_process_group);
-         OOPSY ("TIOCSPGRP");
+         result = ioctl (0, TIOCSPGRP, &our_process_group);
 #endif
        }
 
@@ -514,46 +533,24 @@ kill_command (arg, from_tty)
      char *arg;
      int from_tty;
 {
-  /* Shouldn't this be target_has_execution?  FIXME.  */
-  if (inferior_pid == 0)
+  if (!target_has_execution)
     error ("The program is not being run.");
   if (!query ("Kill the program being debugged? "))
     error ("Not confirmed.");
   target_kill ();
 
+  init_thread_list();          /* Destroy thread info */
+
   /* Killing off the inferior can leave us with a core file.  If so,
      print the state we are left in.  */
   if (target_has_stack) {
-    printf_filtered ("In %s,\n", current_target->to_longname);
+    printf_filtered ("In %s,\n", target_longname);
     if (selected_frame == NULL)
-      fputs_filtered ("No selected stack frame.\n", stdout);
+      fputs_filtered ("No selected stack frame.\n", gdb_stdout);
     else
       print_stack_frame (selected_frame, selected_frame_level, 1);
   }
 }
-
-/* The inferior process has died.  Long live the inferior!  */
-
-void
-generic_mourn_inferior ()
-{
-  inferior_pid = 0;
-  attach_flag = 0;
-  breakpoint_init_inferior ();
-  registers_changed ();
-
-#ifdef CLEAR_DEFERRED_STORES
-  /* Delete any pending stores to the inferior... */
-  CLEAR_DEFERRED_STORES;
-#endif
-
-  reopen_exec_file ();
-  reinit_frame_cache ();
-
-  /* It is confusing to the user for ignore counts to stick around
-     from previous runs of the inferior.  So clear them.  */
-  breakpoint_clear_ignore_counts ();
-}
 \f
 /* Call set_sigint_trap when you need to pass a signal on to an attached
    process when handling SIGINT */
@@ -580,8 +577,67 @@ clear_sigint_trap()
   signal (SIGINT, osig);
 }
 \f
+#if defined (SIGIO) && defined (FASYNC) && defined (FD_SET) && defined (F_SETOWN)
+static void (*old_sigio) ();
+
+static void
+handle_sigio (signo)
+     int signo;
+{
+  int numfds;
+  fd_set readfds;
+
+  signal (SIGIO, handle_sigio);
+
+  FD_ZERO (&readfds);
+  FD_SET (target_activity_fd, &readfds);
+  numfds = select (target_activity_fd + 1, &readfds, NULL, NULL, NULL);
+  if (numfds >= 0 && FD_ISSET (target_activity_fd, &readfds))
+    {
+      if ((*target_activity_function) ())
+       kill (inferior_pid, SIGINT);
+    }
+}
+
+static int old_fcntl_flags;
+
+void
+set_sigio_trap ()
+{
+  if (target_activity_function)
+    {
+      old_sigio = (void (*) ()) signal (SIGIO, handle_sigio);
+      fcntl (target_activity_fd, F_SETOWN, getpid()); 
+      old_fcntl_flags = fcntl (target_activity_fd, F_GETFL, 0);
+      fcntl (target_activity_fd, F_SETFL, old_fcntl_flags | FASYNC);
+    }
+}
+
+void
+clear_sigio_trap ()
+{
+  if (target_activity_function)
+    {
+      signal (SIGIO, old_sigio);
+      fcntl (target_activity_fd, F_SETFL, old_fcntl_flags);
+    }
+}
+#else /* No SIGIO.  */
+void
+set_sigio_trap ()
+{
+  if (target_activity_function)
+    abort ();
+}
 
-int job_control;
+void
+clear_sigio_trap ()
+{
+  if (target_activity_function)
+    abort ();
+}
+#endif /* No SIGIO.  */
+\f
 
 /* This is here because this is where we figure out whether we (probably)
    have job control.  Just using job_control only does part of it because
@@ -596,6 +652,7 @@ int
 gdb_setpgid ()
 {
   int retval = 0;
+
   if (job_control)
     {
 #if defined (NEED_POSIX_SETPGID) || defined (HAVE_TERMIOS)
This page took 0.025649 seconds and 4 git commands to generate.