* 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.
+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.
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 */
/* 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
#define USG 1
#endif
-#define TIOCGETC_BROKEN 1
-#define TIOCGLTC_BROKEN 1
-
#include <sys/param.h>
#include <sys/time.h>
#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
/* 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
#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
#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>
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. */
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;
}
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;
int rate;
}
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;
const char *str;
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);
}
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;
}
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;
int rate;
}
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;
const char *str;
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
struct hardwire_ttystate
{
struct termios termios;
+ pid_t process_group;
};
#endif
struct hardwire_ttystate
{
struct termio termio;
+ int process_group;
};
#endif
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
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
}
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
}
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;
}
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;
const char *str;
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. */
}
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 */
#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. */
#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));
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