This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Simplify child_terminal_inferior


The comment about Lynx in child_terminal_init reads a bit odd, since
it's not exactly clear what "This" in "This is for Lynx" is referring
to.  Looking back in history makes it clearer.  When the comment was
originally added, in commit 91ecc8efa9b9, back in 1994, the code
looked like this:

~~~
#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
~~~

So this looked like it was about when GDB was growing support for
multi-threading, and inferior_pid was still a single int for most
ports.

Eventually we got ptid_t, so the comment isn't really useful today.
Particularly more so since we no longer support Lynx as a GDB host.

The only caller left of child_terminal_init_with_pgrp is gnu-nat.c
(the Hurd), and that target uses fork-child, so when we reach
gnu_terminal_init the current inferior must already have the PID set,
and the child must be a process group leader.

I added the assertion to child_terminal_init just because it didn't
feel right to only have a comment stating the assumption.  And then
because DJGPP's header declares setpgid but not getpgid (uh...), I had
to add the autoconf check for getpgid.  (Note that go32-nat.c
overrides all the terminal-related entry points...)

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* configure.ac: Add getpgid to the checked functions.
	* gnu-nat.c (gnu_terminal_init): Delete.
	(gnu_target): Don't install gnu_terminal_init.
	* inflow.c (child_terminal_init_with_pgrp): Deleted, mergee with ...
	(child_terminal_init): ... this function.  Assert that inferior is
	a process group leader.
---
 gdb/config.in    |  3 +++
 gdb/configure    |  2 +-
 gdb/configure.ac |  2 +-
 gdb/gnu-nat.c    |  7 -------
 gdb/inflow.c     | 24 +++++++-----------------
 5 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/gdb/config.in b/gdb/config.in
index 3f8ee38..cbe44a7 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -192,6 +192,9 @@
 /* Define to 1 if you have the `getpagesize' function. */
 #undef HAVE_GETPAGESIZE
 
+/* Define to 1 if you have the `getpgid' function. */
+#undef HAVE_GETPGID
+
 /* Define to 1 if you have the `getrlimit' function. */
 #undef HAVE_GETRLIMIT
 
diff --git a/gdb/configure b/gdb/configure
index c638652..55e3a30 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -12678,7 +12678,7 @@ fi
 
 for ac_func in getauxval getrusage getuid getgid \
 		pipe poll pread pread64 pwrite resize_term \
-		sbrk setpgid setpgrp setsid \
+		sbrk getpgid setpgid setpgrp setsid \
 		sigaction sigprocmask sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
 		setrlimit getrlimit posix_madvise waitpid \
diff --git a/gdb/configure.ac b/gdb/configure.ac
index b909217..39d2485 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1358,7 +1358,7 @@ AC_FUNC_MMAP
 AC_FUNC_VFORK
 AC_CHECK_FUNCS([getauxval getrusage getuid getgid \
 		pipe poll pread pread64 pwrite resize_term \
-		sbrk setpgid setpgrp setsid \
+		sbrk getpgid setpgid setpgrp setsid \
 		sigaction sigprocmask sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
 		setrlimit getrlimit posix_madvise waitpid \
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 7cb6e4a..2ae2031 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2279,12 +2279,6 @@ gnu_detach (struct target_ops *ops, const char *args, int from_tty)
   inf_child_maybe_unpush_target (ops);
 }
 
-static void
-gnu_terminal_init (struct target_ops *self)
-{
-  gdb_assert (gnu_current_inf);
-  child_terminal_init_with_pgrp (gnu_current_inf->pid);
-}
 
 static void
 gnu_stop (struct target_ops *self, ptid_t ptid)
@@ -2693,7 +2687,6 @@ gnu_target (void)
   t->to_wait = gnu_wait;
   t->to_xfer_partial = gnu_xfer_partial;
   t->to_find_memory_regions = gnu_find_memory_regions;
-  t->to_terminal_init = gnu_terminal_init;
   t->to_kill = gnu_kill_inferior;
   t->to_create_inferior = gnu_create_inferior;
   t->to_mourn_inferior = gnu_mourn_inferior;
diff --git a/gdb/inflow.c b/gdb/inflow.c
index b3f14e4..594717e 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -163,7 +163,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);
@@ -171,8 +171,12 @@ 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.  We assume the child is a process group
+     leader at this point.  */
+  tinfo->process_group = inf->pid;
+#ifdef HAVE_GETPGID
+  gdb_assert (getpgid (inf->pid) == inf->pid);
+#endif
 #endif
 
   if (gdb_has_a_terminal ())
@@ -202,20 +206,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 */
-}
-
 /* RAII class used to ignore SIGTTOU in a scope.  */
 
 class scoped_ignore_sigttou
-- 
2.5.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]