public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/3] Eliminate STOP_SIGNAL, use SIGTSTP directly
  2017-11-02 15:12 [PATCH 0/3] Some terminal handling TCL Pedro Alves
  2017-11-02 15:12 ` [PATCH 2/3] Don't set terminal flags twice in a row Pedro Alves
  2017-11-02 15:12 ` [PATCH 1/3] Assume termios is available, remove support for termio and sgtty Pedro Alves
@ 2017-11-02 15:12 ` Pedro Alves
  2 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2017-11-02 15:12 UTC (permalink / raw)
  To: gdb-patches

The STOP_SIGNAL macro was originally added for Convex Unix [1]:

In:

  git show 7a67dd45ca1c:gdb/m-convex.h

we see:

~~~
  /* Use SIGCONT rather than SIGTSTP because convex Unix occasionally
     turkeys SIGTSTP.  I think.  */

  #define STOP_SIGNAL SIGCONT
~~~

That's gdb-3.5, 1990...  In gdb/ChangeLog-3.x we see:

~~~
Tue Apr 18 13:43:37 1989  Randall Smith  (randy at apple-gunkies.ai.mit.edu)

        Various changes involved in 1) getting gdb to work on the convex,
	[...]
        Made whatever signal indicates a stop configurable (via macro
        STOP_SIGNAL).
        (main): Setup use of above as a signal handler.  Added check for
        "-nw" in args already processed.
        (command_line_input): SIGTSTP ==>STOP_SIGNAL.
~~~

Support for Convex Unix is long gone, and nothing else overrides
STOP_SIGNAL.  So just use SIGTSTP directly, removing a little
obfuscation.

(I don't really understand why we override [1] readline's SIGTSTP
handler (only) when reading scripts (and then fail to restore it
properly, assuming SIG_DFL...), but I'll leave that for another pass.

[1] - Actually, starting with readline 6.3, readline is no longer
installing its handlers while GDB is in control...)

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

	* event-top.c: Check SIGTSTP instead of STOP_SIGNAL thoughout.
	(async_init_signals): Adjust.
	(handle_stop_sig): Rename to ...
	(handle_sigtstp): ... this.
	(async_stop_sig): Rename to ...
	(async_sigtstp_handler): ... this, and delete STOP_SIGNAL !=
	SIGTSTP path.
	* event-top.h: Move signal.h include to the top.  Check SIGTSTP
	instead of STOP_SIGNAL thoughout.
	(handle_stop_sig): Rename to ...
	(handle_sigtstp): ... this.
	* top.c (command_line_input): Replace STOP_SIGNAL -> SIGTSTP.
---
 gdb/event-top.c | 26 +++++++++++---------------
 gdb/event-top.h | 10 ++++------
 gdb/top.c       |  8 ++++----
 3 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 43e2a27..7377189 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -68,8 +68,8 @@ static void async_do_nothing (gdb_client_data);
 static void async_disconnect (gdb_client_data);
 #endif
 static void async_float_handler (gdb_client_data);
-#ifdef STOP_SIGNAL
-static void async_stop_sig (gdb_client_data);
+#ifdef SIGTSTP
+static void async_sigtstp_handler (gdb_client_data);
 #endif
 static void async_sigterm_handler (gdb_client_data arg);
 
@@ -111,7 +111,7 @@ static struct async_signal_handler *sighup_token;
 static struct async_signal_handler *sigquit_token;
 #endif
 static struct async_signal_handler *sigfpe_token;
-#ifdef STOP_SIGNAL
+#ifdef SIGTSTP
 static struct async_signal_handler *sigtstp_token;
 #endif
 static struct async_signal_handler *async_sigterm_token;
@@ -912,9 +912,9 @@ async_init_signals (void)
   sigfpe_token =
     create_async_signal_handler (async_float_handler, NULL);
 
-#ifdef STOP_SIGNAL
+#ifdef SIGTSTP
   sigtstp_token =
-    create_async_signal_handler (async_stop_sig, NULL);
+    create_async_signal_handler (async_sigtstp_handler, NULL);
 #endif
 }
 
@@ -1112,20 +1112,19 @@ async_disconnect (gdb_client_data arg)
 }
 #endif
 
-#ifdef STOP_SIGNAL
+#ifdef SIGTSTP
 void
-handle_stop_sig (int sig)
+handle_sigtstp (int sig)
 {
   mark_async_signal_handler (sigtstp_token);
-  signal (sig, handle_stop_sig);
+  signal (sig, handle_sigtstp);
 }
 
 static void
-async_stop_sig (gdb_client_data arg)
+async_sigtstp_handler (gdb_client_data arg)
 {
   char *prompt = get_prompt ();
 
-#if STOP_SIGNAL == SIGTSTP
   signal (SIGTSTP, SIG_DFL);
 #if HAVE_SIGPROCMASK
   {
@@ -1138,10 +1137,7 @@ async_stop_sig (gdb_client_data arg)
   sigsetmask (0);
 #endif
   raise (SIGTSTP);
-  signal (SIGTSTP, handle_stop_sig);
-#else
-  signal (STOP_SIGNAL, handle_stop_sig);
-#endif
+  signal (SIGTSTP, handle_sigtstp);
   printf_unfiltered ("%s", prompt);
   gdb_flush (gdb_stdout);
 
@@ -1149,7 +1145,7 @@ async_stop_sig (gdb_client_data arg)
      nothing.  */
   dont_repeat ();
 }
-#endif /* STOP_SIGNAL */
+#endif /* SIGTSTP */
 
 /* Tell the event loop what to do if SIGFPE is received.
    See event-signal.c.  */
diff --git a/gdb/event-top.h b/gdb/event-top.h
index 05241ad..d069c56 100644
--- a/gdb/event-top.h
+++ b/gdb/event-top.h
@@ -22,6 +22,8 @@
 #ifndef EVENT_TOP_H
 #define EVENT_TOP_H
 
+#include <signal.h>
+
 struct cmd_list_element;
 
 /* Exported functions from event-top.c.
@@ -36,14 +38,10 @@ extern void change_line_handler (int);
 extern void command_line_handler (char *rl);
 extern void command_handler (char *command);
 
-/* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT.  */
-#ifndef STOP_SIGNAL
-#include <signal.h>
 #ifdef SIGTSTP
-#define STOP_SIGNAL SIGTSTP
-extern void handle_stop_sig (int sig);
-#endif
+extern void handle_sigtstp (int sig);
 #endif
+
 extern void handle_sigint (int sig);
 extern void handle_sigterm (int sig);
 extern void async_request_quit (void *arg);
diff --git a/gdb/top.c b/gdb/top.c
index 9f5dd58..f006c66 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1184,9 +1184,9 @@ command_line_input (const char *prompt_arg, int repeat,
   /* Starting a new command line.  */
   cmd_line_buffer.used_size = 0;
 
-#ifdef STOP_SIGNAL
+#ifdef SIGTSTP
   if (job_control)
-    signal (STOP_SIGNAL, handle_stop_sig);
+    signal (SIGTSTP, handle_sigtstp);
 #endif
 
   while (1)
@@ -1244,9 +1244,9 @@ command_line_input (const char *prompt_arg, int repeat,
       prompt = NULL;
     }
 
-#ifdef STOP_SIGNAL
+#ifdef SIGTSTP
   if (job_control)
-    signal (STOP_SIGNAL, SIG_DFL);
+    signal (SIGTSTP, SIG_DFL);
 #endif
 
   return cmd;
-- 
2.5.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] Don't set terminal flags twice in a row
  2017-11-02 15:12 [PATCH 0/3] Some terminal handling TCL Pedro Alves
@ 2017-11-02 15:12 ` Pedro Alves
  2017-11-02 18:34   ` Sergio Durigan Junior
  2017-11-02 15:12 ` [PATCH 1/3] Assume termios is available, remove support for termio and sgtty Pedro Alves
  2017-11-02 15:12 ` [PATCH 3/3] Eliminate STOP_SIGNAL, use SIGTSTP directly Pedro Alves
  2 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-11-02 15:12 UTC (permalink / raw)
  To: gdb-patches

I find this odd 'set flags twice' ancient code and comment annoyingly
distracting.  It may well be that the reason for the double-set was
simply a copy/paste mistake, and that we've been doing this for
decades [1] for no good reason.  Let's just get rid of it, and if we
find a real reason, add it back with a comment explaining why it's
necessary.

[1] This double-set was already in gdb 2.4 / 1988, the oldest release
we have sources for, and imported in git.  From 'git show 7b4ac7e1ed2c
inflow.c':

   +void
   +terminal_inferior ()
   +{
   +  if (terminal_is_ours)   /*  && inferior_thisrun_terminal == 0) */
   +    {
   +      fcntl (0, F_SETFL, tflags_inferior);
   +      fcntl (0, F_SETFL, tflags_inferior);

The "is there a reason" comment was added in 1993, by:

  commit a88797b5eadf31e21804bc820429028bf708fbcd
  Author:     Fred Fish <fnf@specifix.com>
  AuthorDate: Thu Aug 5 01:33:45 1993 +0000

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

	* inflow.c (child_terminal_inferior, child_terminal_ours_1): No
	longer set flags twice in row.
---
 gdb/inflow.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/gdb/inflow.c b/gdb/inflow.c
index a96d4fc..d46d693 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -244,10 +244,6 @@ child_terminal_inferior (struct target_ops *self)
       int result;
 
 #ifdef F_GETFL
-      /* Is there a reason this is being done twice?  It happens both
-         places we use F_SETFL, so I'm inclined to think perhaps there
-         is some reason, however perverse.  Perhaps not though...  */
-      result = fcntl (0, F_SETFL, tinfo->tflags);
       result = fcntl (0, F_SETFL, tinfo->tflags);
       OOPSY ("fcntl F_SETFL");
 #endif
@@ -403,11 +399,6 @@ child_terminal_ours_1 (int output_only)
 
 #ifdef F_GETFL
       tinfo->tflags = fcntl (0, F_GETFL, 0);
-
-      /* Is there a reason this is being done twice?  It happens both
-         places we use F_SETFL, so I'm inclined to think perhaps there
-         is some reason, however perverse.  Perhaps not though...  */
-      result = fcntl (0, F_SETFL, our_terminal_info.tflags);
       result = fcntl (0, F_SETFL, our_terminal_info.tflags);
 #endif
     }
-- 
2.5.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Some terminal handling TCL
@ 2017-11-02 15:12 Pedro Alves
  2017-11-02 15:12 ` [PATCH 2/3] Don't set terminal flags twice in a row Pedro Alves
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Pedro Alves @ 2017-11-02 15:12 UTC (permalink / raw)
  To: gdb-patches

In context of multi-target support, I've been messing around with
GDB's tty / job control handling, the 'terminal ours/inferior'
switching, etc, and staring at gdb/inflow.c a lot.  While
adjusting/extending this machinery, the fewer code paths / variants we
have to consider, the better.  Hence this precursor series.

Patch #1 removes support for the legacy termio and sgtty terminal
interfaces in favor of assuming termios.  I believe that no
gdb-supported system is actually using termio/sgtty today, and so I
believe that this is actually a no-op change.

Patch #2 removes really odd code that doesn't look like have any
reason to exist.

Patch #3 removes a small gdb abstraction over SIGTSTP that hasn't been
useful in decades.

Pedro Alves (3):
  Assume termios is available, remove support for termio and sgtty
  Don't set terminal flags twice in a row
  Eliminate STOP_SIGNAL, use SIGTSTP directly

 gdb/Makefile.in              |   9 +-
 gdb/common/gdb_termios.h     |  78 -------------
 gdb/common/job-control.c     |  23 ++--
 gdb/configure                |   3 +-
 gdb/configure.ac             |   3 +-
 gdb/event-top.c              |  26 ++---
 gdb/event-top.h              |  10 +-
 gdb/gdbserver/configure      |   2 +-
 gdb/gdbserver/configure.ac   |   2 +-
 gdb/gdbserver/remote-utils.c |  33 +-----
 gdb/inflow.c                 |  97 ++++------------
 gdb/inflow.h                 |  12 +-
 gdb/ser-base.c               |   8 --
 gdb/ser-base.h               |   3 -
 gdb/ser-event.c              |   1 -
 gdb/ser-go32.c               |  12 --
 gdb/ser-mingw.c              |   4 -
 gdb/ser-pipe.c               |   1 -
 gdb/ser-tcp.c                |   1 -
 gdb/ser-unix.c               | 264 +------------------------------------------
 gdb/serial.c                 |   8 --
 gdb/serial.h                 |  12 --
 gdb/top.c                    |   8 +-
 23 files changed, 63 insertions(+), 557 deletions(-)
 delete mode 100644 gdb/common/gdb_termios.h

-- 
2.5.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] Assume termios is available, remove support for termio and sgtty
  2017-11-02 15:12 [PATCH 0/3] Some terminal handling TCL Pedro Alves
  2017-11-02 15:12 ` [PATCH 2/3] Don't set terminal flags twice in a row Pedro Alves
@ 2017-11-02 15:12 ` Pedro Alves
  2017-11-02 18:54   ` Sergio Durigan Junior
  2017-11-02 15:12 ` [PATCH 3/3] Eliminate STOP_SIGNAL, use SIGTSTP directly Pedro Alves
  2 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-11-02 15:12 UTC (permalink / raw)
  To: gdb-patches

This commit garbage collects the termio and sgtty support.

GDB's terminal handling code still has support for the old termio and
sgtty interfaces in addition to termios.  However, I think it's pretty
safe to assume that for a long, long time, Unix-like systems provide
termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
all have had termios.h for many years.  Looking around the web, I
found discussions about FreeBSD folks trying to get rid of old sgtty.h
a decade ago:

  https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html

So I think support for termio and sgtty in GDB is just dead code that
is never compiled anywhere and is just getting in the way.  For
example, serial_noflush_set_tty_state and the raw<->cooked concerns
mentioned in inflow.c only exist because of sgtty (see
hardwire_noflush_set_tty_state).

Regtested on GNU/Linux.

Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
that GDB still includes the termios.h-guarded code.  Confirmed
mingw-w64 GDB still builds and skips the termios.h-guarded code.

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

	* Makefile.in (SER_HARDWIRE): Update comment.
	* common/gdb_termios.h: Delete file.
	* common/job-control.c: Include termios.h and unistd.h instead of
	gdb_termios.h.
	(gdb_setpgid): Remove HAVE_TERMIOS || TIOCGPGRP preprocessor
	check.
	(have_job_control): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove sgtty code.
	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* inflow.c: Include termios.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE checks with HAVE_TERMIOS_H checks throughout.
	Replace PROCESS_GROUP_TYPE references with pid_t references
	throughout.
	(gdb_getpgrp): Delete.
	(set_initial_gdb_ttystate): Use tcgetpgrp instead of gdb_getpgrp.
	(child_terminal_inferior): Remove comment.  Remove sgtty code.
	(child_terminal_ours_1): Use tcgetpgrp directly instead of
	gdb_getpgrp.  Use serial_set_tty_state instead aof
	serial_noflush_set_tty_state.  Remove sgtty code.
	* inflow.h: Include unistd.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE check with HAVE_TERMIOS_H check.
	(inferior_process_group): Now returns pid_t.
	* ser-base.c (ser_base_noflush_set_tty_state): Delete.
	* ser-base.h (ser_base_noflush_set_tty_state): Delete.
	* ser-event.c (serial_event_ops): Update.
	* ser-go32.c (dos_noflush_set_tty_state): Delete.
	(dos_ops): Update.
	* ser-mingw.c (hardwire_ops, tty_ops, pipe_ops, tcp_ops): Update.
	* ser-pipe.c (pipe_ops): Update.
	* ser-tcp.c (tcp_ops): Update.
	* ser-unix.c: Include termios.h instead of gdb_termios.h.  Remove
	HAVE_TERMIOS checks.
	[HAVE_TERMIO] (struct hardwire_ttystate): Delete.
	[HAVE_SGTTY] (struct hardwire_ttystate): Delete.
	(get_tty_state, set_tty_state): Drop termio and sgtty code, and
	assume termios.
	(hardwire_noflush_set_tty_state): Delete.
	(hardwire_print_tty_state, hardwire_drain_output)
	(hardwire_flush_output, hardwire_flush_input)
	(hardwire_send_break, hardwire_raw, hardwire_setbaudrate)
	(hardwire_setstopbits, hardwire_setparity): Drop termio and sgtty
	code, and assume termios.
	(hardwire_ops): Update.
	(_initialize_ser_hardwire): Remove HAVE_TERMIOS check.
	* serial.c (serial_noflush_set_tty_state): Delete.
	* serial.h (serial_noflush_set_tty_state): Delete.
	(serial_ops::noflush_set_tty_state): Delete.

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

	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* remote-utils.c: Include termios.h instead of gdb_termios.h.
	(remote_open): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove termio and sgtty code.
---
 gdb/Makefile.in              |   9 +-
 gdb/common/gdb_termios.h     |  78 -------------
 gdb/common/job-control.c     |  23 ++--
 gdb/configure                |   3 +-
 gdb/configure.ac             |   3 +-
 gdb/gdbserver/configure      |   2 +-
 gdb/gdbserver/configure.ac   |   2 +-
 gdb/gdbserver/remote-utils.c |  33 +-----
 gdb/inflow.c                 |  88 ++++-----------
 gdb/inflow.h                 |  12 +-
 gdb/ser-base.c               |   8 --
 gdb/ser-base.h               |   3 -
 gdb/ser-event.c              |   1 -
 gdb/ser-go32.c               |  12 --
 gdb/ser-mingw.c              |   4 -
 gdb/ser-pipe.c               |   1 -
 gdb/ser-tcp.c                |   1 -
 gdb/ser-unix.c               | 264 +------------------------------------------
 gdb/serial.c                 |   8 --
 gdb/serial.h                 |  12 --
 20 files changed, 44 insertions(+), 523 deletions(-)
 delete mode 100644 gdb/common/gdb_termios.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 6cb0970..c2f6482 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -729,12 +729,9 @@ XMLFILES = \
 	$(srcdir)/features/traceframe-info.dtd \
 	$(srcdir)/features/xinclude.dtd
 
-# This is ser-unix.o for any system which supports a v7/BSD/SYSV/POSIX
-# interface to the serial port.  Hopefully if get ported to OS/2, VMS,
-# etc., then there will be (as part of the C library or perhaps as
-# part of libiberty) a POSIX interface.  But at least for now the
-# host-dependent makefile fragment might need to use something else
-# besides ser-unix.o
+# This is ser-unix.o for any system which supports a POSIX interface
+# to the serial port.  The host-dependent makefile fragment might need
+# to use something else besides ser-unix.o.
 SER_HARDWIRE = @SER_HARDWIRE@
 
 # The `remote' debugging target is supported for most architectures,
diff --git a/gdb/common/gdb_termios.h b/gdb/common/gdb_termios.h
deleted file mode 100644
index 1d0544d..0000000
--- a/gdb/common/gdb_termios.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Common terminal interface definitions for GDB and gdbserver.
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef GDB_TERMIOS_H
-#define GDB_TERMIOS_H
-
-/* If we're using autoconf, it will define HAVE_TERMIOS_H,
-   HAVE_TERMIO_H and HAVE_SGTTY_H for us.  One day we can rewrite
-   ser-unix.c and inflow.c to inspect those names instead of
-   HAVE_TERMIOS, HAVE_TERMIO and the implicit HAVE_SGTTY (when neither
-   HAVE_TERMIOS or HAVE_TERMIO is set).  Until then, make sure that
-   nothing has already defined the one of the names, and do the right
-   thing.  */
-
-#if !defined (HAVE_TERMIOS) && !defined(HAVE_TERMIO) && !defined(HAVE_SGTTY)
-#if defined(HAVE_TERMIOS_H)
-#define HAVE_TERMIOS
-#else /* ! defined (HAVE_TERMIOS_H) */
-#if defined(HAVE_TERMIO_H)
-#define HAVE_TERMIO
-#else /* ! defined (HAVE_TERMIO_H) */
-#if defined(HAVE_SGTTY_H)
-#define HAVE_SGTTY
-#endif /* ! defined (HAVE_SGTTY_H) */
-#endif /* ! defined (HAVE_TERMIO_H) */
-#endif /* ! defined (HAVE_TERMIOS_H) */
-#endif /* !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) &&
-	  !defined (HAVE_SGTTY) */
-
-#if defined(HAVE_TERMIOS)
-#include <termios.h>
-#endif
-
-#if !defined(_WIN32) && !defined (HAVE_TERMIOS)
-
-/* Define a common set of macros -- BSD based -- and redefine whatever
-   the system offers to make it look like that.  FIXME: serial.h and
-   ser-*.c deal with this in a much cleaner fashion; as soon as stuff
-   is converted to use them, can get rid of this crap.  */
-
-#ifdef HAVE_TERMIO
-
-#include <termio.h>
-
-#undef TIOCGETP
-#define TIOCGETP TCGETA
-#undef TIOCSETN
-#define TIOCSETN TCSETA
-#undef TIOCSETP
-#define TIOCSETP TCSETAF
-#define TERMINAL struct termio
-
-#else /* sgtty */
-
-#include <fcntl.h>
-#include <sgtty.h>
-#include <sys/ioctl.h>
-#define TERMINAL struct sgttyb
-
-#endif /* sgtty */
-#endif
-
-#endif /* ! GDB_TERMIOS_H */
diff --git a/gdb/common/job-control.c b/gdb/common/job-control.c
index d76bc57..78fc672 100644
--- a/gdb/common/job-control.c
+++ b/gdb/common/job-control.c
@@ -20,7 +20,10 @@
 
 #include "common-defs.h"
 #include "job-control.h"
-#include "gdb_termios.h"
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#include <unistd.h>
 
 /* Nonzero if we have job control.  */
 int job_control;
@@ -41,7 +44,6 @@ gdb_setpgid ()
 
   if (job_control)
     {
-#if defined (HAVE_TERMIOS) || defined (TIOCGPGRP)
 #ifdef HAVE_SETPGID
       /* The call setpgid (0, 0) is supposed to work and mean the same
          thing as this, but on Ultrix 4.2A it fails with EPERM (and
@@ -56,7 +58,6 @@ gdb_setpgid ()
 #endif
 #endif /* HAVE_SETPGRP */
 #endif /* HAVE_SETPGID */
-#endif /* defined (HAVE_TERMIOS) || defined (TIOCGPGRP) */
     }
 
   return retval;
@@ -67,9 +68,9 @@ gdb_setpgid ()
 void
 have_job_control ()
 {
-  /* OK, figure out whether we have job control.  If neither termios nor
-     sgtty (i.e. termio or go32), leave job_control 0.  */
-#if defined (HAVE_TERMIOS)
+  /* OK, figure out whether we have job control.  If termios is not
+     available, leave job_control 0.  */
+#if defined (HAVE_TERMIOS_H)
   /* Do all systems with termios have the POSIX way of identifying job
      control?  I hope so.  */
 #ifdef _POSIX_JOB_CONTROL
@@ -81,13 +82,5 @@ have_job_control ()
   job_control = 0;		/* Have to assume the worst.  */
 #endif /* _SC_JOB_CONTROL */
 #endif /* _POSIX_JOB_CONTROL */
-#endif /* HAVE_TERMIOS */
-
-#ifdef HAVE_SGTTY
-#ifdef TIOCGPGRP
-  job_control = 1;
-#else
-  job_control = 0;
-#endif /* TIOCGPGRP */
-#endif /* sgtty */
+#endif /* HAVE_TERMIOS_H */
 }
diff --git a/gdb/configure b/gdb/configure
index 6b445e4..c638652 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11554,8 +11554,7 @@ for ac_header in nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
 		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
-		  termios.h termio.h \
-		  sgtty.h elf_hp.h \
+		  termios.h elf_hp.h \
 		  dlfcn.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 4e64c80..b909217 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1298,8 +1298,7 @@ AC_CHECK_HEADERS([nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
 		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
-		  termios.h termio.h \
-		  sgtty.h elf_hp.h \
+		  termios.h elf_hp.h \
 		  dlfcn.h])
 AC_CHECK_HEADERS(sys/proc.h, [], [],
 [#if HAVE_SYS_PARAM_H
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index abab163..d5c62fb 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -6177,7 +6177,7 @@ $as_echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cach
   cd "$ac_popdir"
 
 
-for ac_header in sgtty.h termio.h termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
+for ac_header in termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 60e235d..456d3b3 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -96,7 +96,7 @@ ACX_CONFIGURE_DIR(["../gnulib"], ["build-gnulib-gdbserver"],
 
 ACX_CONFIGURE_DIR(["../../libiberty"], ["build-libiberty-gdbserver"])
 
-AC_CHECK_HEADERS(sgtty.h termio.h termios.h sys/reg.h string.h dnl
+AC_CHECK_HEADERS(termios.h sys/reg.h string.h dnl
 		 proc_service.h sys/procfs.h linux/elf.h dnl
 		 fcntl.h signal.h sys/file.h dnl
 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 66e06522..54f27f4 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -17,7 +17,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "server.h"
-#include "gdb_termios.h"
+#if HAVE_TERMIOS_H
+#include <termios.h>
+#endif
 #include "target.h"
 #include "gdbthread.h"
 #include "tdesc.h"
@@ -325,7 +327,7 @@ remote_open (const char *name)
       if (remote_desc < 0)
 	perror_with_name ("Could not open remote device");
 
-#ifdef HAVE_TERMIOS
+#if HAVE_TERMIOS_H
       {
 	struct termios termios;
 	tcgetattr (remote_desc, &termios);
@@ -342,33 +344,6 @@ remote_open (const char *name)
       }
 #endif
 
-#ifdef HAVE_TERMIO
-      {
-	struct termio termio;
-	ioctl (remote_desc, TCGETA, &termio);
-
-	termio.c_iflag = 0;
-	termio.c_oflag = 0;
-	termio.c_lflag = 0;
-	termio.c_cflag &= ~(CSIZE | PARENB);
-	termio.c_cflag |= CLOCAL | CS8;
-	termio.c_cc[VMIN] = 1;
-	termio.c_cc[VTIME] = 0;
-
-	ioctl (remote_desc, TCSETA, &termio);
-      }
-#endif
-
-#ifdef HAVE_SGTTY
-      {
-	struct sgttyb sg;
-
-	ioctl (remote_desc, TIOCGETP, &sg);
-	sg.sg_flags = RAW;
-	ioctl (remote_desc, TIOCSETP, &sg);
-      }
-#endif
-
       fprintf (stderr, "Remote debugging using %s\n", name);
 
       enable_async_notification (remote_desc);
diff --git a/gdb/inflow.c b/gdb/inflow.c
index d54b8f8..a96d4fc 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -31,7 +31,9 @@
 
 #include "inflow.h"
 #include "gdbcmd.h"
-#include "gdb_termios.h"
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
 #include "job-control.h"
 
 #ifdef HAVE_SYS_IOCTL_H
@@ -64,9 +66,9 @@ struct terminal_info
      it when it resumes.  */
   serial_ttystate ttystate;
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
   /* Process group.  Saved and restored just like ttystate.  */
-  PROCESS_GROUP_TYPE process_group;
+  pid_t process_group;
 #endif
 
   /* fcntl flags.  Saved and restored just like ttystate.  */
@@ -89,11 +91,11 @@ static serial_ttystate initial_gdb_ttystate;
 
 static struct terminal_info *get_inflow_inferior_data (struct inferior *);
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
 
 /* Return the process group of the current inferior.  */
 
-PROCESS_GROUP_TYPE
+pid_t
 inferior_process_group (void)
 {
   return get_inflow_inferior_data (current_inferior ())->process_group;
@@ -121,25 +123,6 @@ static const char *inferior_thisrun_terminal;
 
 int terminal_is_ours;
 
-#ifdef PROCESS_GROUP_TYPE
-static PROCESS_GROUP_TYPE
-gdb_getpgrp (void)
-{
-  int process_group = -1;
-
-#ifdef HAVE_TERMIOS
-  process_group = tcgetpgrp (0);
-#endif
-#ifdef HAVE_TERMIO
-  process_group = getpgrp ();
-#endif
-#ifdef HAVE_SGTTY
-  ioctl (0, TIOCGPGRP, &process_group);
-#endif
-  return process_group;
-}
-#endif
-
 /* See terminal.h.  */
 
 void
@@ -157,8 +140,8 @@ set_initial_gdb_ttystate (void)
 #ifdef F_GETFL
       our_terminal_info.tflags = fcntl (0, F_GETFL, 0);
 #endif
-#ifdef PROCESS_GROUP_TYPE
-      our_terminal_info.process_group = gdb_getpgrp ();
+#ifdef HAVE_TERMIOS_H
+      our_terminal_info.process_group = tcgetpgrp (0);
 #endif
     }
 }
@@ -187,7 +170,7 @@ child_terminal_init_with_pgrp (int pgrp)
   struct inferior *inf = current_inferior ();
   struct terminal_info *tinfo = get_inflow_inferior_data (inf);
 
-#ifdef PROCESS_GROUP_TYPE
+#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.  */
@@ -224,7 +207,7 @@ gdb_save_tty_state (void)
 void
 child_terminal_init (struct target_ops *self)
 {
-#ifdef PROCESS_GROUP_TYPE
+#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
@@ -232,7 +215,7 @@ child_terminal_init (struct target_ops *self)
      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 /* PROCESS_GROUP_TYPE */
+#endif /* HAVE_TERMIOS_H */
 }
 
 /* Put the inferior's terminal settings into effect.
@@ -269,11 +252,7 @@ child_terminal_inferior (struct target_ops *self)
       OOPSY ("fcntl F_SETFL");
 #endif
 
-      /* Because we were careful to not change in or out of raw mode in
-         terminal_ours, we will not change in our out of raw mode with
-         this call, so we don't flush any input.  */
-      result = serial_set_tty_state (stdin_serial,
-				     tinfo->ttystate);
+      result = serial_set_tty_state (stdin_serial, tinfo->ttystate);
       OOPSY ("setting tty state");
 
       if (!job_control)
@@ -298,19 +277,12 @@ child_terminal_inferior (struct target_ops *self)
 
       if (job_control)
 	{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
 	  result = tcsetpgrp (0, tinfo->process_group);
 	  if (!inf->attach_flag)
 	    OOPSY ("tcsetpgrp");
 #endif
-
-#ifdef HAVE_SGTTY
-	  result = ioctl (0, TIOCSPGRP, &tinfo->process_group);
-	  if (!inf->attach_flag)
-	    OOPSY ("TIOCSPGRP");
-#endif
 	}
-
     }
   terminal_is_ours = 0;
 }
@@ -388,34 +360,20 @@ child_terminal_ours_1 (int output_only)
       xfree (tinfo->ttystate);
       tinfo->ttystate = serial_get_tty_state (stdin_serial);
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
       if (!inf->attach_flag)
-	/* If setpgrp failed in terminal_inferior, this would give us
+	/* If tcsetpgrp failed in terminal_inferior, this would give us
 	   our process group instead of the inferior's.  See
 	   terminal_inferior for details.  */
-	tinfo->process_group = gdb_getpgrp ();
+	tinfo->process_group = tcgetpgrp (0);
 #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.
-         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
-         regardless of output_only, because we don't have separate
-         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_terminal_info.ttystate,
-				    tinfo->ttystate);
+      /* Set tty state to our_ttystate.  */
+      serial_set_tty_state (stdin_serial, our_terminal_info.ttystate);
 
       if (job_control)
 	{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
 	  result = tcsetpgrp (0, our_terminal_info.process_group);
 #if 0
 	  /* This fails on Ultrix with EINVAL if you run the testsuite
@@ -428,10 +386,6 @@ child_terminal_ours_1 (int output_only)
 				safe_strerror (errno));
 #endif
 #endif /* termios */
-
-#ifdef HAVE_SGTTY
-	  result = ioctl (0, TIOCSPGRP, &our_terminal_info.process_group);
-#endif
 	}
 
 #ifdef SIGTTOU
@@ -616,7 +570,7 @@ child_terminal_info (struct target_ops *self, const char *args, int from_tty)
     printf_filtered ("\n");
   }
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
   printf_filtered ("Process group = %d\n", (int) tinfo->process_group);
 #endif
 
diff --git a/gdb/inflow.h b/gdb/inflow.h
index 428aed4..0b00c61 100644
--- a/gdb/inflow.h
+++ b/gdb/inflow.h
@@ -20,17 +20,11 @@
 #ifndef INFLOW_H
 #define INFLOW_H
 
-#include "gdb_termios.h"
+#include <unistd.h>
 
-#ifdef HAVE_TERMIOS
-# define PROCESS_GROUP_TYPE pid_t
-#elif defined (HAVE_TERMIO) || defined (HAVE_SGTTY)
-# define PROCESS_GROUP_TYPE int
-#endif
-
-#ifdef PROCESS_GROUP_TYPE
 /* Process group of the current inferior.  */
-extern PROCESS_GROUP_TYPE inferior_process_group (void);
+#ifdef HAVE_TERMIOS_H
+extern pid_t inferior_process_group (void);
 #endif
 
 #endif /* inflow.h */
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 2bfe82b..3262dcc 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -551,14 +551,6 @@ ser_base_set_tty_state (struct serial *scb, serial_ttystate ttystate)
   return 0;
 }
 
-int
-ser_base_noflush_set_tty_state (struct serial *scb,
-				serial_ttystate new_ttystate,
-				serial_ttystate old_ttystate)
-{
-  return 0;
-}
-
 void
 ser_base_print_tty_state (struct serial *scb, 
 			  serial_ttystate ttystate,
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 964d640..ceeb7de 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -40,9 +40,6 @@ extern int ser_base_set_tty_state (struct serial *scb,
 extern void ser_base_print_tty_state (struct serial *scb,
 				      serial_ttystate ttystate,
 				      struct ui_file *stream);
-extern int ser_base_noflush_set_tty_state (struct serial *scb,
-					   serial_ttystate new_ttystate,
-					   serial_ttystate old_ttystate);
 extern int ser_base_setbaudrate (struct serial *scb, int rate);
 extern int ser_base_setstopbits (struct serial *scb, int num);
 extern int ser_base_setparity (struct serial *scb, int parity);
diff --git a/gdb/ser-event.c b/gdb/ser-event.c
index 08b56a3..8b88ca0 100644
--- a/gdb/ser-event.c
+++ b/gdb/ser-event.c
@@ -144,7 +144,6 @@ static const struct serial_ops serial_event_ops =
   NULL, /* copy_tty_state */
   NULL, /* set_tty_state */
   NULL, /* print_tty_state */
-  NULL, /* noflush_set_tty_state */
   NULL, /* setbaudrate */
   NULL, /* setstopbits */
   NULL, /* setparity */
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index e352895..6965f19 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -689,17 +689,6 @@ dos_set_tty_state (struct serial *scb, serial_ttystate ttystate)
 }
 
 static int
-dos_noflush_set_tty_state (struct serial *scb, serial_ttystate new_ttystate,
-			   serial_ttystate old_ttystate)
-{
-  struct dos_ttystate *state;
-
-  state = (struct dos_ttystate *) new_ttystate;
-  dos_setbaudrate (scb, state->baudrate);
-  return 0;
-}
-
-static int
 dos_flush_input (struct serial *scb)
 {
   struct dos_ttystate *port = &ports[scb->fd];
@@ -882,7 +871,6 @@ static const struct serial_ops dos_ops =
   dos_copy_tty_state,
   dos_set_tty_state,
   dos_print_tty_state,
-  dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
   dos_setparity,
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 33e4df3..2359a495 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -1248,7 +1248,6 @@ static const struct serial_ops hardwire_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
   ser_windows_setparity,
@@ -1279,7 +1278,6 @@ static const struct serial_ops tty_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   NULL,
   NULL,
   NULL,
@@ -1310,7 +1308,6 @@ static const struct serial_ops pipe_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
@@ -1341,7 +1338,6 @@ static const struct serial_ops tcp_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index cb94242..56a91fc 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -219,7 +219,6 @@ static const struct serial_ops pipe_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 7ff588b..cc6de30 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -399,7 +399,6 @@ static const struct serial_ops tcp_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 53c33e6..3cbb77f 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -31,9 +31,7 @@
 #include "gdb_select.h"
 #include "gdbcmd.h"
 #include "filestuff.h"
-#include "gdb_termios.h"
-
-#ifdef HAVE_TERMIOS
+#include <termios.h>
 
 struct hardwire_ttystate
   {
@@ -51,32 +49,6 @@ show_serial_hwflow (struct ui_file *file, int from_tty,
 }
 #endif
 
-#endif /* termios */
-
-#ifdef HAVE_TERMIO
-
-/* It is believed that all systems which have added job control to SVR3
-   (e.g. sco) have also added termios.  Even if not, trying to figure out
-   all the variations (TIOCGPGRP vs. TCGETPGRP, etc.) would be pretty
-   bewildering.  So we don't attempt it.  */
-
-struct hardwire_ttystate
-  {
-    struct termio termio;
-  };
-#endif /* termio */
-
-#ifdef HAVE_SGTTY
-struct hardwire_ttystate
-  {
-    struct sgttyb sgttyb;
-    struct tchars tc;
-    struct ltchars ltc;
-    /* Line discipline flags.  */
-    int lmode;
-  };
-#endif /* sgtty */
-
 static int hardwire_open (struct serial *scb, const char *name);
 static void hardwire_raw (struct serial *scb);
 static int rate_to_code (int rate);
@@ -89,8 +61,6 @@ static int set_tty_state (struct serial *scb,
 			  struct hardwire_ttystate * state);
 static serial_ttystate hardwire_get_tty_state (struct serial *scb);
 static int hardwire_set_tty_state (struct serial *scb, serial_ttystate state);
-static int hardwire_noflush_set_tty_state (struct serial *, serial_ttystate,
-					   serial_ttystate);
 static void hardwire_print_tty_state (struct serial *, serial_ttystate,
 				      struct ui_file *);
 static int hardwire_drain_output (struct serial *);
@@ -114,61 +84,19 @@ hardwire_open (struct serial *scb, const char *name)
 static int
 get_tty_state (struct serial *scb, struct hardwire_ttystate *state)
 {
-#ifdef HAVE_TERMIOS
   if (tcgetattr (scb->fd, &state->termios) < 0)
     return -1;
 
   return 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
-    return -1;
-  return 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  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;
-
-  return 0;
-#endif
 }
 
 static int
 set_tty_state (struct serial *scb, struct hardwire_ttystate *state)
 {
-#ifdef HAVE_TERMIOS
   if (tcsetattr (scb->fd, TCSANOW, &state->termios) < 0)
     return -1;
 
   return 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
-    return -1;
-  return 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCSETC, &state->tc) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCSLTC, &state->ltc) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCLSET, &state->lmode) < 0)
-    return -1;
-
-  return 0;
-#endif
 }
 
 static serial_ttystate
@@ -205,39 +133,6 @@ hardwire_set_tty_state (struct serial *scb, serial_ttystate ttystate)
   return set_tty_state (scb, state);
 }
 
-static int
-hardwire_noflush_set_tty_state (struct serial *scb,
-				serial_ttystate new_ttystate,
-				serial_ttystate old_ttystate)
-{
-  struct hardwire_ttystate new_state;
-#ifdef HAVE_SGTTY
-  struct hardwire_ttystate *state = (struct hardwire_ttystate *) old_ttystate;
-#endif
-
-  new_state = *(struct hardwire_ttystate *) new_ttystate;
-
-  /* Don't change in or out of raw mode; we don't want to flush input.
-     termio and termios have no such restriction; for them flushing input
-     is separate from setting the attributes.  */
-
-#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 (struct serial *scb,
 			  serial_ttystate ttystate,
@@ -246,7 +141,6 @@ hardwire_print_tty_state (struct serial *scb,
   struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
   int i;
 
-#ifdef HAVE_TERMIOS
   fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
 		    (int) state->termios.c_iflag,
 		    (int) state->termios.c_oflag);
@@ -262,36 +156,6 @@ hardwire_print_tty_state (struct serial *scb,
   for (i = 0; i < NCCS; i += 1)
     fprintf_filtered (stream, "0x%x ", state->termios.c_cc[i]);
   fprintf_filtered (stream, "\n");
-#endif
-
-#ifdef HAVE_TERMIO
-  fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
-		    state->termio.c_iflag, state->termio.c_oflag);
-  fprintf_filtered (stream, "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);
-  fprintf_filtered (stream, "c_cc: ");
-  for (i = 0; i < NCC; i += 1)
-    fprintf_filtered (stream, "0x%x ", state->termio.c_cc[i]);
-  fprintf_filtered (stream, "\n");
-#endif
-
-#ifdef HAVE_SGTTY
-  fprintf_filtered (stream, "sgttyb.sg_flags = 0x%x.\n",
-		    state->sgttyb.sg_flags);
-
-  fprintf_filtered (stream, "tchars: ");
-  for (i = 0; i < (int) sizeof (struct tchars); i++)
-    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->tc)[i]);
-  fprintf_filtered (stream, "\n");
-
-  fprintf_filtered (stream, "ltchars: ");
-  for (i = 0; i < (int) sizeof (struct ltchars); i++)
-    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->ltc)[i]);
-  fprintf_filtered (stream, "\n");
-
-  fprintf_filtered (stream, "lmode:  0x%x\n", state->lmode);
-#endif
 }
 
 /* Wait for the output to drain away, as opposed to flushing
@@ -300,48 +164,13 @@ hardwire_print_tty_state (struct serial *scb,
 static int
 hardwire_drain_output (struct serial *scb)
 {
-#ifdef HAVE_TERMIOS
   return tcdrain (scb->fd);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCSBRK, 1);
-#endif
-
-#ifdef HAVE_SGTTY
-  /* Get the current state and then restore it using TIOCSETP,
-     which should cause the output to drain and pending input
-     to be discarded.  */
-  {
-    struct hardwire_ttystate state;
-
-    if (get_tty_state (scb, &state))
-      {
-	return (-1);
-      }
-    else
-      {
-	return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
-      }
-  }
-#endif
 }
 
 static int
 hardwire_flush_output (struct serial *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 int
@@ -349,45 +178,13 @@ hardwire_flush_input (struct serial *scb)
 {
   ser_base_flush_input (scb);
 
-#ifdef HAVE_TERMIOS
   return tcflush (scb->fd, TCIFLUSH);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCFLSH, 0);
-#endif
-
-#ifdef HAVE_SGTTY
-  /* This flushes both input and output, but we can't do better.  */
-  return ioctl (scb->fd, TIOCFLUSH, 0);
-#endif
 }
 
 static int
 hardwire_send_break (struct serial *scb)
 {
-#ifdef HAVE_TERMIOS
   return tcsendbreak (scb->fd, 0);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCSBRK, 0);
-#endif
-
-#ifdef HAVE_SGTTY
-  {
-    int status;
-
-    status = ioctl (scb->fd, TIOCSBRK, 0);
-
-    /* Can't use usleep; it doesn't exist in BSD 4.2.  */
-    /* Note that if this gdb_select() is interrupted by a signal it will not
-       wait the full length of time.  I think that is OK.  */
-    gdb_usleep (250000);
-    status = ioctl (scb->fd, TIOCCBRK, 0);
-    return status;
-  }
-#endif
 }
 
 static void
@@ -399,7 +196,6 @@ hardwire_raw (struct serial *scb)
     fprintf_unfiltered (gdb_stderr, "get_tty_state failed: %s\n",
 			safe_strerror (errno));
 
-#ifdef HAVE_TERMIOS
   state.termios.c_iflag = 0;
   state.termios.c_oflag = 0;
   state.termios.c_lflag = 0;
@@ -420,22 +216,6 @@ hardwire_raw (struct serial *scb)
 #endif
   state.termios.c_cc[VMIN] = 0;
   state.termios.c_cc[VTIME] = 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  state.termio.c_iflag = 0;
-  state.termio.c_oflag = 0;
-  state.termio.c_lflag = 0;
-  state.termio.c_cflag &= ~CSIZE;
-  state.termio.c_cflag |= CLOCAL | CS8;
-  state.termio.c_cc[VMIN] = 0;
-  state.termio.c_cc[VTIME] = 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  state.sgttyb.sg_flags |= RAW | ANYP;
-  state.sgttyb.sg_flags &= ~(CBREAK | ECHO);
-#endif
 
   if (set_tty_state (scb, &state))
     fprintf_unfiltered (gdb_stderr, "set_tty_state failed: %s\n",
@@ -604,24 +384,8 @@ hardwire_setbaudrate (struct serial *scb, int rate)
   if (get_tty_state (scb, &state))
     return -1;
 
-#ifdef HAVE_TERMIOS
   cfsetospeed (&state.termios, baud_code);
   cfsetispeed (&state.termios, baud_code);
-#endif
-
-#ifdef HAVE_TERMIO
-#ifndef CIBAUD
-#define CIBAUD CBAUD
-#endif
-
-  state.termio.c_cflag &= ~(CBAUD | CIBAUD);
-  state.termio.c_cflag |= baud_code;
-#endif
-
-#ifdef HAVE_SGTTY
-  state.sgttyb.sg_ispeed = baud_code;
-  state.sgttyb.sg_ospeed = baud_code;
-#endif
 
   return set_tty_state (scb, &state);
 }
@@ -648,23 +412,10 @@ hardwire_setstopbits (struct serial *scb, int num)
       return 1;
     }
 
-#ifdef HAVE_TERMIOS
   if (!newbit)
     state.termios.c_cflag &= ~CSTOPB;
   else
     state.termios.c_cflag |= CSTOPB;	/* two bits */
-#endif
-
-#ifdef HAVE_TERMIO
-  if (!newbit)
-    state.termio.c_cflag &= ~CSTOPB;
-  else
-    state.termio.c_cflag |= CSTOPB;	/* two bits */
-#endif
-
-#ifdef HAVE_SGTTY
-  return 0;			/* sgtty doesn't support this */
-#endif
 
   return set_tty_state (scb, &state);
 }
@@ -697,19 +448,9 @@ hardwire_setparity (struct serial *scb, int parity)
       return -1;
     }
 
-#ifdef HAVE_TERMIOS
   state.termios.c_cflag &= ~(PARENB | PARODD);
   state.termios.c_cflag |= newparity;
-#endif
 
-#ifdef HAVE_TERMIO
-  state.termio.c_cflag &= ~(PARENB | PARODD);
-  state.termio.c_cflag |= newparity;
-#endif
-
-#ifdef HAVE_SGTTY
-  return 0;            /* sgtty doesn't support this */
-#endif
   return set_tty_state (scb, &state);
 }
 
@@ -744,7 +485,6 @@ static const struct serial_ops hardwire_ops =
   hardwire_copy_tty_state,
   hardwire_set_tty_state,
   hardwire_print_tty_state,
-  hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
   hardwire_setparity,
@@ -759,7 +499,6 @@ _initialize_ser_hardwire (void)
 {
   serial_add_interface (&hardwire_ops);
 
-#ifdef HAVE_TERMIOS
 #ifdef CRTSCTS
   add_setshow_boolean_cmd ("remoteflow", no_class,
 			   &serial_hwflow, _("\
@@ -771,7 +510,6 @@ when debugging using remote targets."),
 			   show_serial_hwflow,
 			   &setlist, &showlist);
 #endif
-#endif
 }
 
 int
diff --git a/gdb/serial.c b/gdb/serial.c
index 6866549..32d4f5a 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -514,14 +514,6 @@ serial_print_tty_state (struct serial *scb,
 }
 
 int
-serial_noflush_set_tty_state (struct serial *scb,
-			      serial_ttystate new_ttystate,
-			      serial_ttystate old_ttystate)
-{
-  return scb->ops->noflush_set_tty_state (scb, new_ttystate, old_ttystate);
-}
-
-int
 serial_setbaudrate (struct serial *scb, int rate)
 {
   return scb->ops->setbaudrate (scb, rate);
diff --git a/gdb/serial.h b/gdb/serial.h
index c76ddbe..647eab3 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -169,16 +169,6 @@ extern void serial_print_tty_state (struct serial *scb,
 				    serial_ttystate ttystate,
 				    struct ui_file *);
 
-/* 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.  */
-
-extern int serial_noflush_set_tty_state (struct serial *scb,
-					 serial_ttystate new_ttystate,
-					 serial_ttystate old_ttystate);
-
 /* Set the baudrate to the decimal value supplied.  Returns 0 for
    success, -1 for failure.  */
 
@@ -276,8 +266,6 @@ struct serial_ops
     int (*set_tty_state) (struct serial *, serial_ttystate);
     void (*print_tty_state) (struct serial *, serial_ttystate,
 			     struct ui_file *);
-    int (*noflush_set_tty_state) (struct serial *, serial_ttystate,
-				  serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
     /* Set the value PARITY as parity setting for serial object.
-- 
2.5.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] Don't set terminal flags twice in a row
  2017-11-02 15:12 ` [PATCH 2/3] Don't set terminal flags twice in a row Pedro Alves
@ 2017-11-02 18:34   ` Sergio Durigan Junior
  0 siblings, 0 replies; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-02 18:34 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thursday, November 02 2017, Pedro Alves wrote:

> I find this odd 'set flags twice' ancient code and comment annoyingly
> distracting.  It may well be that the reason for the double-set was
> simply a copy/paste mistake, and that we've been doing this for
> decades [1] for no good reason.  Let's just get rid of it, and if we
> find a real reason, add it back with a comment explaining why it's
> necessary.
>
> [1] This double-set was already in gdb 2.4 / 1988, the oldest release
> we have sources for, and imported in git.  From 'git show 7b4ac7e1ed2c
> inflow.c':
>
>    +void
>    +terminal_inferior ()
>    +{
>    +  if (terminal_is_ours)   /*  && inferior_thisrun_terminal == 0) */
>    +    {
>    +      fcntl (0, F_SETFL, tflags_inferior);
>    +      fcntl (0, F_SETFL, tflags_inferior);
>
> The "is there a reason" comment was added in 1993, by:
>
>   commit a88797b5eadf31e21804bc820429028bf708fbcd
>   Author:     Fred Fish <fnf@specifix.com>
>   AuthorDate: Thu Aug 5 01:33:45 1993 +0000

FWIW, I've stumbled upon this part while doing the startup-with-shell
work, and it also intrigued me.  Anyway, I agree that we should remove
this double-set.  Thanks for doing that.

>
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
> 	* inflow.c (child_terminal_inferior, child_terminal_ours_1): No
> 	longer set flags twice in row.
> ---
>  gdb/inflow.c | 9 ---------
>  1 file changed, 9 deletions(-)
>
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index a96d4fc..d46d693 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -244,10 +244,6 @@ child_terminal_inferior (struct target_ops *self)
>        int result;
>  
>  #ifdef F_GETFL
> -      /* Is there a reason this is being done twice?  It happens both
> -         places we use F_SETFL, so I'm inclined to think perhaps there
> -         is some reason, however perverse.  Perhaps not though...  */
> -      result = fcntl (0, F_SETFL, tinfo->tflags);
>        result = fcntl (0, F_SETFL, tinfo->tflags);
>        OOPSY ("fcntl F_SETFL");
>  #endif
> @@ -403,11 +399,6 @@ child_terminal_ours_1 (int output_only)
>  
>  #ifdef F_GETFL
>        tinfo->tflags = fcntl (0, F_GETFL, 0);
> -
> -      /* Is there a reason this is being done twice?  It happens both
> -         places we use F_SETFL, so I'm inclined to think perhaps there
> -         is some reason, however perverse.  Perhaps not though...  */
> -      result = fcntl (0, F_SETFL, our_terminal_info.tflags);
>        result = fcntl (0, F_SETFL, our_terminal_info.tflags);
>  #endif
>      }
> -- 
> 2.5.5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty
  2017-11-02 15:12 ` [PATCH 1/3] Assume termios is available, remove support for termio and sgtty Pedro Alves
@ 2017-11-02 18:54   ` Sergio Durigan Junior
  2017-11-02 19:27     ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-02 18:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thursday, November 02 2017, Pedro Alves wrote:

> This commit garbage collects the termio and sgtty support.
>
> GDB's terminal handling code still has support for the old termio and
> sgtty interfaces in addition to termios.  However, I think it's pretty
> safe to assume that for a long, long time, Unix-like systems provide
> termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
> all have had termios.h for many years.  Looking around the web, I
> found discussions about FreeBSD folks trying to get rid of old sgtty.h
> a decade ago:
>
>   https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html
>
> So I think support for termio and sgtty in GDB is just dead code that
> is never compiled anywhere and is just getting in the way.  For
> example, serial_noflush_set_tty_state and the raw<->cooked concerns
> mentioned in inflow.c only exist because of sgtty (see
> hardwire_noflush_set_tty_state).
>
> Regtested on GNU/Linux.
>
> Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
> that GDB still includes the termios.h-guarded code.  Confirmed

"that that"

> mingw-w64 GDB still builds and skips the termios.h-guarded code.

Thanks for doing that.

You may remember that I also stumbled upon this while doing the
startup-with-shell, but I didn't have the necessary background knowledge
to do a deep cleanup.  It's always nice to see old code being removed.

> gdb/ChangeLog:
> yyyy-mm-ddd  Pedro Alves  <palves@redhat.com>
>
> 	* Makefile.in (SER_HARDWIRE): Update comment.
> 	* common/gdb_termios.h: Delete file.
> 	* common/job-control.c: Include termios.h and unistd.h instead of
> 	gdb_termios.h.
> 	(gdb_setpgid): Remove HAVE_TERMIOS || TIOCGPGRP preprocessor
> 	check.
> 	(have_job_control): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
> 	Remove sgtty code.
> 	* configure.ac: No longer check for termio.h and sgtty.h.
> 	* configure: Regenerate.
> 	* inflow.c: Include termios.h instead of gdb_termios.h.  Replace
> 	PROCESS_GROUP_TYPE checks with HAVE_TERMIOS_H checks throughout.
> 	Replace PROCESS_GROUP_TYPE references with pid_t references
> 	throughout.
> 	(gdb_getpgrp): Delete.
> 	(set_initial_gdb_ttystate): Use tcgetpgrp instead of gdb_getpgrp.
> 	(child_terminal_inferior): Remove comment.  Remove sgtty code.
> 	(child_terminal_ours_1): Use tcgetpgrp directly instead of
> 	gdb_getpgrp.  Use serial_set_tty_state instead aof
> 	serial_noflush_set_tty_state.  Remove sgtty code.
> 	* inflow.h: Include unistd.h instead of gdb_termios.h.  Replace
> 	PROCESS_GROUP_TYPE check with HAVE_TERMIOS_H check.
> 	(inferior_process_group): Now returns pid_t.
> 	* ser-base.c (ser_base_noflush_set_tty_state): Delete.
> 	* ser-base.h (ser_base_noflush_set_tty_state): Delete.
> 	* ser-event.c (serial_event_ops): Update.
> 	* ser-go32.c (dos_noflush_set_tty_state): Delete.
> 	(dos_ops): Update.
> 	* ser-mingw.c (hardwire_ops, tty_ops, pipe_ops, tcp_ops): Update.
> 	* ser-pipe.c (pipe_ops): Update.
> 	* ser-tcp.c (tcp_ops): Update.
> 	* ser-unix.c: Include termios.h instead of gdb_termios.h.  Remove
> 	HAVE_TERMIOS checks.
> 	[HAVE_TERMIO] (struct hardwire_ttystate): Delete.
> 	[HAVE_SGTTY] (struct hardwire_ttystate): Delete.
> 	(get_tty_state, set_tty_state): Drop termio and sgtty code, and
> 	assume termios.
> 	(hardwire_noflush_set_tty_state): Delete.
> 	(hardwire_print_tty_state, hardwire_drain_output)
> 	(hardwire_flush_output, hardwire_flush_input)
> 	(hardwire_send_break, hardwire_raw, hardwire_setbaudrate)
> 	(hardwire_setstopbits, hardwire_setparity): Drop termio and sgtty
> 	code, and assume termios.
> 	(hardwire_ops): Update.
> 	(_initialize_ser_hardwire): Remove HAVE_TERMIOS check.
> 	* serial.c (serial_noflush_set_tty_state): Delete.
> 	* serial.h (serial_noflush_set_tty_state): Delete.
> 	(serial_ops::noflush_set_tty_state): Delete.
>
> gdb/gdbserver/ChangeLog:
> yyyy-mm-ddd  Pedro Alves  <palves@redhat.com>
>
> 	* configure.ac: No longer check for termio.h and sgtty.h.
> 	* configure: Regenerate.
> 	* remote-utils.c: Include termios.h instead of gdb_termios.h.
> 	(remote_open): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
> 	Remove termio and sgtty code.
> ---
>  gdb/Makefile.in              |   9 +-
>  gdb/common/gdb_termios.h     |  78 -------------
>  gdb/common/job-control.c     |  23 ++--
>  gdb/configure                |   3 +-
>  gdb/configure.ac             |   3 +-
>  gdb/gdbserver/configure      |   2 +-
>  gdb/gdbserver/configure.ac   |   2 +-
>  gdb/gdbserver/remote-utils.c |  33 +-----
>  gdb/inflow.c                 |  88 ++++-----------
>  gdb/inflow.h                 |  12 +-
>  gdb/ser-base.c               |   8 --
>  gdb/ser-base.h               |   3 -
>  gdb/ser-event.c              |   1 -
>  gdb/ser-go32.c               |  12 --
>  gdb/ser-mingw.c              |   4 -
>  gdb/ser-pipe.c               |   1 -
>  gdb/ser-tcp.c                |   1 -
>  gdb/ser-unix.c               | 264 +------------------------------------------
>  gdb/serial.c                 |   8 --
>  gdb/serial.h                 |  12 --
>  20 files changed, 44 insertions(+), 523 deletions(-)
>  delete mode 100644 gdb/common/gdb_termios.h
>
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index 6cb0970..c2f6482 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -729,12 +729,9 @@ XMLFILES = \
>  	$(srcdir)/features/traceframe-info.dtd \
>  	$(srcdir)/features/xinclude.dtd
>  
> -# This is ser-unix.o for any system which supports a v7/BSD/SYSV/POSIX
> -# interface to the serial port.  Hopefully if get ported to OS/2, VMS,
> -# etc., then there will be (as part of the C library or perhaps as
> -# part of libiberty) a POSIX interface.  But at least for now the
> -# host-dependent makefile fragment might need to use something else
> -# besides ser-unix.o
> +# This is ser-unix.o for any system which supports a POSIX interface
> +# to the serial port.  The host-dependent makefile fragment might need
> +# to use something else besides ser-unix.o.
>  SER_HARDWIRE = @SER_HARDWIRE@
>  
>  # The `remote' debugging target is supported for most architectures,

You also need to remove common/gdb_termios.h from HFILES_NO_SRCDIR here.

> diff --git a/gdb/common/gdb_termios.h b/gdb/common/gdb_termios.h
> deleted file mode 100644
> index 1d0544d..0000000
> --- a/gdb/common/gdb_termios.h
> +++ /dev/null
> @@ -1,78 +0,0 @@
> -/* Common terminal interface definitions for GDB and gdbserver.
> -   Copyright (C) 1986-2017 Free Software Foundation, Inc.
> -
> -   This file is part of GDB.
> -
> -   This program is free software; you can redistribute it and/or modify
> -   it under the terms of the GNU General Public License as published by
> -   the Free Software Foundation; either version 3 of the License, or
> -   (at your option) any later version.
> -
> -   This program is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -   GNU General Public License for more details.
> -
> -   You should have received a copy of the GNU General Public License
> -   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> -
> -#ifndef GDB_TERMIOS_H
> -#define GDB_TERMIOS_H
> -
> -/* If we're using autoconf, it will define HAVE_TERMIOS_H,
> -   HAVE_TERMIO_H and HAVE_SGTTY_H for us.  One day we can rewrite
> -   ser-unix.c and inflow.c to inspect those names instead of
> -   HAVE_TERMIOS, HAVE_TERMIO and the implicit HAVE_SGTTY (when neither
> -   HAVE_TERMIOS or HAVE_TERMIO is set).  Until then, make sure that
> -   nothing has already defined the one of the names, and do the right
> -   thing.  */
> -
> -#if !defined (HAVE_TERMIOS) && !defined(HAVE_TERMIO) && !defined(HAVE_SGTTY)
> -#if defined(HAVE_TERMIOS_H)
> -#define HAVE_TERMIOS
> -#else /* ! defined (HAVE_TERMIOS_H) */
> -#if defined(HAVE_TERMIO_H)
> -#define HAVE_TERMIO
> -#else /* ! defined (HAVE_TERMIO_H) */
> -#if defined(HAVE_SGTTY_H)
> -#define HAVE_SGTTY
> -#endif /* ! defined (HAVE_SGTTY_H) */
> -#endif /* ! defined (HAVE_TERMIO_H) */
> -#endif /* ! defined (HAVE_TERMIOS_H) */
> -#endif /* !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) &&
> -	  !defined (HAVE_SGTTY) */
> -
> -#if defined(HAVE_TERMIOS)
> -#include <termios.h>
> -#endif
> -
> -#if !defined(_WIN32) && !defined (HAVE_TERMIOS)
> -
> -/* Define a common set of macros -- BSD based -- and redefine whatever
> -   the system offers to make it look like that.  FIXME: serial.h and
> -   ser-*.c deal with this in a much cleaner fashion; as soon as stuff
> -   is converted to use them, can get rid of this crap.  */
> -
> -#ifdef HAVE_TERMIO
> -
> -#include <termio.h>
> -
> -#undef TIOCGETP
> -#define TIOCGETP TCGETA
> -#undef TIOCSETN
> -#define TIOCSETN TCSETA
> -#undef TIOCSETP
> -#define TIOCSETP TCSETAF
> -#define TERMINAL struct termio
> -
> -#else /* sgtty */
> -
> -#include <fcntl.h>
> -#include <sgtty.h>
> -#include <sys/ioctl.h>
> -#define TERMINAL struct sgttyb
> -
> -#endif /* sgtty */
> -#endif
> -
> -#endif /* ! GDB_TERMIOS_H */
> diff --git a/gdb/common/job-control.c b/gdb/common/job-control.c
> index d76bc57..78fc672 100644
> --- a/gdb/common/job-control.c
> +++ b/gdb/common/job-control.c
> @@ -20,7 +20,10 @@
>  
>  #include "common-defs.h"
>  #include "job-control.h"
> -#include "gdb_termios.h"
> +#ifdef HAVE_TERMIOS_H
> +#include <termios.h>
> +#endif
> +#include <unistd.h>
>  
>  /* Nonzero if we have job control.  */
>  int job_control;
> @@ -41,7 +44,6 @@ gdb_setpgid ()
>  
>    if (job_control)
>      {
> -#if defined (HAVE_TERMIOS) || defined (TIOCGPGRP)
>  #ifdef HAVE_SETPGID
>        /* The call setpgid (0, 0) is supposed to work and mean the same
>           thing as this, but on Ultrix 4.2A it fails with EPERM (and
> @@ -56,7 +58,6 @@ gdb_setpgid ()
>  #endif
>  #endif /* HAVE_SETPGRP */
>  #endif /* HAVE_SETPGID */
> -#endif /* defined (HAVE_TERMIOS) || defined (TIOCGPGRP) */

Did you decide to remove the check for HAVE_TERMIOS (instead of
replacing it with an "#ifdef HAVE_TERMIOS_H") because we're already
checking for HAVE_SETPGID?

>      }
>  
>    return retval;
> @@ -67,9 +68,9 @@ gdb_setpgid ()
>  void
>  have_job_control ()
>  {
> -  /* OK, figure out whether we have job control.  If neither termios nor
> -     sgtty (i.e. termio or go32), leave job_control 0.  */
> -#if defined (HAVE_TERMIOS)
> +  /* OK, figure out whether we have job control.  If termios is not
> +     available, leave job_control 0.  */
> +#if defined (HAVE_TERMIOS_H)
>    /* Do all systems with termios have the POSIX way of identifying job
>       control?  I hope so.  */
>  #ifdef _POSIX_JOB_CONTROL
> @@ -81,13 +82,5 @@ have_job_control ()
>    job_control = 0;		/* Have to assume the worst.  */
>  #endif /* _SC_JOB_CONTROL */
>  #endif /* _POSIX_JOB_CONTROL */
> -#endif /* HAVE_TERMIOS */
> -
> -#ifdef HAVE_SGTTY
> -#ifdef TIOCGPGRP
> -  job_control = 1;
> -#else
> -  job_control = 0;
> -#endif /* TIOCGPGRP */
> -#endif /* sgtty */
> +#endif /* HAVE_TERMIOS_H */
>  }
> diff --git a/gdb/configure b/gdb/configure
> index 6b445e4..c638652 100755
> --- a/gdb/configure
> +++ b/gdb/configure
> @@ -11554,8 +11554,7 @@ for ac_header in nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
>  		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
>  		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
>  		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
> -		  termios.h termio.h \
> -		  sgtty.h elf_hp.h \
> +		  termios.h elf_hp.h \
>  		  dlfcn.h
>  do :
>    as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index 4e64c80..b909217 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -1298,8 +1298,7 @@ AC_CHECK_HEADERS([nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
>  		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
>  		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
>  		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
> -		  termios.h termio.h \
> -		  sgtty.h elf_hp.h \
> +		  termios.h elf_hp.h \
>  		  dlfcn.h])
>  AC_CHECK_HEADERS(sys/proc.h, [], [],
>  [#if HAVE_SYS_PARAM_H
> diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
> index abab163..d5c62fb 100755
> --- a/gdb/gdbserver/configure
> +++ b/gdb/gdbserver/configure
> @@ -6177,7 +6177,7 @@ $as_echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cach
>    cd "$ac_popdir"
>  
>  
> -for ac_header in sgtty.h termio.h termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
> +for ac_header in termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
>  do :
>    as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
>  ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
> diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
> index 60e235d..456d3b3 100644
> --- a/gdb/gdbserver/configure.ac
> +++ b/gdb/gdbserver/configure.ac
> @@ -96,7 +96,7 @@ ACX_CONFIGURE_DIR(["../gnulib"], ["build-gnulib-gdbserver"],
>  
>  ACX_CONFIGURE_DIR(["../../libiberty"], ["build-libiberty-gdbserver"])
>  
> -AC_CHECK_HEADERS(sgtty.h termio.h termios.h sys/reg.h string.h dnl
> +AC_CHECK_HEADERS(termios.h sys/reg.h string.h dnl
>  		 proc_service.h sys/procfs.h linux/elf.h dnl
>  		 fcntl.h signal.h sys/file.h dnl
>  		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
> diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
> index 66e06522..54f27f4 100644
> --- a/gdb/gdbserver/remote-utils.c
> +++ b/gdb/gdbserver/remote-utils.c
> @@ -17,7 +17,9 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>  
>  #include "server.h"
> -#include "gdb_termios.h"
> +#if HAVE_TERMIOS_H
> +#include <termios.h>
> +#endif
>  #include "target.h"
>  #include "gdbthread.h"
>  #include "tdesc.h"
> @@ -325,7 +327,7 @@ remote_open (const char *name)
>        if (remote_desc < 0)
>  	perror_with_name ("Could not open remote device");
>  
> -#ifdef HAVE_TERMIOS
> +#if HAVE_TERMIOS_H

Why s/#ifdef/#if/?  I prefer #ifdef BTW.

>        {
>  	struct termios termios;
>  	tcgetattr (remote_desc, &termios);
> @@ -342,33 +344,6 @@ remote_open (const char *name)
>        }
>  #endif
>  
> -#ifdef HAVE_TERMIO
> -      {
> -	struct termio termio;
> -	ioctl (remote_desc, TCGETA, &termio);
> -
> -	termio.c_iflag = 0;
> -	termio.c_oflag = 0;
> -	termio.c_lflag = 0;
> -	termio.c_cflag &= ~(CSIZE | PARENB);
> -	termio.c_cflag |= CLOCAL | CS8;
> -	termio.c_cc[VMIN] = 1;
> -	termio.c_cc[VTIME] = 0;
> -
> -	ioctl (remote_desc, TCSETA, &termio);
> -      }
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -      {
> -	struct sgttyb sg;
> -
> -	ioctl (remote_desc, TIOCGETP, &sg);
> -	sg.sg_flags = RAW;
> -	ioctl (remote_desc, TIOCSETP, &sg);
> -      }
> -#endif
> -
>        fprintf (stderr, "Remote debugging using %s\n", name);
>  
>        enable_async_notification (remote_desc);
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index d54b8f8..a96d4fc 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -31,7 +31,9 @@
>  
>  #include "inflow.h"
>  #include "gdbcmd.h"
> -#include "gdb_termios.h"
> +#ifdef HAVE_TERMIOS_H
> +#include <termios.h>
> +#endif
>  #include "job-control.h"
>  
>  #ifdef HAVE_SYS_IOCTL_H
> @@ -64,9 +66,9 @@ struct terminal_info
>       it when it resumes.  */
>    serial_ttystate ttystate;
>  
> -#ifdef PROCESS_GROUP_TYPE
> +#ifdef HAVE_TERMIOS_H
>    /* Process group.  Saved and restored just like ttystate.  */
> -  PROCESS_GROUP_TYPE process_group;
> +  pid_t process_group;
>  #endif
>  
>    /* fcntl flags.  Saved and restored just like ttystate.  */
> @@ -89,11 +91,11 @@ static serial_ttystate initial_gdb_ttystate;
>  
>  static struct terminal_info *get_inflow_inferior_data (struct inferior *);
>  
> -#ifdef PROCESS_GROUP_TYPE
> +#ifdef HAVE_TERMIOS_H
>  
>  /* Return the process group of the current inferior.  */
>  
> -PROCESS_GROUP_TYPE
> +pid_t
>  inferior_process_group (void)
>  {
>    return get_inflow_inferior_data (current_inferior ())->process_group;
> @@ -121,25 +123,6 @@ static const char *inferior_thisrun_terminal;
>  
>  int terminal_is_ours;
>  
> -#ifdef PROCESS_GROUP_TYPE
> -static PROCESS_GROUP_TYPE
> -gdb_getpgrp (void)
> -{
> -  int process_group = -1;
> -
> -#ifdef HAVE_TERMIOS
> -  process_group = tcgetpgrp (0);
> -#endif
> -#ifdef HAVE_TERMIO
> -  process_group = getpgrp ();
> -#endif
> -#ifdef HAVE_SGTTY
> -  ioctl (0, TIOCGPGRP, &process_group);
> -#endif
> -  return process_group;
> -}
> -#endif
> -
>  /* See terminal.h.  */
>  
>  void
> @@ -157,8 +140,8 @@ set_initial_gdb_ttystate (void)
>  #ifdef F_GETFL
>        our_terminal_info.tflags = fcntl (0, F_GETFL, 0);
>  #endif
> -#ifdef PROCESS_GROUP_TYPE
> -      our_terminal_info.process_group = gdb_getpgrp ();
> +#ifdef HAVE_TERMIOS_H
> +      our_terminal_info.process_group = tcgetpgrp (0);
>  #endif
>      }
>  }
> @@ -187,7 +170,7 @@ child_terminal_init_with_pgrp (int pgrp)
>    struct inferior *inf = current_inferior ();
>    struct terminal_info *tinfo = get_inflow_inferior_data (inf);
>  
> -#ifdef PROCESS_GROUP_TYPE
> +#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.  */
> @@ -224,7 +207,7 @@ gdb_save_tty_state (void)
>  void
>  child_terminal_init (struct target_ops *self)
>  {
> -#ifdef PROCESS_GROUP_TYPE
> +#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
> @@ -232,7 +215,7 @@ child_terminal_init (struct target_ops *self)
>       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 /* PROCESS_GROUP_TYPE */
> +#endif /* HAVE_TERMIOS_H */
>  }
>  
>  /* Put the inferior's terminal settings into effect.
> @@ -269,11 +252,7 @@ child_terminal_inferior (struct target_ops *self)
>        OOPSY ("fcntl F_SETFL");
>  #endif
>  
> -      /* Because we were careful to not change in or out of raw mode in
> -         terminal_ours, we will not change in our out of raw mode with
> -         this call, so we don't flush any input.  */
> -      result = serial_set_tty_state (stdin_serial,
> -				     tinfo->ttystate);
> +      result = serial_set_tty_state (stdin_serial, tinfo->ttystate);
>        OOPSY ("setting tty state");
>  
>        if (!job_control)
> @@ -298,19 +277,12 @@ child_terminal_inferior (struct target_ops *self)
>  
>        if (job_control)
>  	{
> -#ifdef HAVE_TERMIOS
> +#ifdef HAVE_TERMIOS_H
>  	  result = tcsetpgrp (0, tinfo->process_group);
>  	  if (!inf->attach_flag)
>  	    OOPSY ("tcsetpgrp");
>  #endif
> -
> -#ifdef HAVE_SGTTY
> -	  result = ioctl (0, TIOCSPGRP, &tinfo->process_group);
> -	  if (!inf->attach_flag)
> -	    OOPSY ("TIOCSPGRP");
> -#endif
>  	}
> -
>      }
>    terminal_is_ours = 0;
>  }
> @@ -388,34 +360,20 @@ child_terminal_ours_1 (int output_only)
>        xfree (tinfo->ttystate);
>        tinfo->ttystate = serial_get_tty_state (stdin_serial);
>  
> -#ifdef PROCESS_GROUP_TYPE
> +#ifdef HAVE_TERMIOS_H
>        if (!inf->attach_flag)
> -	/* If setpgrp failed in terminal_inferior, this would give us
> +	/* If tcsetpgrp failed in terminal_inferior, this would give us
>  	   our process group instead of the inferior's.  See
>  	   terminal_inferior for details.  */
> -	tinfo->process_group = gdb_getpgrp ();
> +	tinfo->process_group = tcgetpgrp (0);
>  #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.
> -         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
> -         regardless of output_only, because we don't have separate
> -         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_terminal_info.ttystate,
> -				    tinfo->ttystate);
> +      /* Set tty state to our_ttystate.  */
> +      serial_set_tty_state (stdin_serial, our_terminal_info.ttystate);
>  
>        if (job_control)
>  	{
> -#ifdef HAVE_TERMIOS
> +#ifdef HAVE_TERMIOS_H
>  	  result = tcsetpgrp (0, our_terminal_info.process_group);
>  #if 0
>  	  /* This fails on Ultrix with EINVAL if you run the testsuite
> @@ -428,10 +386,6 @@ child_terminal_ours_1 (int output_only)
>  				safe_strerror (errno));
>  #endif
>  #endif /* termios */
> -
> -#ifdef HAVE_SGTTY
> -	  result = ioctl (0, TIOCSPGRP, &our_terminal_info.process_group);
> -#endif
>  	}
>  
>  #ifdef SIGTTOU
> @@ -616,7 +570,7 @@ child_terminal_info (struct target_ops *self, const char *args, int from_tty)
>      printf_filtered ("\n");
>    }
>  
> -#ifdef PROCESS_GROUP_TYPE
> +#ifdef HAVE_TERMIOS_H
>    printf_filtered ("Process group = %d\n", (int) tinfo->process_group);
>  #endif
>  
> diff --git a/gdb/inflow.h b/gdb/inflow.h
> index 428aed4..0b00c61 100644
> --- a/gdb/inflow.h
> +++ b/gdb/inflow.h
> @@ -20,17 +20,11 @@
>  #ifndef INFLOW_H
>  #define INFLOW_H
>  
> -#include "gdb_termios.h"
> +#include <unistd.h>
>  
> -#ifdef HAVE_TERMIOS
> -# define PROCESS_GROUP_TYPE pid_t
> -#elif defined (HAVE_TERMIO) || defined (HAVE_SGTTY)
> -# define PROCESS_GROUP_TYPE int
> -#endif
> -
> -#ifdef PROCESS_GROUP_TYPE
>  /* Process group of the current inferior.  */
> -extern PROCESS_GROUP_TYPE inferior_process_group (void);
> +#ifdef HAVE_TERMIOS_H
> +extern pid_t inferior_process_group (void);
>  #endif
>  
>  #endif /* inflow.h */
> diff --git a/gdb/ser-base.c b/gdb/ser-base.c
> index 2bfe82b..3262dcc 100644
> --- a/gdb/ser-base.c
> +++ b/gdb/ser-base.c
> @@ -551,14 +551,6 @@ ser_base_set_tty_state (struct serial *scb, serial_ttystate ttystate)
>    return 0;
>  }
>  
> -int
> -ser_base_noflush_set_tty_state (struct serial *scb,
> -				serial_ttystate new_ttystate,
> -				serial_ttystate old_ttystate)
> -{
> -  return 0;
> -}
> -
>  void
>  ser_base_print_tty_state (struct serial *scb, 
>  			  serial_ttystate ttystate,
> diff --git a/gdb/ser-base.h b/gdb/ser-base.h
> index 964d640..ceeb7de 100644
> --- a/gdb/ser-base.h
> +++ b/gdb/ser-base.h
> @@ -40,9 +40,6 @@ extern int ser_base_set_tty_state (struct serial *scb,
>  extern void ser_base_print_tty_state (struct serial *scb,
>  				      serial_ttystate ttystate,
>  				      struct ui_file *stream);
> -extern int ser_base_noflush_set_tty_state (struct serial *scb,
> -					   serial_ttystate new_ttystate,
> -					   serial_ttystate old_ttystate);
>  extern int ser_base_setbaudrate (struct serial *scb, int rate);
>  extern int ser_base_setstopbits (struct serial *scb, int num);
>  extern int ser_base_setparity (struct serial *scb, int parity);
> diff --git a/gdb/ser-event.c b/gdb/ser-event.c
> index 08b56a3..8b88ca0 100644
> --- a/gdb/ser-event.c
> +++ b/gdb/ser-event.c
> @@ -144,7 +144,6 @@ static const struct serial_ops serial_event_ops =
>    NULL, /* copy_tty_state */
>    NULL, /* set_tty_state */
>    NULL, /* print_tty_state */
> -  NULL, /* noflush_set_tty_state */
>    NULL, /* setbaudrate */
>    NULL, /* setstopbits */
>    NULL, /* setparity */
> diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
> index e352895..6965f19 100644
> --- a/gdb/ser-go32.c
> +++ b/gdb/ser-go32.c
> @@ -689,17 +689,6 @@ dos_set_tty_state (struct serial *scb, serial_ttystate ttystate)
>  }
>  
>  static int
> -dos_noflush_set_tty_state (struct serial *scb, serial_ttystate new_ttystate,
> -			   serial_ttystate old_ttystate)
> -{
> -  struct dos_ttystate *state;
> -
> -  state = (struct dos_ttystate *) new_ttystate;
> -  dos_setbaudrate (scb, state->baudrate);
> -  return 0;
> -}
> -
> -static int
>  dos_flush_input (struct serial *scb)
>  {
>    struct dos_ttystate *port = &ports[scb->fd];
> @@ -882,7 +871,6 @@ static const struct serial_ops dos_ops =
>    dos_copy_tty_state,
>    dos_set_tty_state,
>    dos_print_tty_state,
> -  dos_noflush_set_tty_state,
>    dos_setbaudrate,
>    dos_setstopbits,
>    dos_setparity,
> diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
> index 33e4df3..2359a495 100644
> --- a/gdb/ser-mingw.c
> +++ b/gdb/ser-mingw.c
> @@ -1248,7 +1248,6 @@ static const struct serial_ops hardwire_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    ser_windows_setbaudrate,
>    ser_windows_setstopbits,
>    ser_windows_setparity,
> @@ -1279,7 +1278,6 @@ static const struct serial_ops tty_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    NULL,
>    NULL,
>    NULL,
> @@ -1310,7 +1308,6 @@ static const struct serial_ops pipe_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    ser_base_setbaudrate,
>    ser_base_setstopbits,
>    ser_base_setparity,
> @@ -1341,7 +1338,6 @@ static const struct serial_ops tcp_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    ser_base_setbaudrate,
>    ser_base_setstopbits,
>    ser_base_setparity,
> diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
> index cb94242..56a91fc 100644
> --- a/gdb/ser-pipe.c
> +++ b/gdb/ser-pipe.c
> @@ -219,7 +219,6 @@ static const struct serial_ops pipe_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    ser_base_setbaudrate,
>    ser_base_setstopbits,
>    ser_base_setparity,
> diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
> index 7ff588b..cc6de30 100644
> --- a/gdb/ser-tcp.c
> +++ b/gdb/ser-tcp.c
> @@ -399,7 +399,6 @@ static const struct serial_ops tcp_ops =
>    ser_base_copy_tty_state,
>    ser_base_set_tty_state,
>    ser_base_print_tty_state,
> -  ser_base_noflush_set_tty_state,
>    ser_base_setbaudrate,
>    ser_base_setstopbits,
>    ser_base_setparity,
> diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
> index 53c33e6..3cbb77f 100644
> --- a/gdb/ser-unix.c
> +++ b/gdb/ser-unix.c
> @@ -31,9 +31,7 @@
>  #include "gdb_select.h"
>  #include "gdbcmd.h"
>  #include "filestuff.h"
> -#include "gdb_termios.h"
> -
> -#ifdef HAVE_TERMIOS
> +#include <termios.h>
>  
>  struct hardwire_ttystate
>    {
> @@ -51,32 +49,6 @@ show_serial_hwflow (struct ui_file *file, int from_tty,
>  }
>  #endif
>  
> -#endif /* termios */
> -
> -#ifdef HAVE_TERMIO
> -
> -/* It is believed that all systems which have added job control to SVR3
> -   (e.g. sco) have also added termios.  Even if not, trying to figure out
> -   all the variations (TIOCGPGRP vs. TCGETPGRP, etc.) would be pretty
> -   bewildering.  So we don't attempt it.  */
> -
> -struct hardwire_ttystate
> -  {
> -    struct termio termio;
> -  };
> -#endif /* termio */
> -
> -#ifdef HAVE_SGTTY
> -struct hardwire_ttystate
> -  {
> -    struct sgttyb sgttyb;
> -    struct tchars tc;
> -    struct ltchars ltc;
> -    /* Line discipline flags.  */
> -    int lmode;
> -  };
> -#endif /* sgtty */
> -
>  static int hardwire_open (struct serial *scb, const char *name);
>  static void hardwire_raw (struct serial *scb);
>  static int rate_to_code (int rate);
> @@ -89,8 +61,6 @@ static int set_tty_state (struct serial *scb,
>  			  struct hardwire_ttystate * state);
>  static serial_ttystate hardwire_get_tty_state (struct serial *scb);
>  static int hardwire_set_tty_state (struct serial *scb, serial_ttystate state);
> -static int hardwire_noflush_set_tty_state (struct serial *, serial_ttystate,
> -					   serial_ttystate);
>  static void hardwire_print_tty_state (struct serial *, serial_ttystate,
>  				      struct ui_file *);
>  static int hardwire_drain_output (struct serial *);
> @@ -114,61 +84,19 @@ hardwire_open (struct serial *scb, const char *name)
>  static int
>  get_tty_state (struct serial *scb, struct hardwire_ttystate *state)
>  {
> -#ifdef HAVE_TERMIOS
>    if (tcgetattr (scb->fd, &state->termios) < 0)
>      return -1;
>  
>    return 0;
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
> -    return -1;
> -  return 0;
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  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;
> -
> -  return 0;
> -#endif
>  }
>  
>  static int
>  set_tty_state (struct serial *scb, struct hardwire_ttystate *state)
>  {
> -#ifdef HAVE_TERMIOS
>    if (tcsetattr (scb->fd, TCSANOW, &state->termios) < 0)
>      return -1;
>  
>    return 0;
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
> -    return -1;
> -  return 0;
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
> -    return -1;
> -  if (ioctl (scb->fd, TIOCSETC, &state->tc) < 0)
> -    return -1;
> -  if (ioctl (scb->fd, TIOCSLTC, &state->ltc) < 0)
> -    return -1;
> -  if (ioctl (scb->fd, TIOCLSET, &state->lmode) < 0)
> -    return -1;
> -
> -  return 0;
> -#endif
>  }
>  
>  static serial_ttystate
> @@ -205,39 +133,6 @@ hardwire_set_tty_state (struct serial *scb, serial_ttystate ttystate)
>    return set_tty_state (scb, state);
>  }
>  
> -static int
> -hardwire_noflush_set_tty_state (struct serial *scb,
> -				serial_ttystate new_ttystate,
> -				serial_ttystate old_ttystate)
> -{
> -  struct hardwire_ttystate new_state;
> -#ifdef HAVE_SGTTY
> -  struct hardwire_ttystate *state = (struct hardwire_ttystate *) old_ttystate;
> -#endif
> -
> -  new_state = *(struct hardwire_ttystate *) new_ttystate;
> -
> -  /* Don't change in or out of raw mode; we don't want to flush input.
> -     termio and termios have no such restriction; for them flushing input
> -     is separate from setting the attributes.  */
> -
> -#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 (struct serial *scb,
>  			  serial_ttystate ttystate,
> @@ -246,7 +141,6 @@ hardwire_print_tty_state (struct serial *scb,
>    struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
>    int i;
>  
> -#ifdef HAVE_TERMIOS
>    fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
>  		    (int) state->termios.c_iflag,
>  		    (int) state->termios.c_oflag);
> @@ -262,36 +156,6 @@ hardwire_print_tty_state (struct serial *scb,
>    for (i = 0; i < NCCS; i += 1)
>      fprintf_filtered (stream, "0x%x ", state->termios.c_cc[i]);
>    fprintf_filtered (stream, "\n");
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
> -		    state->termio.c_iflag, state->termio.c_oflag);
> -  fprintf_filtered (stream, "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);
> -  fprintf_filtered (stream, "c_cc: ");
> -  for (i = 0; i < NCC; i += 1)
> -    fprintf_filtered (stream, "0x%x ", state->termio.c_cc[i]);
> -  fprintf_filtered (stream, "\n");
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  fprintf_filtered (stream, "sgttyb.sg_flags = 0x%x.\n",
> -		    state->sgttyb.sg_flags);
> -
> -  fprintf_filtered (stream, "tchars: ");
> -  for (i = 0; i < (int) sizeof (struct tchars); i++)
> -    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->tc)[i]);
> -  fprintf_filtered (stream, "\n");
> -
> -  fprintf_filtered (stream, "ltchars: ");
> -  for (i = 0; i < (int) sizeof (struct ltchars); i++)
> -    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->ltc)[i]);
> -  fprintf_filtered (stream, "\n");
> -
> -  fprintf_filtered (stream, "lmode:  0x%x\n", state->lmode);
> -#endif
>  }
>  
>  /* Wait for the output to drain away, as opposed to flushing
> @@ -300,48 +164,13 @@ hardwire_print_tty_state (struct serial *scb,
>  static int
>  hardwire_drain_output (struct serial *scb)
>  {
> -#ifdef HAVE_TERMIOS
>    return tcdrain (scb->fd);
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  return ioctl (scb->fd, TCSBRK, 1);
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  /* Get the current state and then restore it using TIOCSETP,
> -     which should cause the output to drain and pending input
> -     to be discarded.  */
> -  {
> -    struct hardwire_ttystate state;
> -
> -    if (get_tty_state (scb, &state))
> -      {
> -	return (-1);
> -      }
> -    else
> -      {
> -	return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
> -      }
> -  }
> -#endif
>  }
>  
>  static int
>  hardwire_flush_output (struct serial *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 int
> @@ -349,45 +178,13 @@ hardwire_flush_input (struct serial *scb)
>  {
>    ser_base_flush_input (scb);
>  
> -#ifdef HAVE_TERMIOS
>    return tcflush (scb->fd, TCIFLUSH);
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  return ioctl (scb->fd, TCFLSH, 0);
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  /* This flushes both input and output, but we can't do better.  */
> -  return ioctl (scb->fd, TIOCFLUSH, 0);
> -#endif
>  }
>  
>  static int
>  hardwire_send_break (struct serial *scb)
>  {
> -#ifdef HAVE_TERMIOS
>    return tcsendbreak (scb->fd, 0);
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  return ioctl (scb->fd, TCSBRK, 0);
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  {
> -    int status;
> -
> -    status = ioctl (scb->fd, TIOCSBRK, 0);
> -
> -    /* Can't use usleep; it doesn't exist in BSD 4.2.  */
> -    /* Note that if this gdb_select() is interrupted by a signal it will not
> -       wait the full length of time.  I think that is OK.  */
> -    gdb_usleep (250000);
> -    status = ioctl (scb->fd, TIOCCBRK, 0);
> -    return status;
> -  }
> -#endif
>  }
>  
>  static void
> @@ -399,7 +196,6 @@ hardwire_raw (struct serial *scb)
>      fprintf_unfiltered (gdb_stderr, "get_tty_state failed: %s\n",
>  			safe_strerror (errno));
>  
> -#ifdef HAVE_TERMIOS
>    state.termios.c_iflag = 0;
>    state.termios.c_oflag = 0;
>    state.termios.c_lflag = 0;
> @@ -420,22 +216,6 @@ hardwire_raw (struct serial *scb)
>  #endif
>    state.termios.c_cc[VMIN] = 0;
>    state.termios.c_cc[VTIME] = 0;
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  state.termio.c_iflag = 0;
> -  state.termio.c_oflag = 0;
> -  state.termio.c_lflag = 0;
> -  state.termio.c_cflag &= ~CSIZE;
> -  state.termio.c_cflag |= CLOCAL | CS8;
> -  state.termio.c_cc[VMIN] = 0;
> -  state.termio.c_cc[VTIME] = 0;
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  state.sgttyb.sg_flags |= RAW | ANYP;
> -  state.sgttyb.sg_flags &= ~(CBREAK | ECHO);
> -#endif
>  
>    if (set_tty_state (scb, &state))
>      fprintf_unfiltered (gdb_stderr, "set_tty_state failed: %s\n",
> @@ -604,24 +384,8 @@ hardwire_setbaudrate (struct serial *scb, int rate)
>    if (get_tty_state (scb, &state))
>      return -1;
>  
> -#ifdef HAVE_TERMIOS
>    cfsetospeed (&state.termios, baud_code);
>    cfsetispeed (&state.termios, baud_code);
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -#ifndef CIBAUD
> -#define CIBAUD CBAUD
> -#endif
> -
> -  state.termio.c_cflag &= ~(CBAUD | CIBAUD);
> -  state.termio.c_cflag |= baud_code;
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  state.sgttyb.sg_ispeed = baud_code;
> -  state.sgttyb.sg_ospeed = baud_code;
> -#endif
>  
>    return set_tty_state (scb, &state);
>  }
> @@ -648,23 +412,10 @@ hardwire_setstopbits (struct serial *scb, int num)
>        return 1;
>      }
>  
> -#ifdef HAVE_TERMIOS
>    if (!newbit)
>      state.termios.c_cflag &= ~CSTOPB;
>    else
>      state.termios.c_cflag |= CSTOPB;	/* two bits */
> -#endif
> -
> -#ifdef HAVE_TERMIO
> -  if (!newbit)
> -    state.termio.c_cflag &= ~CSTOPB;
> -  else
> -    state.termio.c_cflag |= CSTOPB;	/* two bits */
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  return 0;			/* sgtty doesn't support this */
> -#endif
>  
>    return set_tty_state (scb, &state);
>  }
> @@ -697,19 +448,9 @@ hardwire_setparity (struct serial *scb, int parity)
>        return -1;
>      }
>  
> -#ifdef HAVE_TERMIOS
>    state.termios.c_cflag &= ~(PARENB | PARODD);
>    state.termios.c_cflag |= newparity;
> -#endif
>  
> -#ifdef HAVE_TERMIO
> -  state.termio.c_cflag &= ~(PARENB | PARODD);
> -  state.termio.c_cflag |= newparity;
> -#endif
> -
> -#ifdef HAVE_SGTTY
> -  return 0;            /* sgtty doesn't support this */
> -#endif
>    return set_tty_state (scb, &state);
>  }
>  
> @@ -744,7 +485,6 @@ static const struct serial_ops hardwire_ops =
>    hardwire_copy_tty_state,
>    hardwire_set_tty_state,
>    hardwire_print_tty_state,
> -  hardwire_noflush_set_tty_state,
>    hardwire_setbaudrate,
>    hardwire_setstopbits,
>    hardwire_setparity,
> @@ -759,7 +499,6 @@ _initialize_ser_hardwire (void)
>  {
>    serial_add_interface (&hardwire_ops);
>  
> -#ifdef HAVE_TERMIOS
>  #ifdef CRTSCTS
>    add_setshow_boolean_cmd ("remoteflow", no_class,
>  			   &serial_hwflow, _("\
> @@ -771,7 +510,6 @@ when debugging using remote targets."),
>  			   show_serial_hwflow,
>  			   &setlist, &showlist);
>  #endif
> -#endif
>  }
>  
>  int
> diff --git a/gdb/serial.c b/gdb/serial.c
> index 6866549..32d4f5a 100644
> --- a/gdb/serial.c
> +++ b/gdb/serial.c
> @@ -514,14 +514,6 @@ serial_print_tty_state (struct serial *scb,
>  }
>  
>  int
> -serial_noflush_set_tty_state (struct serial *scb,
> -			      serial_ttystate new_ttystate,
> -			      serial_ttystate old_ttystate)
> -{
> -  return scb->ops->noflush_set_tty_state (scb, new_ttystate, old_ttystate);
> -}
> -
> -int
>  serial_setbaudrate (struct serial *scb, int rate)
>  {
>    return scb->ops->setbaudrate (scb, rate);
> diff --git a/gdb/serial.h b/gdb/serial.h
> index c76ddbe..647eab3 100644
> --- a/gdb/serial.h
> +++ b/gdb/serial.h
> @@ -169,16 +169,6 @@ extern void serial_print_tty_state (struct serial *scb,
>  				    serial_ttystate ttystate,
>  				    struct ui_file *);
>  
> -/* 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.  */
> -
> -extern int serial_noflush_set_tty_state (struct serial *scb,
> -					 serial_ttystate new_ttystate,
> -					 serial_ttystate old_ttystate);
> -
>  /* Set the baudrate to the decimal value supplied.  Returns 0 for
>     success, -1 for failure.  */
>  
> @@ -276,8 +266,6 @@ struct serial_ops
>      int (*set_tty_state) (struct serial *, serial_ttystate);
>      void (*print_tty_state) (struct serial *, serial_ttystate,
>  			     struct ui_file *);
> -    int (*noflush_set_tty_state) (struct serial *, serial_ttystate,
> -				  serial_ttystate);
>      int (*setbaudrate) (struct serial *, int rate);
>      int (*setstopbits) (struct serial *, int num);
>      /* Set the value PARITY as parity setting for serial object.
> -- 
> 2.5.5

As far as I could, I reviewed all the changes, and they seem OK to me
modulo the few nits I pointed.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty
  2017-11-02 18:54   ` Sergio Durigan Junior
@ 2017-11-02 19:27     ` Pedro Alves
  2017-11-02 19:32       ` Sergio Durigan Junior
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-11-02 19:27 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 11/02/2017 06:54 PM, Sergio Durigan Junior wrote:
> On Thursday, November 02 2017, Pedro Alves wrote:
> 
>> This commit garbage collects the termio and sgtty support.
>>
>> GDB's terminal handling code still has support for the old termio and
>> sgtty interfaces in addition to termios.  However, I think it's pretty
>> safe to assume that for a long, long time, Unix-like systems provide
>> termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
>> all have had termios.h for many years.  Looking around the web, I
>> found discussions about FreeBSD folks trying to get rid of old sgtty.h
>> a decade ago:
>>
>>   https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html
>>
>> So I think support for termio and sgtty in GDB is just dead code that
>> is never compiled anywhere and is just getting in the way.  For
>> example, serial_noflush_set_tty_state and the raw<->cooked concerns
>> mentioned in inflow.c only exist because of sgtty (see
>> hardwire_noflush_set_tty_state).
>>
>> Regtested on GNU/Linux.
>>
>> Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
>> that GDB still includes the termios.h-guarded code.  Confirmed
> 
> "that that"

Eh, that was actually on purpose.  It's "I confirmed that $something",
with "$something == that GDB (the one I built) still includes".
The first 'that' is the subordinating that, and the second 'that' is 
a demonstrative pronoun.  It's not unlike:
"I think that this thing is blue, and
 I think that that other thing is white".

> 
>> mingw-w64 GDB still builds and skips the termios.h-guarded code.
> 
> Thanks for doing that.
> 
> You may remember that I also stumbled upon this while doing the
> startup-with-shell, but I didn't have the necessary background knowledge
> to do a deep cleanup.  It's always nice to see old code being removed.

Well, it was only after banging my head against the terminal
handling for a couple weeks that I realized that this is
all dead code.  :-P

>> --- a/gdb/Makefile.in
>> +++ b/gdb/Makefile.in
>> @@ -729,12 +729,9 @@ XMLFILES = \
>>  	$(srcdir)/features/traceframe-info.dtd \
>>  	$(srcdir)/features/xinclude.dtd
>>  
>> -# This is ser-unix.o for any system which supports a v7/BSD/SYSV/POSIX
>> -# interface to the serial port.  Hopefully if get ported to OS/2, VMS,
>> -# etc., then there will be (as part of the C library or perhaps as
>> -# part of libiberty) a POSIX interface.  But at least for now the
>> -# host-dependent makefile fragment might need to use something else
>> -# besides ser-unix.o
>> +# This is ser-unix.o for any system which supports a POSIX interface
>> +# to the serial port.  The host-dependent makefile fragment might need
>> +# to use something else besides ser-unix.o.
>>  SER_HARDWIRE = @SER_HARDWIRE@
>>  
>>  # The `remote' debugging target is supported for most architectures,
> 
> You also need to remove common/gdb_termios.h from HFILES_NO_SRCDIR here.

Good point.  Consider it done.

>> -#if defined (HAVE_TERMIOS) || defined (TIOCGPGRP)
>>  #ifdef HAVE_SETPGID
>>        /* The call setpgid (0, 0) is supposed to work and mean the same
>>           thing as this, but on Ultrix 4.2A it fails with EPERM (and
>> @@ -56,7 +58,6 @@ gdb_setpgid ()
>>  #endif
>>  #endif /* HAVE_SETPGRP */
>>  #endif /* HAVE_SETPGID */
>> -#endif /* defined (HAVE_TERMIOS) || defined (TIOCGPGRP) */
> 
> Did you decide to remove the check for HAVE_TERMIOS (instead of
> replacing it with an "#ifdef HAVE_TERMIOS_H") because we're already
> checking for HAVE_SETPGID?

Yes.

>> --- a/gdb/gdbserver/remote-utils.c
>> +++ b/gdb/gdbserver/remote-utils.c
>> @@ -17,7 +17,9 @@
>>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>>  
>>  #include "server.h"
>> -#include "gdb_termios.h"
>> +#if HAVE_TERMIOS_H
>> +#include <termios.h>
>> +#endif
>>  #include "target.h"
>>  #include "gdbthread.h"
>>  #include "tdesc.h"
>> @@ -325,7 +327,7 @@ remote_open (const char *name)
>>        if (remote_desc < 0)
>>  	perror_with_name ("Could not open remote device");
>>  
>> -#ifdef HAVE_TERMIOS
>> +#if HAVE_TERMIOS_H
> 
> Why s/#ifdef/#if/?  I prefer #ifdef BTW.

Yeah, I used #if here because it's what the file is already
using for the other headers:

#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if HAVE_SYS_FILE_H
#include <sys/file.h>
#endif

etc.

> As far as I could, I reviewed all the changes, and they seem OK to me
> modulo the few nits I pointed.

Thanks for the review!

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty
  2017-11-02 19:27     ` Pedro Alves
@ 2017-11-02 19:32       ` Sergio Durigan Junior
  2017-11-06 16:11         ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Sergio Durigan Junior @ 2017-11-02 19:32 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thursday, November 02 2017, Pedro Alves wrote:

> On 11/02/2017 06:54 PM, Sergio Durigan Junior wrote:
>> On Thursday, November 02 2017, Pedro Alves wrote:
>> 
>>> This commit garbage collects the termio and sgtty support.
>>>
>>> GDB's terminal handling code still has support for the old termio and
>>> sgtty interfaces in addition to termios.  However, I think it's pretty
>>> safe to assume that for a long, long time, Unix-like systems provide
>>> termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
>>> all have had termios.h for many years.  Looking around the web, I
>>> found discussions about FreeBSD folks trying to get rid of old sgtty.h
>>> a decade ago:
>>>
>>>   https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html
>>>
>>> So I think support for termio and sgtty in GDB is just dead code that
>>> is never compiled anywhere and is just getting in the way.  For
>>> example, serial_noflush_set_tty_state and the raw<->cooked concerns
>>> mentioned in inflow.c only exist because of sgtty (see
>>> hardwire_noflush_set_tty_state).
>>>
>>> Regtested on GNU/Linux.
>>>
>>> Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
>>> that GDB still includes the termios.h-guarded code.  Confirmed
>> 
>> "that that"
>
> Eh, that was actually on purpose.  It's "I confirmed that $something",
> with "$something == that GDB (the one I built) still includes".
> The first 'that' is the subordinating that, and the second 'that' is 
> a demonstrative pronoun.  It's not unlike:
> "I think that this thing is blue, and
>  I think that that other thing is white".

Ah, OK, it took me a while to understand what you were trying to say
there :-).  Sorry about the noise.

>> 
>>> mingw-w64 GDB still builds and skips the termios.h-guarded code.
>> 
>> Thanks for doing that.
>> 
>> You may remember that I also stumbled upon this while doing the
>> startup-with-shell, but I didn't have the necessary background knowledge
>> to do a deep cleanup.  It's always nice to see old code being removed.
>
> Well, it was only after banging my head against the terminal
> handling for a couple weeks that I realized that this is
> all dead code.  :-P

:-)

>>> --- a/gdb/gdbserver/remote-utils.c
>>> +++ b/gdb/gdbserver/remote-utils.c
>>> @@ -17,7 +17,9 @@
>>>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>>>  
>>>  #include "server.h"
>>> -#include "gdb_termios.h"
>>> +#if HAVE_TERMIOS_H
>>> +#include <termios.h>
>>> +#endif
>>>  #include "target.h"
>>>  #include "gdbthread.h"
>>>  #include "tdesc.h"
>>> @@ -325,7 +327,7 @@ remote_open (const char *name)
>>>        if (remote_desc < 0)
>>>  	perror_with_name ("Could not open remote device");
>>>  
>>> -#ifdef HAVE_TERMIOS
>>> +#if HAVE_TERMIOS_H
>> 
>> Why s/#ifdef/#if/?  I prefer #ifdef BTW.
>
> Yeah, I used #if here because it's what the file is already
> using for the other headers:
>
> #if HAVE_SYS_IOCTL_H
> #include <sys/ioctl.h>
> #endif
> #if HAVE_SYS_FILE_H
> #include <sys/file.h>
> #endif
>
> etc.

I see.  Up to you, but I'd use #ifdef everywhere.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty
  2017-11-02 19:32       ` Sergio Durigan Junior
@ 2017-11-06 16:11         ` Pedro Alves
  2017-11-06 16:31           ` [pushed] Don't check termio.h and sgtty.h in common/common.m4 either (Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty) Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-11-06 16:11 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 11/02/2017 07:32 PM, Sergio Durigan Junior wrote:
> On Thursday, November 02 2017, Pedro Alves wrote:
> 
>> On 11/02/2017 06:54 PM, Sergio Durigan Junior wrote:
>>> On Thursday, November 02 2017, Pedro Alves wrote:
>>>
>>>> This commit garbage collects the termio and sgtty support.
>>>>
>>>> GDB's terminal handling code still has support for the old termio and
>>>> sgtty interfaces in addition to termios.  However, I think it's pretty
>>>> safe to assume that for a long, long time, Unix-like systems provide
>>>> termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
>>>> all have had termios.h for many years.  Looking around the web, I
>>>> found discussions about FreeBSD folks trying to get rid of old sgtty.h
>>>> a decade ago:
>>>>
>>>>   https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html
>>>>
>>>> So I think support for termio and sgtty in GDB is just dead code that
>>>> is never compiled anywhere and is just getting in the way.  For
>>>> example, serial_noflush_set_tty_state and the raw<->cooked concerns
>>>> mentioned in inflow.c only exist because of sgtty (see
>>>> hardwire_noflush_set_tty_state).
>>>>
>>>> Regtested on GNU/Linux.
>>>>
>>>> Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
>>>> that GDB still includes the termios.h-guarded code.  Confirmed
>>>
>>> "that that"
>>
>> Eh, that was actually on purpose.  It's "I confirmed that $something",
>> with "$something == that GDB (the one I built) still includes".
>> The first 'that' is the subordinating that, and the second 'that' is 
>> a demonstrative pronoun.  It's not unlike:
>> "I think that this thing is blue, and
>>  I think that that other thing is white".
> 
> Ah, OK, it took me a while to understand what you were trying to say
> there :-).  Sorry about the noise.

I've tweaked it to say instead:
~~~
Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
the resulting GDBs still include the termios.h-guarded code.
Confirmed mingw-w64 GDB still builds and skips the termios.h-guarded
code.
~~~

I've also tweaked the gdb/Makefile.in:SER_HARDWIRE comment
further, from:

+# This is ser-unix.o for any system which supports a POSIX interface
+# to the serial port.  The host-dependent makefile fragment might need
+# to use something else besides ser-unix.o.
 SER_HARDWIRE = @SER_HARDWIRE@

to:

+# Build the ser-*.o files the host supports.  This includes ser-unix.o
+# for any system that supports a POSIX interface to the serial port.
+# See configure.ac.
 SER_HARDWIRE = @SER_HARDWIRE@

because I realized this was still talking about makefile
fragments that largely no longer exist since your configure.nat
patch.

>>
>> Yeah, I used #if here because it's what the file is already
>> using for the other headers:
>>
>> #if HAVE_SYS_IOCTL_H
>> #include <sys/ioctl.h>
>> #endif
>> #if HAVE_SYS_FILE_H
>> #include <sys/file.h>
>> #endif
>>
>> etc.
> 
> I see.  Up to you, but I'd use #ifdef everywhere.

There's no way to win here, in this patch.  Either we end up with
mixed use of #if and #ifdef in the same file, or we end up with mixed
use of #if vs #ifdef across files.  I chose to avoid mixed use
in the same file.  I wouldn't object a patch that made the
whole files of #ifdef, of course.  This shows most places in
gdb & gdbserver using #if instead of #ifdef to check
for existence of a header:

 cd gdb; grep "#if H" -rn | grep _H | grep -v "gnulib/"

Here's what I'm pushing in, along with the rest of the series.

Thanks again for taking a look!

From 761480da864a42772a1cdafec197d1bc79def165 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 6 Nov 2017 15:36:46 +0000
Subject: [PATCH] Assume termios is available, remove support for termio and
 sgtty

This commit garbage collects the termio and sgtty support.

GDB's terminal handling code still has support for the old termio and
sgtty interfaces in addition to termios.  However, I think it's pretty
safe to assume that for a long, long time, Unix-like systems provide
termios.  GNU/Linux, Solaris, Cygwin, AIX, DJGPP, macOS and the BSDs
all have had termios.h for many years.  Looking around the web, I
found discussions about FreeBSD folks trying to get rid of old sgtty.h
a decade ago:

  https://lists.freebsd.org/pipermail/freebsd-hackers/2007-March/019983.html

So I think support for termio and sgtty in GDB is just dead code that
is never compiled anywhere and is just getting in the way.  For
example, serial_noflush_set_tty_state and the raw<->cooked concerns
mentioned in inflow.c only exist because of sgtty (see
hardwire_noflush_set_tty_state).

Regtested on GNU/Linux.

Confirmed that I can still build Solaris, DJGPP and AIX GDB and that
the resulting GDBs still include the termios.h-guarded code.
Confirmed mingw-w64 GDB still builds and skips the termios.h-guarded
code.

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

	* Makefile.in (SER_HARDWIRE): Update comment.
	(HFILES_NO_SRCDIR): Remove gdb_termios.h.
	* common/gdb_termios.h: Delete file.
	* common/job-control.c: Include termios.h and unistd.h instead of
	gdb_termios.h.
	(gdb_setpgid): Remove HAVE_TERMIOS || TIOCGPGRP preprocessor
	check.
	(have_job_control): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove sgtty code.
	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* inflow.c: Include termios.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE checks with HAVE_TERMIOS_H checks throughout.
	Replace PROCESS_GROUP_TYPE references with pid_t references
	throughout.
	(gdb_getpgrp): Delete.
	(set_initial_gdb_ttystate): Use tcgetpgrp instead of gdb_getpgrp.
	(child_terminal_inferior): Remove comment.  Remove sgtty code.
	(child_terminal_ours_1): Use tcgetpgrp directly instead of
	gdb_getpgrp.  Use serial_set_tty_state instead aof
	serial_noflush_set_tty_state.  Remove sgtty code.
	* inflow.h: Include unistd.h instead of gdb_termios.h.  Replace
	PROCESS_GROUP_TYPE check with HAVE_TERMIOS_H check.
	(inferior_process_group): Now returns pid_t.
	* ser-base.c (ser_base_noflush_set_tty_state): Delete.
	* ser-base.h (ser_base_noflush_set_tty_state): Delete.
	* ser-event.c (serial_event_ops): Update.
	* ser-go32.c (dos_noflush_set_tty_state): Delete.
	(dos_ops): Update.
	* ser-mingw.c (hardwire_ops, tty_ops, pipe_ops, tcp_ops): Update.
	* ser-pipe.c (pipe_ops): Update.
	* ser-tcp.c (tcp_ops): Update.
	* ser-unix.c: Include termios.h instead of gdb_termios.h.  Remove
	HAVE_TERMIOS checks.
	[HAVE_TERMIO] (struct hardwire_ttystate): Delete.
	[HAVE_SGTTY] (struct hardwire_ttystate): Delete.
	(get_tty_state, set_tty_state): Drop termio and sgtty code, and
	assume termios.
	(hardwire_noflush_set_tty_state): Delete.
	(hardwire_print_tty_state, hardwire_drain_output)
	(hardwire_flush_output, hardwire_flush_input)
	(hardwire_send_break, hardwire_raw, hardwire_setbaudrate)
	(hardwire_setstopbits, hardwire_setparity): Drop termio and sgtty
	code, and assume termios.
	(hardwire_ops): Update.
	(_initialize_ser_hardwire): Remove HAVE_TERMIOS check.
	* serial.c (serial_noflush_set_tty_state): Delete.
	* serial.h (serial_noflush_set_tty_state): Delete.
	(serial_ops::noflush_set_tty_state): Delete.

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

	* configure.ac: No longer check for termio.h and sgtty.h.
	* configure: Regenerate.
	* remote-utils.c: Include termios.h instead of gdb_termios.h.
	(remote_open): Check HAVE_TERMIOS_H instead of HAVE_TERMIOS.
	Remove termio and sgtty code.
---
 gdb/Makefile.in              |  10 +-
 gdb/common/gdb_termios.h     |  78 -------------
 gdb/common/job-control.c     |  23 ++--
 gdb/configure                |   3 +-
 gdb/configure.ac             |   3 +-
 gdb/gdbserver/configure      |   2 +-
 gdb/gdbserver/configure.ac   |   2 +-
 gdb/gdbserver/remote-utils.c |  33 +-----
 gdb/inflow.c                 |  88 ++++-----------
 gdb/inflow.h                 |  12 +-
 gdb/ser-base.c               |   8 --
 gdb/ser-base.h               |   3 -
 gdb/ser-event.c              |   1 -
 gdb/ser-go32.c               |  12 --
 gdb/ser-mingw.c              |   4 -
 gdb/ser-pipe.c               |   1 -
 gdb/ser-tcp.c                |   1 -
 gdb/ser-unix.c               | 264 +------------------------------------------
 gdb/serial.c                 |   8 --
 gdb/serial.h                 |  12 --
 20 files changed, 44 insertions(+), 524 deletions(-)
 delete mode 100644 gdb/common/gdb_termios.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 84d3493..6fe9b38 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -729,12 +729,9 @@ XMLFILES = \
 	$(srcdir)/features/traceframe-info.dtd \
 	$(srcdir)/features/xinclude.dtd
 
-# This is ser-unix.o for any system which supports a v7/BSD/SYSV/POSIX
-# interface to the serial port.  Hopefully if get ported to OS/2, VMS,
-# etc., then there will be (as part of the C library or perhaps as
-# part of libiberty) a POSIX interface.  But at least for now the
-# host-dependent makefile fragment might need to use something else
-# besides ser-unix.o
+# Build the ser-*.o files the host supports.  This includes ser-unix.o
+# for any system that supports a POSIX interface to the serial port.
+# See configure.ac.
 SER_HARDWIRE = @SER_HARDWIRE@
 
 # The `remote' debugging target is supported for most architectures,
@@ -1539,7 +1536,6 @@ HFILES_NO_SRCDIR = \
 	common/gdb_setjmp.h \
 	common/gdb_signals.h \
 	common/gdb_sys_time.h \
-	common/gdb_termios.h \
 	common/gdb_vecs.h \
 	common/gdb_wait.h \
 	common/common-inferior.h \
diff --git a/gdb/common/gdb_termios.h b/gdb/common/gdb_termios.h
deleted file mode 100644
index 1d0544d..0000000
--- a/gdb/common/gdb_termios.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Common terminal interface definitions for GDB and gdbserver.
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef GDB_TERMIOS_H
-#define GDB_TERMIOS_H
-
-/* If we're using autoconf, it will define HAVE_TERMIOS_H,
-   HAVE_TERMIO_H and HAVE_SGTTY_H for us.  One day we can rewrite
-   ser-unix.c and inflow.c to inspect those names instead of
-   HAVE_TERMIOS, HAVE_TERMIO and the implicit HAVE_SGTTY (when neither
-   HAVE_TERMIOS or HAVE_TERMIO is set).  Until then, make sure that
-   nothing has already defined the one of the names, and do the right
-   thing.  */
-
-#if !defined (HAVE_TERMIOS) && !defined(HAVE_TERMIO) && !defined(HAVE_SGTTY)
-#if defined(HAVE_TERMIOS_H)
-#define HAVE_TERMIOS
-#else /* ! defined (HAVE_TERMIOS_H) */
-#if defined(HAVE_TERMIO_H)
-#define HAVE_TERMIO
-#else /* ! defined (HAVE_TERMIO_H) */
-#if defined(HAVE_SGTTY_H)
-#define HAVE_SGTTY
-#endif /* ! defined (HAVE_SGTTY_H) */
-#endif /* ! defined (HAVE_TERMIO_H) */
-#endif /* ! defined (HAVE_TERMIOS_H) */
-#endif /* !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) &&
-	  !defined (HAVE_SGTTY) */
-
-#if defined(HAVE_TERMIOS)
-#include <termios.h>
-#endif
-
-#if !defined(_WIN32) && !defined (HAVE_TERMIOS)
-
-/* Define a common set of macros -- BSD based -- and redefine whatever
-   the system offers to make it look like that.  FIXME: serial.h and
-   ser-*.c deal with this in a much cleaner fashion; as soon as stuff
-   is converted to use them, can get rid of this crap.  */
-
-#ifdef HAVE_TERMIO
-
-#include <termio.h>
-
-#undef TIOCGETP
-#define TIOCGETP TCGETA
-#undef TIOCSETN
-#define TIOCSETN TCSETA
-#undef TIOCSETP
-#define TIOCSETP TCSETAF
-#define TERMINAL struct termio
-
-#else /* sgtty */
-
-#include <fcntl.h>
-#include <sgtty.h>
-#include <sys/ioctl.h>
-#define TERMINAL struct sgttyb
-
-#endif /* sgtty */
-#endif
-
-#endif /* ! GDB_TERMIOS_H */
diff --git a/gdb/common/job-control.c b/gdb/common/job-control.c
index d76bc57..78fc672 100644
--- a/gdb/common/job-control.c
+++ b/gdb/common/job-control.c
@@ -20,7 +20,10 @@
 
 #include "common-defs.h"
 #include "job-control.h"
-#include "gdb_termios.h"
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#include <unistd.h>
 
 /* Nonzero if we have job control.  */
 int job_control;
@@ -41,7 +44,6 @@ gdb_setpgid ()
 
   if (job_control)
     {
-#if defined (HAVE_TERMIOS) || defined (TIOCGPGRP)
 #ifdef HAVE_SETPGID
       /* The call setpgid (0, 0) is supposed to work and mean the same
          thing as this, but on Ultrix 4.2A it fails with EPERM (and
@@ -56,7 +58,6 @@ gdb_setpgid ()
 #endif
 #endif /* HAVE_SETPGRP */
 #endif /* HAVE_SETPGID */
-#endif /* defined (HAVE_TERMIOS) || defined (TIOCGPGRP) */
     }
 
   return retval;
@@ -67,9 +68,9 @@ gdb_setpgid ()
 void
 have_job_control ()
 {
-  /* OK, figure out whether we have job control.  If neither termios nor
-     sgtty (i.e. termio or go32), leave job_control 0.  */
-#if defined (HAVE_TERMIOS)
+  /* OK, figure out whether we have job control.  If termios is not
+     available, leave job_control 0.  */
+#if defined (HAVE_TERMIOS_H)
   /* Do all systems with termios have the POSIX way of identifying job
      control?  I hope so.  */
 #ifdef _POSIX_JOB_CONTROL
@@ -81,13 +82,5 @@ have_job_control ()
   job_control = 0;		/* Have to assume the worst.  */
 #endif /* _SC_JOB_CONTROL */
 #endif /* _POSIX_JOB_CONTROL */
-#endif /* HAVE_TERMIOS */
-
-#ifdef HAVE_SGTTY
-#ifdef TIOCGPGRP
-  job_control = 1;
-#else
-  job_control = 0;
-#endif /* TIOCGPGRP */
-#endif /* sgtty */
+#endif /* HAVE_TERMIOS_H */
 }
diff --git a/gdb/configure b/gdb/configure
index 6b445e4..c638652 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11554,8 +11554,7 @@ for ac_header in nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
 		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
-		  termios.h termio.h \
-		  sgtty.h elf_hp.h \
+		  termios.h elf_hp.h \
 		  dlfcn.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 4e64c80..b909217 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1298,8 +1298,7 @@ AC_CHECK_HEADERS([nlist.h machine/reg.h poll.h sys/poll.h proc_service.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/procfs.h sys/ptrace.h ptrace.h \
 		  sys/reg.h sys/debugreg.h sys/select.h sys/syscall.h \
-		  termios.h termio.h \
-		  sgtty.h elf_hp.h \
+		  termios.h elf_hp.h \
 		  dlfcn.h])
 AC_CHECK_HEADERS(sys/proc.h, [], [],
 [#if HAVE_SYS_PARAM_H
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index abab163..d5c62fb 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -6177,7 +6177,7 @@ $as_echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cach
   cd "$ac_popdir"
 
 
-for ac_header in sgtty.h termio.h termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
+for ac_header in termios.h sys/reg.h string.h 		 proc_service.h sys/procfs.h linux/elf.h 		 fcntl.h signal.h sys/file.h 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h 		 netinet/tcp.h arpa/inet.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 60e235d..456d3b3 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -96,7 +96,7 @@ ACX_CONFIGURE_DIR(["../gnulib"], ["build-gnulib-gdbserver"],
 
 ACX_CONFIGURE_DIR(["../../libiberty"], ["build-libiberty-gdbserver"])
 
-AC_CHECK_HEADERS(sgtty.h termio.h termios.h sys/reg.h string.h dnl
+AC_CHECK_HEADERS(termios.h sys/reg.h string.h dnl
 		 proc_service.h sys/procfs.h linux/elf.h dnl
 		 fcntl.h signal.h sys/file.h dnl
 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 66e06522..54f27f4 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -17,7 +17,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "server.h"
-#include "gdb_termios.h"
+#if HAVE_TERMIOS_H
+#include <termios.h>
+#endif
 #include "target.h"
 #include "gdbthread.h"
 #include "tdesc.h"
@@ -325,7 +327,7 @@ remote_open (const char *name)
       if (remote_desc < 0)
 	perror_with_name ("Could not open remote device");
 
-#ifdef HAVE_TERMIOS
+#if HAVE_TERMIOS_H
       {
 	struct termios termios;
 	tcgetattr (remote_desc, &termios);
@@ -342,33 +344,6 @@ remote_open (const char *name)
       }
 #endif
 
-#ifdef HAVE_TERMIO
-      {
-	struct termio termio;
-	ioctl (remote_desc, TCGETA, &termio);
-
-	termio.c_iflag = 0;
-	termio.c_oflag = 0;
-	termio.c_lflag = 0;
-	termio.c_cflag &= ~(CSIZE | PARENB);
-	termio.c_cflag |= CLOCAL | CS8;
-	termio.c_cc[VMIN] = 1;
-	termio.c_cc[VTIME] = 0;
-
-	ioctl (remote_desc, TCSETA, &termio);
-      }
-#endif
-
-#ifdef HAVE_SGTTY
-      {
-	struct sgttyb sg;
-
-	ioctl (remote_desc, TIOCGETP, &sg);
-	sg.sg_flags = RAW;
-	ioctl (remote_desc, TIOCSETP, &sg);
-      }
-#endif
-
       fprintf (stderr, "Remote debugging using %s\n", name);
 
       enable_async_notification (remote_desc);
diff --git a/gdb/inflow.c b/gdb/inflow.c
index d54b8f8..a96d4fc 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -31,7 +31,9 @@
 
 #include "inflow.h"
 #include "gdbcmd.h"
-#include "gdb_termios.h"
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
 #include "job-control.h"
 
 #ifdef HAVE_SYS_IOCTL_H
@@ -64,9 +66,9 @@ struct terminal_info
      it when it resumes.  */
   serial_ttystate ttystate;
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
   /* Process group.  Saved and restored just like ttystate.  */
-  PROCESS_GROUP_TYPE process_group;
+  pid_t process_group;
 #endif
 
   /* fcntl flags.  Saved and restored just like ttystate.  */
@@ -89,11 +91,11 @@ static serial_ttystate initial_gdb_ttystate;
 
 static struct terminal_info *get_inflow_inferior_data (struct inferior *);
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
 
 /* Return the process group of the current inferior.  */
 
-PROCESS_GROUP_TYPE
+pid_t
 inferior_process_group (void)
 {
   return get_inflow_inferior_data (current_inferior ())->process_group;
@@ -121,25 +123,6 @@ static const char *inferior_thisrun_terminal;
 
 int terminal_is_ours;
 
-#ifdef PROCESS_GROUP_TYPE
-static PROCESS_GROUP_TYPE
-gdb_getpgrp (void)
-{
-  int process_group = -1;
-
-#ifdef HAVE_TERMIOS
-  process_group = tcgetpgrp (0);
-#endif
-#ifdef HAVE_TERMIO
-  process_group = getpgrp ();
-#endif
-#ifdef HAVE_SGTTY
-  ioctl (0, TIOCGPGRP, &process_group);
-#endif
-  return process_group;
-}
-#endif
-
 /* See terminal.h.  */
 
 void
@@ -157,8 +140,8 @@ set_initial_gdb_ttystate (void)
 #ifdef F_GETFL
       our_terminal_info.tflags = fcntl (0, F_GETFL, 0);
 #endif
-#ifdef PROCESS_GROUP_TYPE
-      our_terminal_info.process_group = gdb_getpgrp ();
+#ifdef HAVE_TERMIOS_H
+      our_terminal_info.process_group = tcgetpgrp (0);
 #endif
     }
 }
@@ -187,7 +170,7 @@ child_terminal_init_with_pgrp (int pgrp)
   struct inferior *inf = current_inferior ();
   struct terminal_info *tinfo = get_inflow_inferior_data (inf);
 
-#ifdef PROCESS_GROUP_TYPE
+#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.  */
@@ -224,7 +207,7 @@ gdb_save_tty_state (void)
 void
 child_terminal_init (struct target_ops *self)
 {
-#ifdef PROCESS_GROUP_TYPE
+#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
@@ -232,7 +215,7 @@ child_terminal_init (struct target_ops *self)
      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 /* PROCESS_GROUP_TYPE */
+#endif /* HAVE_TERMIOS_H */
 }
 
 /* Put the inferior's terminal settings into effect.
@@ -269,11 +252,7 @@ child_terminal_inferior (struct target_ops *self)
       OOPSY ("fcntl F_SETFL");
 #endif
 
-      /* Because we were careful to not change in or out of raw mode in
-         terminal_ours, we will not change in our out of raw mode with
-         this call, so we don't flush any input.  */
-      result = serial_set_tty_state (stdin_serial,
-				     tinfo->ttystate);
+      result = serial_set_tty_state (stdin_serial, tinfo->ttystate);
       OOPSY ("setting tty state");
 
       if (!job_control)
@@ -298,19 +277,12 @@ child_terminal_inferior (struct target_ops *self)
 
       if (job_control)
 	{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
 	  result = tcsetpgrp (0, tinfo->process_group);
 	  if (!inf->attach_flag)
 	    OOPSY ("tcsetpgrp");
 #endif
-
-#ifdef HAVE_SGTTY
-	  result = ioctl (0, TIOCSPGRP, &tinfo->process_group);
-	  if (!inf->attach_flag)
-	    OOPSY ("TIOCSPGRP");
-#endif
 	}
-
     }
   terminal_is_ours = 0;
 }
@@ -388,34 +360,20 @@ child_terminal_ours_1 (int output_only)
       xfree (tinfo->ttystate);
       tinfo->ttystate = serial_get_tty_state (stdin_serial);
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
       if (!inf->attach_flag)
-	/* If setpgrp failed in terminal_inferior, this would give us
+	/* If tcsetpgrp failed in terminal_inferior, this would give us
 	   our process group instead of the inferior's.  See
 	   terminal_inferior for details.  */
-	tinfo->process_group = gdb_getpgrp ();
+	tinfo->process_group = tcgetpgrp (0);
 #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.
-         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
-         regardless of output_only, because we don't have separate
-         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_terminal_info.ttystate,
-				    tinfo->ttystate);
+      /* Set tty state to our_ttystate.  */
+      serial_set_tty_state (stdin_serial, our_terminal_info.ttystate);
 
       if (job_control)
 	{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
 	  result = tcsetpgrp (0, our_terminal_info.process_group);
 #if 0
 	  /* This fails on Ultrix with EINVAL if you run the testsuite
@@ -428,10 +386,6 @@ child_terminal_ours_1 (int output_only)
 				safe_strerror (errno));
 #endif
 #endif /* termios */
-
-#ifdef HAVE_SGTTY
-	  result = ioctl (0, TIOCSPGRP, &our_terminal_info.process_group);
-#endif
 	}
 
 #ifdef SIGTTOU
@@ -616,7 +570,7 @@ child_terminal_info (struct target_ops *self, const char *args, int from_tty)
     printf_filtered ("\n");
   }
 
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
   printf_filtered ("Process group = %d\n", (int) tinfo->process_group);
 #endif
 
diff --git a/gdb/inflow.h b/gdb/inflow.h
index 428aed4..0b00c61 100644
--- a/gdb/inflow.h
+++ b/gdb/inflow.h
@@ -20,17 +20,11 @@
 #ifndef INFLOW_H
 #define INFLOW_H
 
-#include "gdb_termios.h"
+#include <unistd.h>
 
-#ifdef HAVE_TERMIOS
-# define PROCESS_GROUP_TYPE pid_t
-#elif defined (HAVE_TERMIO) || defined (HAVE_SGTTY)
-# define PROCESS_GROUP_TYPE int
-#endif
-
-#ifdef PROCESS_GROUP_TYPE
 /* Process group of the current inferior.  */
-extern PROCESS_GROUP_TYPE inferior_process_group (void);
+#ifdef HAVE_TERMIOS_H
+extern pid_t inferior_process_group (void);
 #endif
 
 #endif /* inflow.h */
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 2bfe82b..3262dcc 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -551,14 +551,6 @@ ser_base_set_tty_state (struct serial *scb, serial_ttystate ttystate)
   return 0;
 }
 
-int
-ser_base_noflush_set_tty_state (struct serial *scb,
-				serial_ttystate new_ttystate,
-				serial_ttystate old_ttystate)
-{
-  return 0;
-}
-
 void
 ser_base_print_tty_state (struct serial *scb, 
 			  serial_ttystate ttystate,
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 964d640..ceeb7de 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -40,9 +40,6 @@ extern int ser_base_set_tty_state (struct serial *scb,
 extern void ser_base_print_tty_state (struct serial *scb,
 				      serial_ttystate ttystate,
 				      struct ui_file *stream);
-extern int ser_base_noflush_set_tty_state (struct serial *scb,
-					   serial_ttystate new_ttystate,
-					   serial_ttystate old_ttystate);
 extern int ser_base_setbaudrate (struct serial *scb, int rate);
 extern int ser_base_setstopbits (struct serial *scb, int num);
 extern int ser_base_setparity (struct serial *scb, int parity);
diff --git a/gdb/ser-event.c b/gdb/ser-event.c
index 08b56a3..8b88ca0 100644
--- a/gdb/ser-event.c
+++ b/gdb/ser-event.c
@@ -144,7 +144,6 @@ static const struct serial_ops serial_event_ops =
   NULL, /* copy_tty_state */
   NULL, /* set_tty_state */
   NULL, /* print_tty_state */
-  NULL, /* noflush_set_tty_state */
   NULL, /* setbaudrate */
   NULL, /* setstopbits */
   NULL, /* setparity */
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index e352895..6965f19 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -689,17 +689,6 @@ dos_set_tty_state (struct serial *scb, serial_ttystate ttystate)
 }
 
 static int
-dos_noflush_set_tty_state (struct serial *scb, serial_ttystate new_ttystate,
-			   serial_ttystate old_ttystate)
-{
-  struct dos_ttystate *state;
-
-  state = (struct dos_ttystate *) new_ttystate;
-  dos_setbaudrate (scb, state->baudrate);
-  return 0;
-}
-
-static int
 dos_flush_input (struct serial *scb)
 {
   struct dos_ttystate *port = &ports[scb->fd];
@@ -882,7 +871,6 @@ static const struct serial_ops dos_ops =
   dos_copy_tty_state,
   dos_set_tty_state,
   dos_print_tty_state,
-  dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
   dos_setparity,
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 33e4df3..2359a495 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -1248,7 +1248,6 @@ static const struct serial_ops hardwire_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
   ser_windows_setparity,
@@ -1279,7 +1278,6 @@ static const struct serial_ops tty_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   NULL,
   NULL,
   NULL,
@@ -1310,7 +1308,6 @@ static const struct serial_ops pipe_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
@@ -1341,7 +1338,6 @@ static const struct serial_ops tcp_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index cb94242..56a91fc 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -219,7 +219,6 @@ static const struct serial_ops pipe_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 7ff588b..cc6de30 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -399,7 +399,6 @@ static const struct serial_ops tcp_ops =
   ser_base_copy_tty_state,
   ser_base_set_tty_state,
   ser_base_print_tty_state,
-  ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
   ser_base_setparity,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 53c33e6..3cbb77f 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -31,9 +31,7 @@
 #include "gdb_select.h"
 #include "gdbcmd.h"
 #include "filestuff.h"
-#include "gdb_termios.h"
-
-#ifdef HAVE_TERMIOS
+#include <termios.h>
 
 struct hardwire_ttystate
   {
@@ -51,32 +49,6 @@ show_serial_hwflow (struct ui_file *file, int from_tty,
 }
 #endif
 
-#endif /* termios */
-
-#ifdef HAVE_TERMIO
-
-/* It is believed that all systems which have added job control to SVR3
-   (e.g. sco) have also added termios.  Even if not, trying to figure out
-   all the variations (TIOCGPGRP vs. TCGETPGRP, etc.) would be pretty
-   bewildering.  So we don't attempt it.  */
-
-struct hardwire_ttystate
-  {
-    struct termio termio;
-  };
-#endif /* termio */
-
-#ifdef HAVE_SGTTY
-struct hardwire_ttystate
-  {
-    struct sgttyb sgttyb;
-    struct tchars tc;
-    struct ltchars ltc;
-    /* Line discipline flags.  */
-    int lmode;
-  };
-#endif /* sgtty */
-
 static int hardwire_open (struct serial *scb, const char *name);
 static void hardwire_raw (struct serial *scb);
 static int rate_to_code (int rate);
@@ -89,8 +61,6 @@ static int set_tty_state (struct serial *scb,
 			  struct hardwire_ttystate * state);
 static serial_ttystate hardwire_get_tty_state (struct serial *scb);
 static int hardwire_set_tty_state (struct serial *scb, serial_ttystate state);
-static int hardwire_noflush_set_tty_state (struct serial *, serial_ttystate,
-					   serial_ttystate);
 static void hardwire_print_tty_state (struct serial *, serial_ttystate,
 				      struct ui_file *);
 static int hardwire_drain_output (struct serial *);
@@ -114,61 +84,19 @@ hardwire_open (struct serial *scb, const char *name)
 static int
 get_tty_state (struct serial *scb, struct hardwire_ttystate *state)
 {
-#ifdef HAVE_TERMIOS
   if (tcgetattr (scb->fd, &state->termios) < 0)
     return -1;
 
   return 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
-    return -1;
-  return 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  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;
-
-  return 0;
-#endif
 }
 
 static int
 set_tty_state (struct serial *scb, struct hardwire_ttystate *state)
 {
-#ifdef HAVE_TERMIOS
   if (tcsetattr (scb->fd, TCSANOW, &state->termios) < 0)
     return -1;
 
   return 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
-    return -1;
-  return 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCSETC, &state->tc) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCSLTC, &state->ltc) < 0)
-    return -1;
-  if (ioctl (scb->fd, TIOCLSET, &state->lmode) < 0)
-    return -1;
-
-  return 0;
-#endif
 }
 
 static serial_ttystate
@@ -205,39 +133,6 @@ hardwire_set_tty_state (struct serial *scb, serial_ttystate ttystate)
   return set_tty_state (scb, state);
 }
 
-static int
-hardwire_noflush_set_tty_state (struct serial *scb,
-				serial_ttystate new_ttystate,
-				serial_ttystate old_ttystate)
-{
-  struct hardwire_ttystate new_state;
-#ifdef HAVE_SGTTY
-  struct hardwire_ttystate *state = (struct hardwire_ttystate *) old_ttystate;
-#endif
-
-  new_state = *(struct hardwire_ttystate *) new_ttystate;
-
-  /* Don't change in or out of raw mode; we don't want to flush input.
-     termio and termios have no such restriction; for them flushing input
-     is separate from setting the attributes.  */
-
-#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 (struct serial *scb,
 			  serial_ttystate ttystate,
@@ -246,7 +141,6 @@ hardwire_print_tty_state (struct serial *scb,
   struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
   int i;
 
-#ifdef HAVE_TERMIOS
   fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
 		    (int) state->termios.c_iflag,
 		    (int) state->termios.c_oflag);
@@ -262,36 +156,6 @@ hardwire_print_tty_state (struct serial *scb,
   for (i = 0; i < NCCS; i += 1)
     fprintf_filtered (stream, "0x%x ", state->termios.c_cc[i]);
   fprintf_filtered (stream, "\n");
-#endif
-
-#ifdef HAVE_TERMIO
-  fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
-		    state->termio.c_iflag, state->termio.c_oflag);
-  fprintf_filtered (stream, "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);
-  fprintf_filtered (stream, "c_cc: ");
-  for (i = 0; i < NCC; i += 1)
-    fprintf_filtered (stream, "0x%x ", state->termio.c_cc[i]);
-  fprintf_filtered (stream, "\n");
-#endif
-
-#ifdef HAVE_SGTTY
-  fprintf_filtered (stream, "sgttyb.sg_flags = 0x%x.\n",
-		    state->sgttyb.sg_flags);
-
-  fprintf_filtered (stream, "tchars: ");
-  for (i = 0; i < (int) sizeof (struct tchars); i++)
-    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->tc)[i]);
-  fprintf_filtered (stream, "\n");
-
-  fprintf_filtered (stream, "ltchars: ");
-  for (i = 0; i < (int) sizeof (struct ltchars); i++)
-    fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->ltc)[i]);
-  fprintf_filtered (stream, "\n");
-
-  fprintf_filtered (stream, "lmode:  0x%x\n", state->lmode);
-#endif
 }
 
 /* Wait for the output to drain away, as opposed to flushing
@@ -300,48 +164,13 @@ hardwire_print_tty_state (struct serial *scb,
 static int
 hardwire_drain_output (struct serial *scb)
 {
-#ifdef HAVE_TERMIOS
   return tcdrain (scb->fd);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCSBRK, 1);
-#endif
-
-#ifdef HAVE_SGTTY
-  /* Get the current state and then restore it using TIOCSETP,
-     which should cause the output to drain and pending input
-     to be discarded.  */
-  {
-    struct hardwire_ttystate state;
-
-    if (get_tty_state (scb, &state))
-      {
-	return (-1);
-      }
-    else
-      {
-	return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
-      }
-  }
-#endif
 }
 
 static int
 hardwire_flush_output (struct serial *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 int
@@ -349,45 +178,13 @@ hardwire_flush_input (struct serial *scb)
 {
   ser_base_flush_input (scb);
 
-#ifdef HAVE_TERMIOS
   return tcflush (scb->fd, TCIFLUSH);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCFLSH, 0);
-#endif
-
-#ifdef HAVE_SGTTY
-  /* This flushes both input and output, but we can't do better.  */
-  return ioctl (scb->fd, TIOCFLUSH, 0);
-#endif
 }
 
 static int
 hardwire_send_break (struct serial *scb)
 {
-#ifdef HAVE_TERMIOS
   return tcsendbreak (scb->fd, 0);
-#endif
-
-#ifdef HAVE_TERMIO
-  return ioctl (scb->fd, TCSBRK, 0);
-#endif
-
-#ifdef HAVE_SGTTY
-  {
-    int status;
-
-    status = ioctl (scb->fd, TIOCSBRK, 0);
-
-    /* Can't use usleep; it doesn't exist in BSD 4.2.  */
-    /* Note that if this gdb_select() is interrupted by a signal it will not
-       wait the full length of time.  I think that is OK.  */
-    gdb_usleep (250000);
-    status = ioctl (scb->fd, TIOCCBRK, 0);
-    return status;
-  }
-#endif
 }
 
 static void
@@ -399,7 +196,6 @@ hardwire_raw (struct serial *scb)
     fprintf_unfiltered (gdb_stderr, "get_tty_state failed: %s\n",
 			safe_strerror (errno));
 
-#ifdef HAVE_TERMIOS
   state.termios.c_iflag = 0;
   state.termios.c_oflag = 0;
   state.termios.c_lflag = 0;
@@ -420,22 +216,6 @@ hardwire_raw (struct serial *scb)
 #endif
   state.termios.c_cc[VMIN] = 0;
   state.termios.c_cc[VTIME] = 0;
-#endif
-
-#ifdef HAVE_TERMIO
-  state.termio.c_iflag = 0;
-  state.termio.c_oflag = 0;
-  state.termio.c_lflag = 0;
-  state.termio.c_cflag &= ~CSIZE;
-  state.termio.c_cflag |= CLOCAL | CS8;
-  state.termio.c_cc[VMIN] = 0;
-  state.termio.c_cc[VTIME] = 0;
-#endif
-
-#ifdef HAVE_SGTTY
-  state.sgttyb.sg_flags |= RAW | ANYP;
-  state.sgttyb.sg_flags &= ~(CBREAK | ECHO);
-#endif
 
   if (set_tty_state (scb, &state))
     fprintf_unfiltered (gdb_stderr, "set_tty_state failed: %s\n",
@@ -604,24 +384,8 @@ hardwire_setbaudrate (struct serial *scb, int rate)
   if (get_tty_state (scb, &state))
     return -1;
 
-#ifdef HAVE_TERMIOS
   cfsetospeed (&state.termios, baud_code);
   cfsetispeed (&state.termios, baud_code);
-#endif
-
-#ifdef HAVE_TERMIO
-#ifndef CIBAUD
-#define CIBAUD CBAUD
-#endif
-
-  state.termio.c_cflag &= ~(CBAUD | CIBAUD);
-  state.termio.c_cflag |= baud_code;
-#endif
-
-#ifdef HAVE_SGTTY
-  state.sgttyb.sg_ispeed = baud_code;
-  state.sgttyb.sg_ospeed = baud_code;
-#endif
 
   return set_tty_state (scb, &state);
 }
@@ -648,23 +412,10 @@ hardwire_setstopbits (struct serial *scb, int num)
       return 1;
     }
 
-#ifdef HAVE_TERMIOS
   if (!newbit)
     state.termios.c_cflag &= ~CSTOPB;
   else
     state.termios.c_cflag |= CSTOPB;	/* two bits */
-#endif
-
-#ifdef HAVE_TERMIO
-  if (!newbit)
-    state.termio.c_cflag &= ~CSTOPB;
-  else
-    state.termio.c_cflag |= CSTOPB;	/* two bits */
-#endif
-
-#ifdef HAVE_SGTTY
-  return 0;			/* sgtty doesn't support this */
-#endif
 
   return set_tty_state (scb, &state);
 }
@@ -697,19 +448,9 @@ hardwire_setparity (struct serial *scb, int parity)
       return -1;
     }
 
-#ifdef HAVE_TERMIOS
   state.termios.c_cflag &= ~(PARENB | PARODD);
   state.termios.c_cflag |= newparity;
-#endif
 
-#ifdef HAVE_TERMIO
-  state.termio.c_cflag &= ~(PARENB | PARODD);
-  state.termio.c_cflag |= newparity;
-#endif
-
-#ifdef HAVE_SGTTY
-  return 0;            /* sgtty doesn't support this */
-#endif
   return set_tty_state (scb, &state);
 }
 
@@ -744,7 +485,6 @@ static const struct serial_ops hardwire_ops =
   hardwire_copy_tty_state,
   hardwire_set_tty_state,
   hardwire_print_tty_state,
-  hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
   hardwire_setparity,
@@ -759,7 +499,6 @@ _initialize_ser_hardwire (void)
 {
   serial_add_interface (&hardwire_ops);
 
-#ifdef HAVE_TERMIOS
 #ifdef CRTSCTS
   add_setshow_boolean_cmd ("remoteflow", no_class,
 			   &serial_hwflow, _("\
@@ -771,7 +510,6 @@ when debugging using remote targets."),
 			   show_serial_hwflow,
 			   &setlist, &showlist);
 #endif
-#endif
 }
 
 int
diff --git a/gdb/serial.c b/gdb/serial.c
index 6866549..32d4f5a 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -514,14 +514,6 @@ serial_print_tty_state (struct serial *scb,
 }
 
 int
-serial_noflush_set_tty_state (struct serial *scb,
-			      serial_ttystate new_ttystate,
-			      serial_ttystate old_ttystate)
-{
-  return scb->ops->noflush_set_tty_state (scb, new_ttystate, old_ttystate);
-}
-
-int
 serial_setbaudrate (struct serial *scb, int rate)
 {
   return scb->ops->setbaudrate (scb, rate);
diff --git a/gdb/serial.h b/gdb/serial.h
index c76ddbe..647eab3 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -169,16 +169,6 @@ extern void serial_print_tty_state (struct serial *scb,
 				    serial_ttystate ttystate,
 				    struct ui_file *);
 
-/* 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.  */
-
-extern int serial_noflush_set_tty_state (struct serial *scb,
-					 serial_ttystate new_ttystate,
-					 serial_ttystate old_ttystate);
-
 /* Set the baudrate to the decimal value supplied.  Returns 0 for
    success, -1 for failure.  */
 
@@ -276,8 +266,6 @@ struct serial_ops
     int (*set_tty_state) (struct serial *, serial_ttystate);
     void (*print_tty_state) (struct serial *, serial_ttystate,
 			     struct ui_file *);
-    int (*noflush_set_tty_state) (struct serial *, serial_ttystate,
-				  serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
     /* Set the value PARITY as parity setting for serial object.
-- 
2.5.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [pushed] Don't check termio.h and sgtty.h in common/common.m4 either (Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty)
  2017-11-06 16:11         ` Pedro Alves
@ 2017-11-06 16:31           ` Pedro Alves
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Alves @ 2017-11-06 16:31 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 11/06/2017 04:11 PM, Pedro Alves wrote:

> Here's what I'm pushing in, along with the rest of the series.

And (of course only...) after pushing I realized that gdb/config.in still
had the HAVE_TERMIO_H/HAVE_SGTTY_H templates.  Turns out that
I missed removing the header checks in common/common.m4.

I've pushed in the obvious follow up patch below.

From d1928160a324c1b6cd14afeecd4c81ab927883fa Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 6 Nov 2017 16:19:12 +0000
Subject: [PATCH] Don't check termio.h and sgtty.h in common/common.m4 either

common/common.m4 still had checks for termio.h/sgtty.h that are stale
now.  Remove them.

gdb/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* common/common.m4 (GDB_AC_COMMON): No longer check termio.h nor
	sgtty.h.
	* config.in, configure: Regenerate.

gdb/gdbserver/ChangeLog:
2017-11-06  Pedro Alves  <palves@redhat.com>

	* config.in, configure: Regenerate.
---
 gdb/ChangeLog           | 6 ++++++
 gdb/gdbserver/ChangeLog | 4 ++++
 gdb/common/common.m4    | 2 +-
 gdb/config.in           | 6 ------
 gdb/configure           | 2 +-
 gdb/gdbserver/config.in | 6 ------
 gdb/gdbserver/configure | 2 +-
 7 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 80caa43..7a90ea5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2017-11-06  Pedro Alves  <palves@redhat.com>
 
+	* common/common.m4 (GDB_AC_COMMON): No longer check termio.h nor
+	sgtty.h.
+	* config.in, configure: Regenerate.
+
+2017-11-06  Pedro Alves  <palves@redhat.com>
+
 	* event-top.c: Check SIGTSTP instead of STOP_SIGNAL thoughout.
 	(async_init_signals): Adjust.
 	(handle_stop_sig): Rename to ...
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index cb2e4d0..eaf6a68 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,7 @@
+2017-11-06  Pedro Alves  <palves@redhat.com>
+
+	* config.in, configure: Regenerate.
+
 2017-10-27  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* target.c (struct thread_search): Remove.
diff --git a/gdb/common/common.m4 b/gdb/common/common.m4
index 45726ab..7e701b6 100644
--- a/gdb/common/common.m4
+++ b/gdb/common/common.m4
@@ -29,7 +29,7 @@ AC_DEFUN([GDB_AC_COMMON], [
 		   sys/resource.h sys/socket.h sys/syscall.h dnl
 		   sys/un.h sys/wait.h dnl
 		   thread_db.h wait.h dnl
-		   termios.h termio.h sgtty.h)
+		   termios.h)
 
   AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction])
 
diff --git a/gdb/config.in b/gdb/config.in
index 3f8ee38..904c604 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -414,9 +414,6 @@
 /* Define to 1 if you have the `setsid' function. */
 #undef HAVE_SETSID
 
-/* Define to 1 if you have the <sgtty.h> header file. */
-#undef HAVE_SGTTY_H
-
 /* Define to 1 if you have the `sigaction' function. */
 #undef HAVE_SIGACTION
 
@@ -555,9 +552,6 @@
 /* Define to 1 if you have the <termios.h> header file. */
 #undef HAVE_TERMIOS_H
 
-/* Define to 1 if you have the <termio.h> header file. */
-#undef HAVE_TERMIO_H
-
 /* Define to 1 if you have the <term.h> header file. */
 #undef HAVE_TERM_H
 
diff --git a/gdb/configure b/gdb/configure
index c638652..def194d 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -13068,7 +13068,7 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
   fi
 
 
-  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h sys/syscall.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h termio.h sgtty.h
+  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h sys/syscall.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 5dacbac..4a2e778 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -205,9 +205,6 @@
 /* Define to 1 if you have the `setns' function. */
 #undef HAVE_SETNS
 
-/* Define to 1 if you have the <sgtty.h> header file. */
-#undef HAVE_SGTTY_H
-
 /* Define to 1 if you have the `sigaction' function. */
 #undef HAVE_SIGACTION
 
@@ -292,9 +289,6 @@
 /* Define to 1 if you have the <termios.h> header file. */
 #undef HAVE_TERMIOS_H
 
-/* Define to 1 if you have the <termio.h> header file. */
-#undef HAVE_TERMIO_H
-
 /* Define to 1 if you have the <thread_db.h> header file. */
 #undef HAVE_THREAD_DB_H
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index d5c62fb..ec032bc 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -6769,7 +6769,7 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
   fi
 
 
-  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h sys/syscall.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h termio.h sgtty.h
+  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h sys/syscall.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
-- 
2.5.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-11-06 16:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-02 15:12 [PATCH 0/3] Some terminal handling TCL Pedro Alves
2017-11-02 15:12 ` [PATCH 2/3] Don't set terminal flags twice in a row Pedro Alves
2017-11-02 18:34   ` Sergio Durigan Junior
2017-11-02 15:12 ` [PATCH 1/3] Assume termios is available, remove support for termio and sgtty Pedro Alves
2017-11-02 18:54   ` Sergio Durigan Junior
2017-11-02 19:27     ` Pedro Alves
2017-11-02 19:32       ` Sergio Durigan Junior
2017-11-06 16:11         ` Pedro Alves
2017-11-06 16:31           ` [pushed] Don't check termio.h and sgtty.h in common/common.m4 either (Re: [PATCH 1/3] Assume termios is available, remove support for termio and sgtty) Pedro Alves
2017-11-02 15:12 ` [PATCH 3/3] Eliminate STOP_SIGNAL, use SIGTSTP directly Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).