]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* inftarg.c: Remove unused include of terminal.h.
authorJim Kingdon <jkingdon@engr.sgi.com>
Wed, 30 Jun 1993 22:20:53 +0000 (22:20 +0000)
committerJim Kingdon <jkingdon@engr.sgi.com>
Wed, 30 Jun 1993 22:20:53 +0000 (22:20 +0000)
* signals.h: Don't undefine signals anymore.
* main.c: Use job_control from serial.h.
* fork-child.c (fork_inferior): Use gdb_setpgid.
* serial.h, ser-unix.c, ser-go32.c: Provide gdb_setpgid.
* utils.c (quit): Use current_target->to_terminal_ours to figure
out whether we care about lack of job control, rather than __GO32__.
* utils.c: Include serial.h not terminal.h
(quit): Use job_control not TIOCGPGRP.
* terminal.h: Don't undefine TIOCGPGRP.
* serial.h, ser-unix.c, ser-go32.c, ser-tcp.c: Add SERIAL_FLUSH_OUTPUT.
* utils.c (quit): Use it.
* serial.h: Add SERIAL_UN_FDOPEN.
* utils.c (quit): Use it.
* ser-unix.c: Add process group to ttystate.
[HAVE_SGTTY]: Add tchars, ltchars, and lmode to ttystate.
* inflow.c: Include serial.h not terminal.h.
Use serial.h stuff to replace most of the maze of #ifdef's.
* inflow.c, main.c, inferior.h: make gdb_has_a_terminal a function.
* serial.h: Document SERIAL_SET_TTY_STATE as being immediate.
* ser-unix.c: Use TIOCSETN not TIOCSETP so it is true.
* serial.h, ser-unix.c, ser-go32.c, ser-tcp.c:
Add SERIAL_PRINT_TTY_STATE, SERIAL_NOFLUSH_SET_TTY_STATE, and
SERIAL_SET_PROCESS_GROUP.
* inflow.c: Use them.
* config/xm-svr4.h, config/rs6000/xm-rs6000.h, config/sparc/sun4os4.h:
Define HAVE_TERMIOS.
* Various: Remove all use of TIOC*_BROKEN.

13 files changed:
gdb/ChangeLog
gdb/config/i386/xm-i386sco.h
gdb/config/i386/xm-i386v32.h
gdb/config/m88k/xm-delta88.h
gdb/config/rs6000/xm-rs6000.h
gdb/config/sparc/xm-sun4os4.h
gdb/config/xm-sysv4.h
gdb/fork-child.c
gdb/ser-go32.c
gdb/ser-tcp.c
gdb/ser-unix.c
gdb/serial.h
gdb/signals.h

index febebb77edf8e9f4af15fcda68b67c35317e6211..3b447531660ece958c6b46068196df94b0e94ec2 100644 (file)
@@ -1,3 +1,34 @@
+Tue Jun 29 11:02:58 1993  Jim Kingdon  (kingdon@lioth.cygnus.com)
+
+       * inftarg.c: Remove unused include of terminal.h.
+       * signals.h: Don't undefine signals anymore.
+       * main.c: Use job_control from serial.h.
+       * fork-child.c (fork_inferior): Use gdb_setpgid.
+       * serial.h, ser-unix.c, ser-go32.c: Provide gdb_setpgid.
+       * utils.c (quit): Use current_target->to_terminal_ours to figure
+       out whether we care about lack of job control, rather than __GO32__.
+       * utils.c: Include serial.h not terminal.h
+       (quit): Use job_control not TIOCGPGRP.
+       * terminal.h: Don't undefine TIOCGPGRP.
+       * serial.h, ser-unix.c, ser-go32.c, ser-tcp.c: Add SERIAL_FLUSH_OUTPUT.
+       * utils.c (quit): Use it.
+       * serial.h: Add SERIAL_UN_FDOPEN.
+       * utils.c (quit): Use it.
+       * ser-unix.c: Add process group to ttystate.
+       [HAVE_SGTTY]: Add tchars, ltchars, and lmode to ttystate.
+       * inflow.c: Include serial.h not terminal.h.
+       Use serial.h stuff to replace most of the maze of #ifdef's.
+       * inflow.c, main.c, inferior.h: make gdb_has_a_terminal a function.
+       * serial.h: Document SERIAL_SET_TTY_STATE as being immediate.
+       * ser-unix.c: Use TIOCSETN not TIOCSETP so it is true.
+       * serial.h, ser-unix.c, ser-go32.c, ser-tcp.c:
+       Add SERIAL_PRINT_TTY_STATE, SERIAL_NOFLUSH_SET_TTY_STATE, and
+       SERIAL_SET_PROCESS_GROUP.
+       * inflow.c: Use them.
+       * config/xm-svr4.h, config/rs6000/xm-rs6000.h, config/sparc/sun4os4.h:
+       Define HAVE_TERMIOS.
+       * Various: Remove all use of TIOC*_BROKEN.
+
 Wed Jun 30 12:20:51 1993  Peter Schauer  (pes@regent.e-technik.tu-muenchen.de)
 
        * config/m68k/tm-sun3.h (BELIEVE_PCC_PROMOTION_TYPE): Define.
index e500e26a5545f1f9c41032f8523a70b1f13d486f..968e0a00769c784a1282f4ea6ed122d5f0915bc2 100644 (file)
@@ -27,10 +27,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
    the name of this field is.  */
 #define U_FPSTATE(u) u.u_fps.u_fpstate
 
-/* TIOCGETC is defined in System V 3.2 termio.h, but struct tchars
-   is not.  This makes problems for inflow.c.  */
-#define TIOCGETC_BROKEN
-
 /* All the job control definitions exist in SCO Unix, but the standard
    shells don't use them.  So we must disable job control. */
 /* This is no longer true with 3.2v2 and later */
index 129f8b8a1a04044b6f3f7859caeec297fa29d741..bdec33882aca904f52fd669db1a6b0fae29ce1e8 100644 (file)
@@ -22,7 +22,3 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Apparently there is inconsistency among various System V's about what
    the name of this field is.  */
 #define U_FPSTATE(u) u.u_fps.u_fpstate
-
-/* TIOCGETC is defined in System V 3.2 termio.h, but struct tchars
-   is not.  This makes problems for inflow.c.  */
-#define TIOCGETC_BROKEN
index 1fa021419f0a987b575cd7e4cd17350dc478fdb0..7398f588a836aec8e706c610ef1dfd1fcbf13a7f 100644 (file)
@@ -24,9 +24,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define USG 1
 #endif
 
-#define TIOCGETC_BROKEN 1
-#define TIOCGLTC_BROKEN 1
-
 #include <sys/param.h>
 #include <sys/time.h>
 
index 718b10a845de9ec72b632bcfca6a32318d860ed7..b44287d4f8ba077e96b028af92ddcee788010f3c 100644 (file)
@@ -37,7 +37,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #define        HOST_BYTE_ORDER BIG_ENDIAN
 
-#define        HAVE_TERMIO 1
+/* At least as of AIX 3.2, we have termios.  */
+#define        HAVE_TERMIOS 1
+/* #define HAVE_TERMIO 1 */
+
 #define        USG 1
 #define        HAVE_SIGSETMASK 1
 
index db2c8151893d556bcd63ce049cd5e4c1f5f68b8a..03d1c8f5d088b6d158942dbdf17e638e9df1f606 100644 (file)
@@ -57,3 +57,9 @@ extern int free ();
 /* SunOS 4.x uses nonstandard "char *" as type of third argument to ptrace() */
 
 #define PTRACE_ARG3_TYPE char*
+
+/* Using termios is required to save and restore ICRNL and ONLCR
+   separately.  */
+
+/* At least SunOS 4.1.1 has termios.  I'm not sure about 4.0.3.  */
+#define HAVE_TERMIOS
index c2cc1f66ee274d93a00b90af5b2372b54ef84f2b..08057686d0f2f7fadfae466c4de2261c8380adff 100644 (file)
@@ -22,22 +22,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #define SVR4_SHARED_LIBS
 
-/* SVR4 has termio facilities. */
+/* SVR4 has termios facilities. */
 
-#define HAVE_TERMIO
+#define HAVE_TERMIOS
 
 /* SVR4 has mmap facilities */
 
 #define HAVE_MMAP
 
-/* TIOCGETC and TIOCGLTC are picked up somewhere, but struct tchars
-   and struct ltchars are not.  This makes problems for inflow.c.
-   It is unknown at this time if this is a generic SVR4 problem or
-   one just limited to the initial SVR4 port host machine. */
-
-#define TIOCGETC_BROKEN
-#define TIOCGLTC_BROKEN
-
 /* SVR4 is a derivative of System V Release 3 (USG) */
 
 #define USG
index 613f1eeaa10bdd0e50f93e4623e73fbb9e065130..b413889f996908f2f7ea5c78fc3b6ec66a01423a 100644 (file)
@@ -24,7 +24,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "wait.h"
 #include "gdbcore.h"
-#include "terminal.h"          /* For #ifdef TIOCGPGRP and new_tty */
+#include "serial.h" /* For job_control.  */
+#include "terminal.h"          /* For new_tty */
 
 #include <signal.h>
 
@@ -152,20 +153,10 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun)
       if (debug_fork) 
        sleep (debug_fork);
 
-#ifdef TIOCGPGRP
       /* Run inferior in a separate process group.  */
-#ifdef NEED_POSIX_SETPGID
-      debug_setpgrp = setpgid (0, 0);
-#else
-#if defined(USG) && !defined(SETPGRP_ARGS)
-      debug_setpgrp = setpgrp ();
-#else
-      debug_setpgrp = setpgrp (getpid (), getpid ());
-#endif /* USG */
-#endif /* NEED_POSIX_SETPGID */
+      debug_setpgrp = gdb_setpgid ();
       if (debug_setpgrp == -1)
         perror("setpgrp failed in child");
-#endif /* TIOCGPGRP */
 
 #ifdef SET_STACK_LIMIT_HUGE
       /* Reset the stack limit back to what it was.  */
index 8689e24ea0a1351b4fdad5297d0c5b0d578df08f..ff1bdf119307aeaffa7082b81786a87b18ac7a7c 100644 (file)
@@ -266,6 +266,14 @@ go32_open (scb, name)
   return 0;
 }
 
+static int
+go32_flush_output (scb)
+     serial_t scb;
+{
+  /* No need to flush, because there is no buffering.  */
+  return 0;
+}
+
 static void
 go32_raw (scb)
      serial_t scb;
@@ -310,6 +318,24 @@ go32_set_tty_state(scb, ttystate)
   return 0;
 }
 
+static int
+go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
+     serial_t scb;
+     serial_ttystate new_ttystate;
+     serial_ttystate old_ttystate;
+{
+  return 0;
+}
+
+static void
+go32_print_tty_state (scb, ttystate)
+     serial_t scb;
+     serial_ttystate ttystate;
+{
+  /* Nothing to print.  */
+  return;
+}
+
 static int
 go32_setbaudrate (scb, rate)
      serial_t scb;
@@ -318,6 +344,15 @@ go32_setbaudrate (scb, rate)
   return 0;
 }
 
+static int
+go32_set_process_group (scb, ttystate, group)
+     serial_t scb;
+     serial_ttystate ttystate;
+     int group;
+{
+  return 0;
+}
+
 static int
 go32_write (scb, str, len)
      serial_t scb;
@@ -343,13 +378,25 @@ static struct serial_ops go32_ops =
   go32_close,
   go32_readchar,
   go32_write,
+  go32_flush_output,
   go32_raw,
   go32_get_tty_state,
   go32_set_tty_state,
-  go32_setbaudrate
+  go32_print_tty_state,
+  go32_noflush_set_tty_state,
+  go32_setbaudrate,
+  go32_set_process_group
 };
 
+/* There is never job control on go32.  */
+int
+gdb_setpgid ()
+{
+  return 0;
+}
+
 _initialize_ser_go32 ()
 {
+  job_control = 0;
   serial_add_interface (&go32_ops);
 }
index 5afe63e3d63e50e01005aff868ae2b90284c0259..6ff79aa3d4a670dc67b539e3be046ea3bad646c4 100644 (file)
@@ -140,6 +140,15 @@ tcp_set_tty_state(scb, ttystate)
   return 0;
 }
 
+static int
+tcp_flush_output (scb)
+     serial_t scb;
+{
+  /* This is only used by utils.c on stdout, so it doesn't need to work
+     for tcp.  */
+  return 0;
+}
+
 static void
 tcp_raw(scb)
      serial_t scb;
@@ -226,6 +235,24 @@ tcp_readchar(scb, timeout)
   return *scb->bufp++;
 }
 
+static int
+tcp_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
+     serial_t scb;
+     serial_ttystate new_ttystate;
+     serial_ttystate old_ttystate;
+{
+  return 0;
+}
+
+static void
+tcp_print_tty_state (scb, ttystate)
+     serial_t scb;
+     serial_ttystate ttystate;
+{
+  /* Nothing to print.  */
+  return;
+}
+
 static int
 tcp_setbaudrate(scb, rate)
      serial_t scb;
@@ -234,6 +261,15 @@ tcp_setbaudrate(scb, rate)
   return 0;                    /* Never fails! */
 }
 
+static int
+tcp_set_process_group (scb, ttystate, group)
+     serial_t scb;
+     serial_ttystate ttystate;
+     int group;
+{
+  return 0;
+}
+
 static int
 tcp_write(scb, str, len)
      serial_t scb;
@@ -273,10 +309,14 @@ static struct serial_ops tcp_ops =
   tcp_close,
   tcp_readchar,
   tcp_write,
+  tcp_flush_output,
   tcp_raw,
   tcp_get_tty_state,
   tcp_set_tty_state,
+  tcp_print_tty_state,
+  tcp_noflush_set_tty_state,
   tcp_setbaudrate,
+  tcp_set_process_group
 };
 
 void
index eb34da5de7ff1c413af3faa0ba1f563dae3484dc..e88fbb7ab7893a68b77f7b2c569909f529fd3086 100644 (file)
@@ -33,6 +33,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 struct hardwire_ttystate
 {
   struct termios termios;
+  pid_t process_group;
 };
 #endif
 
@@ -42,6 +43,7 @@ struct hardwire_ttystate
 struct hardwire_ttystate
 {
   struct termio termio;
+  int process_group;
 };
 #endif
 
@@ -55,6 +57,17 @@ struct hardwire_ttystate
 struct hardwire_ttystate
 {
   struct sgttyb sgttyb;
+  struct tchars tc;
+  struct ltchars ltc;
+  /* Line discipline flags.  */
+  int lmode;
+
+#ifdef SHORT_PGRP
+  /* This is only used for the ultra.  Does it have pid_t?  */
+  short process_group;
+#else
+  int process_group;
+#endif
 };
 #endif
 
@@ -92,15 +105,45 @@ get_tty_state(scb, state)
      struct hardwire_ttystate *state;
 {
 #ifdef HAVE_TERMIOS
-  return tcgetattr(scb->fd, &state->termios);
+  pid_t new_process_group;
+
+  if (tcgetattr(scb->fd, &state->termios) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  new_process_group = tcgetpgrp (scb->fd);
+  if (new_process_group == (pid_t)-1)
+    return -1;
+  state->process_group = new_process_group;
+  return 0;
 #endif
 
 #ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCGETA, &state->termio);
+  if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  return ioctl (scb->fd, TIOCGPGRP, &state->process_group);
 #endif
 
 #ifdef HAVE_SGTTY
-  return ioctl (scb->fd, TIOCGETP, &state->sgttyb);
+  if (ioctl (scb->fd, TIOCGETP, &state->sgttyb) < 0)
+    return -1;
+  if (ioctl (scb->fd, TIOCGETC, &state->tc) < 0)
+    return -1;
+  if (ioctl (scb->fd, TIOCGLTC, &state->ltc) < 0)
+    return -1;
+  if (ioctl (scb->fd, TIOCLGET, &state->lmode) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  return ioctl (scb->fd, TIOCGPGRP, &state->process_group);
 #endif
 }
 
@@ -109,18 +152,40 @@ set_tty_state(scb, state)
      serial_t scb;
      struct hardwire_ttystate *state;
 {
-  int err;
-
 #ifdef HAVE_TERMIOS
-  return tcsetattr(scb->fd, TCSANOW, &state->termios);
+  if (tcsetattr(scb->fd, TCSANOW, &state->termios) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  /* Need to ignore errors, at least if attach_flag is set.  */
+  tcsetpgrp (scb->fd, state->process_group);
+  return 0;
 #endif
 
 #ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCSETA, &state->termio);
+  if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  /* Need to ignore errors, at least if attach_flag is set.  */
+  ioctl (scb->fd, TIOCSPGRP, &state->process_group);
+  return 0;
 #endif
 
 #ifdef HAVE_SGTTY
-  return ioctl (scb->fd, TIOCSETP, &state->sgttyb);
+  if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
+    return -1;
+
+  if (!job_control)
+    return 0;
+
+  /* Need to ignore errors, at least if attach_flag is set.  */
+  ioctl (scb->fd, TIOCSPGRP, &state->process_group);
+  return 0;
 #endif
 }
 
@@ -150,6 +215,120 @@ hardwire_set_tty_state(scb, ttystate)
   return set_tty_state(scb, state);
 }
 
+static int
+hardwire_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
+     serial_t scb;
+     serial_ttystate new_ttystate;
+     serial_ttystate old_ttystate;
+{
+  struct hardwire_ttystate new_state =
+    *(struct hardwire_ttystate *)new_ttystate;
+  struct hardwire_ttystate *state = (struct hardwire_ttystate *) old_ttystate;
+
+#ifdef HAVE_TERMIOS
+  /* I'm not sure whether this is necessary; the manpage makes no mention
+     of discarding input when switching to/from ICANON.  */
+  if (state->termios.c_lflag & ICANON)
+    new_state.termios.c_lflag |= ICANON;
+  else
+    new_state.termios.c_lflag &= ~ICANON;
+#endif
+
+#ifdef HAVE_TERMIO
+  /* I'm not sure whether this is necessary; the manpage makes no mention
+     of discarding input when switching to/from ICANON.  */
+  if (state->termio.c_lflag & ICANON)
+    new_state.termio.c_lflag |= ICANON;
+  else
+    new_state.termio.c_lflag &= ~ICANON;
+#endif
+
+#ifdef HAVE_SGTTY
+  if (state->sgttyb.sg_flags & RAW)
+    new_state.sgttyb.sg_flags |= RAW;
+  else
+    new_state.sgttyb.sg_flags &= ~RAW;
+
+  /* I'm not sure whether this is necessary; the manpage just mentions
+     RAW not CBREAK.  */
+  if (state->sgttyb.sg_flags & CBREAK)
+    new_state.sgttyb.sg_flags |= CBREAK;
+  else
+    new_state.sgttyb.sg_flags &= ~CBREAK;
+#endif
+
+  return set_tty_state (scb, &new_state);
+}
+
+static void
+hardwire_print_tty_state (scb, ttystate)
+     serial_t scb;
+     serial_ttystate ttystate;
+{
+  struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
+  int i;
+
+  printf_filtered ("Process group = %d\n", state->process_group);
+
+#ifdef HAVE_TERMIOS
+  printf_filtered ("c_iflag = 0x%x, c_oflag = 0x%x,\n",
+                  state->termios.c_iflag, state->termios.c_oflag);
+  printf_filtered ("c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n",
+                  state->termios.c_cflag, state->termios.c_lflag,
+                  state->termios.c_line);
+  printf_filtered ("c_cc: ");
+  for (i = 0; i < NCCS; i += 1)
+    printf_filtered ("0x%x ", state->termios.c_cc[i]);
+  printf_filtered ("\n");
+#endif
+
+#ifdef HAVE_TERMIO
+  printf_filtered ("c_iflag = 0x%x, c_oflag = 0x%x,\n",
+                  state->termio.c_iflag, state->termio.c_oflag);
+  printf_filtered ("c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n",
+                  state->termio.c_cflag, state->termio.c_lflag,
+                  state->termio.c_line);
+  printf_filtered ("c_cc: ");
+  for (i = 0; i < NCC; i += 1)
+    printf_filtered ("0x%x ", state->termio.c_cc[i]);
+  printf_filtered ("\n");
+#endif
+
+#ifdef HAVE_SGTTY
+  printf_filtered ("sgttyb.sg_flags = 0x%x.\n", state->sgttyb.sg_flags);
+
+  printf_filtered ("tchars: ");
+  for (i = 0; i < (int)sizeof (struct tchars); i++)
+    printf_filtered ("0x%x ", ((unsigned char *)&state->tc)[i]);
+  printf_filtered ("\n");
+
+  printf_filtered ("ltchars: ");
+  for (i = 0; i < (int)sizeof (struct ltchars); i++)
+    printf_filtered ("0x%x ", ((unsigned char *)&state->ltc)[i]);
+  printf_filtered ("\n");
+
+  printf_filtered ("lmode:  0x%x\n", state->lmode);
+#endif
+}
+
+static int
+hardwire_flush_output (scb)
+     serial_t scb;
+{
+#ifdef HAVE_TERMIOS
+  return tcflush (scb->fd, TCOFLUSH);
+#endif
+
+#ifdef HAVE_TERMIO
+  return ioctl (scb->fd, TCFLSH, 1);
+#endif
+
+#ifdef HAVE_SGTTY
+  /* This flushes both input and output, but we can't do better.  */
+  return ioctl (scb->fd, TIOCFLUSH, 0);
+#endif  
+}
+
 static void
 hardwire_raw(scb)
      serial_t scb;
@@ -379,6 +558,16 @@ hardwire_setbaudrate(scb, rate)
   return set_tty_state (scb, &state);
 }
 
+static int
+hardwire_set_process_group (scb, ttystate, group)
+     serial_t scb;
+     serial_ttystate ttystate;
+     int group;
+{
+  ((struct hardwire_ttystate *)ttystate)->process_group = group;
+  return 0;
+}
+
 static int
 hardwire_write(scb, str, len)
      serial_t scb;
@@ -418,14 +607,75 @@ static struct serial_ops hardwire_ops =
   hardwire_close,
   hardwire_readchar,
   hardwire_write,
+  hardwire_flush_output,
   hardwire_raw,
   hardwire_get_tty_state,
   hardwire_set_tty_state,
+  hardwire_print_tty_state,
+  hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
+  hardwire_set_process_group
 };
 
+int job_control;
+#if defined (HAVE_TERMIOS)
+#include <unistd.h>
+#endif
+
+/* 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
+   setpgid or setpgrp might not exist on a system without job control.
+   It might be considered misplaced (on the other hand, process groups and
+   job control are closely related to ttys).
+
+   For a more clean implementation, in libiberty, put a setpgid which merely
+   calls setpgrp and a setpgrp which does nothing (any system with job control
+   will have one or the other).  */
+int
+gdb_setpgid ()
+{
+  int retval = 0;
+  if (job_control)
+    {
+#if defined (NEED_POSIX_SETPGID) || defined (HAVE_TERMIOS)
+      /* Do all systems with termios have setpgid?  I hope so.  */
+      retval = setpgid (0, 0);
+#else
+#if defined (TIOCGPGRP)
+#if defined(USG) && !defined(SETPGRP_ARGS)
+      retval = setpgrp ();
+#else
+      retval = setpgrp (getpid (), getpid ());
+#endif /* USG */
+#endif /* TIOCGPGRP.  */
+#endif /* NEED_POSIX_SETPGID */
+    }
+  return retval;
+}
+
 void
 _initialize_ser_hardwire ()
 {
   serial_add_interface (&hardwire_ops);
+
+  /* OK, figure out whether we have job control.  */
+
+#if defined (HAVE_TERMIOS)
+  /* Do all systems with termios have the POSIX way of identifying job
+     control?  I hope so.  */
+#ifdef _POSIX_JOB_CONTROL
+  job_control = _POSIX_JOB_CONTROL;
+#else
+  job_control = sysconf (_SC_JOB_CONTROL);
+#endif
+
+#else /* not termios.  */
+
+#ifdef TIOCGPGRP
+  job_control = 1;
+#else
+  job_control = 0;
+#endif /* TIOCGPGRP */
+
+#endif /* not termios.  */
 }
index f83fda7045f42141331fc7377916cdbd649ee430..630ed43b1f9712cc10983fa99f1b2057a8d470b9 100644 (file)
@@ -41,10 +41,15 @@ struct serial_ops {
   void (*close) PARAMS ((serial_t));
   int (*readchar) PARAMS ((serial_t, int timeout));
   int (*write) PARAMS ((serial_t, const char *str, int len));
+  int (*flush_output) PARAMS ((serial_t));
   void (*go_raw) PARAMS ((serial_t));
   serial_ttystate (*get_tty_state) PARAMS ((serial_t));
   int (*set_tty_state) PARAMS ((serial_t, serial_ttystate));
+  void (*print_tty_state) PARAMS ((serial_t, serial_ttystate));
+  int (*noflush_set_tty_state)
+    PARAMS ((serial_t, serial_ttystate, serial_ttystate));
   int (*setbaudrate) PARAMS ((serial_t, int rate));
+  int (*set_process_group) PARAMS ((serial_t, serial_ttystate, int));
 };
 
 /* Add a new serial interface to the interface list */
@@ -67,14 +72,36 @@ serial_t serial_fdopen PARAMS ((int fd));
 
 #define SERIAL_FDOPEN(FD) serial_fdopen(FD)
 
+/* Flush pending output.  */
+
+#define SERIAL_FLUSH_OUTPUT(SERIAL_T) \
+  ((SERIAL_T)->ops->flush_output((SERIAL_T)))
+
 /* Turn the port into raw mode. */
 
 #define SERIAL_RAW(SERIAL_T) (SERIAL_T)->ops->go_raw((SERIAL_T))
 
+/* Return a pointer to a newly malloc'd ttystate containing the state
+   of the tty.  */
 #define SERIAL_GET_TTY_STATE(SERIAL_T) (SERIAL_T)->ops->get_tty_state((SERIAL_T))
 
+/* Set the state of the tty to TTYSTATE.  The change is immediate.
+   When changing to or from raw mode, input might be discarded.  */
 #define SERIAL_SET_TTY_STATE(SERIAL_T, TTYSTATE) (SERIAL_T)->ops->set_tty_state((SERIAL_T), (TTYSTATE))
 
+/* printf_filtered a user-comprehensible description of ttystate.  */
+#define SERIAL_PRINT_TTY_STATE(SERIAL_T, TTYSTATE) \
+  ((*((SERIAL_T)->ops->print_tty_state)) ((SERIAL_T), (TTYSTATE)))
+
+/* Set the tty state to NEW_TTYSTATE, where OLD_TTYSTATE is the
+   current state (generally obtained from a recent call to
+   SERIAL_GET_TTY_STATE), but be careful not to discard any input.
+   This means that we never switch in or out of raw mode, even
+   if NEW_TTYSTATE specifies a switch.  */
+#define SERIAL_NOFLUSH_SET_TTY_STATE(SERIAL_T, NEW_TTYSTATE, OLD_TTYSTATE) \
+  ((*((SERIAL_T)->ops->noflush_set_tty_state)) \
+    ((SERIAL_T), (NEW_TTYSTATE), (OLD_TTYSTATE)))
+
 /* Read one char from the serial device with TIMEOUT seconds timeout.
    Returns char if ok, else one of the following codes.  Note that all
    error codes are guaranteed to be < 0.  */
@@ -101,3 +128,21 @@ void serial_close PARAMS ((serial_t));
 
 #define SERIAL_CLOSE(SERIAL_T) serial_close(SERIAL_T)
 
+/* Destroy SERIAL_T without doing the rest of the stuff that SERIAL_CLOSE
+   does.  */
+
+#define SERIAL_UN_FDOPEN(SERIAL_T) (free (SERIAL_T))
+
+/* Set the process group saved in TTYSTATE to GROUP.  This just modifies
+   the ttystate setting; need to call SERIAL_SET_TTY_STATE for this to
+   actually have any effect.  If no job control, then don't do anything.  */
+#define SERIAL_SET_PROCESS_GROUP(SERIAL_T, TTYSTATE, GROUP) \
+  ((*((SERIAL_T)->ops->set_process_group)) (SERIAL_T, TTYSTATE, GROUP))
+
+/* Do we have job control?  Can be assumed to always be the same within
+   a given run of GDB.  In ser-unix.c, ser-go32.c, etc.  */
+extern int job_control;
+
+/* Set the process group of the caller to its own pid, or do nothing if
+   we lack job control.  */
+extern int gdb_setpgid PARAMS ((void));
index a89fc0387c7504e16c3a5e3d090dddb5f246fa84..08fa606ef0974b456ce9d299a9d92a0d16e441f3 100644 (file)
@@ -22,13 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
     eliminates certain signal names when job control is not supported,
     (or, on some systems, when job control is there but doesn't work
     the way GDB expects it to work).  */
+/* This has been superceded by the job_control variable in serial.h.  */
 
 #include <signal.h>
-
-#ifdef NO_JOB_CONTROL
-# undef SIGTSTP
-# undef SIGSTOP
-# undef SIGCONT
-# undef SIGTTIN
-# undef SIGTTOU
-#endif