OSDN Git Service

* linux-low.c (linux_create_inferior): Call setpgid. Return
authordrow <drow>
Thu, 29 Aug 2002 18:50:24 +0000 (18:50 +0000)
committerdrow <drow>
Thu, 29 Aug 2002 18:50:24 +0000 (18:50 +0000)
        the new PID.
        (unstopped_p, linux_signal_pid): Remove.
        (linux_target_ops): Remove linux_signal_pid.
        * remote-utils.c (putpkt, input_interrupt): Use signal_pid
        global instead of target method.
        * target.h (struct target_ops): Remove signal_pid.  Update comment
        for create_inferior.
        * server.c (signal_pid): New variable.
        (create_inferior): Set signal_pid.  Block SIGTTOU and SIGTTIN in
        gdbserver.  Set the child to be the foreground process group.
        (attach_inferior): Set signal_pid.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c
gdb/gdbserver/remote-utils.c
gdb/gdbserver/server.c
gdb/gdbserver/target.h

index c5365cf..e7ab609 100644 (file)
@@ -1,3 +1,18 @@
+2002-08-29  Daniel Jacobowitz  <drow@mvista.com>
+
+       * linux-low.c (linux_create_inferior): Call setpgid.  Return
+       the new PID.
+       (unstopped_p, linux_signal_pid): Remove.
+       (linux_target_ops): Remove linux_signal_pid.
+       * remote-utils.c (putpkt, input_interrupt): Use signal_pid
+       global instead of target method.
+       * target.h (struct target_ops): Remove signal_pid.  Update comment
+       for create_inferior.
+       * server.c (signal_pid): New variable.
+       (create_inferior): Set signal_pid.  Block SIGTTOU and SIGTTIN in
+       gdbserver.  Set the child to be the foreground process group. 
+       (attach_inferior): Set signal_pid.
+
 2002-08-23  Daniel Jacobowitz  <drow@mvista.com>
 
        * ChangeLog: New file, with entries from gdb/ChangeLog after GDB 5.2.
index 7048daf..7644f9e 100644 (file)
@@ -149,6 +149,8 @@ linux_create_inferior (char *program, char **allargs)
 
       signal (SIGRTMIN + 1, SIG_DFL);
 
+      setpgid (0, 0);
+
       execv (program, allargs);
 
       fprintf (stderr, "Cannot exec %s: %s.\n", program,
@@ -160,7 +162,7 @@ linux_create_inferior (char *program, char **allargs)
   new_process = add_process (pid);
   add_thread (pid, new_process);
 
-  return 0;
+  return pid;
 }
 
 /* Attach to an inferior process.  */
@@ -1228,34 +1230,6 @@ linux_look_up_symbols (void)
 #endif
 }
 
-/* Return 1 if this process is not stopped.  */
-static int
-unstopped_p (struct inferior_list_entry *entry, void *dummy)
-{
-  struct process_info *process = (struct process_info *) entry;
-
-  if (process->stopped)
-    return 0;
-
-  return 1;
-}
-
-static int
-linux_signal_pid ()
-{
-  struct inferior_list_entry *process;
-
-  process = find_inferior (&all_processes, unstopped_p, NULL);
-
-  if (process == NULL)
-    {
-      warning ("no unstopped process");
-      return inferior_pid;
-    }
-
-  return pid_of ((struct process_info *) process);
-}
-
 \f
 static struct target_ops linux_target_ops = {
   linux_create_inferior,
@@ -1269,7 +1243,6 @@ static struct target_ops linux_target_ops = {
   linux_read_memory,
   linux_write_memory,
   linux_look_up_symbols,
-  linux_signal_pid,
 };
 
 static void
index c610c4c..d569937 100644 (file)
@@ -46,6 +46,8 @@ static int remote_desc;
 extern int using_threads;
 extern int debug_threads;
 
+extern int signal_pid;
+
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
@@ -324,7 +326,7 @@ putpkt (char *buf)
 
       /* Check for an input interrupt while we're here.  */
       if (buf3[0] == '\003')
-       kill ((*the_target->signal_pid) (), SIGINT);
+       kill (signal_pid, SIGINT);
     }
   while (buf3[0] != '+');
 
@@ -361,7 +363,7 @@ input_interrupt (int unused)
          return;
        }
       
-      kill ((*the_target->signal_pid) (), SIGINT);
+      kill (signal_pid, SIGINT);
     }
 }
 
index b674ed0..d0963ba 100644 (file)
 
 #include "server.h"
 
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+
 int cont_thread;
 int general_thread;
 int step_thread;
@@ -31,14 +35,27 @@ int server_waiting;
 
 jmp_buf toplevel;
 
+/* The PID of the originally created or attached inferior.  Used to
+   send signals to the process when GDB sends us an asynchronous interrupt
+   (user hitting Control-C in the client), and to wait for the child to exit
+   when no longer debugging it.  */
+
+int signal_pid;
+
 static unsigned char
 start_inferior (char *argv[], char *statusptr)
 {
-  /* FIXME Check error? Or turn to void.  */
-  create_inferior (argv[0], argv);
+  signal (SIGTTOU, SIG_DFL);
+  signal (SIGTTIN, SIG_DFL);
+
+  signal_pid = create_inferior (argv[0], argv);
 
   fprintf (stderr, "Process %s created; pid = %d\n", argv[0],
-          all_threads.head->id);
+          signal_pid);
+
+  signal (SIGTTOU, SIG_IGN);
+  signal (SIGTTIN, SIG_IGN);
+  tcsetpgrp (fileno (stderr), signal_pid);
 
   /* Wait till we are at 1st instruction in program, return signal number.  */
   return mywait (statusptr, 0);
@@ -49,9 +66,15 @@ attach_inferior (int pid, char *statusptr, unsigned char *sigptr)
 {
   /* myattach should return -1 if attaching is unsupported,
      0 if it succeeded, and call error() otherwise.  */
+
   if (myattach (pid) != 0)
     return -1;
 
+  /* FIXME - It may be that we should get the SIGNAL_PID from the
+     attach function, so that it can be the main thread instead of
+     whichever we were told to attach to.  */
+  signal_pid = pid;
+
   *sigptr = mywait (statusptr, 0);
 
   return 0;
index c6aeee6..e554c0a 100644 (file)
@@ -32,7 +32,7 @@ struct target_ops
      ARGS is a standard NULL-terminated array of arguments,
      to be passed to the inferior as ``argv''.
 
-     Returns 0 on success, -1 on failure.  Registers the new
+     Returns the new PID on success, -1 on failure.  Registers the new
      process with the process list.  */
 
   int (*create_inferior) (char *program, char **args);
@@ -104,11 +104,6 @@ struct target_ops
      symbols.  */
 
   void (*look_up_symbols) (void);
-
-  /* Return the PID we should send a signal to.  Used for asynchronous
-     interrupts (user hitting Control-C).  */
-
-  int (*signal_pid) (void);
 };
 
 extern struct target_ops *the_target;