public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: Setting parity for remote serial
@ 2013-07-24 14:29 Yurij Grechishhev
  2013-07-24 16:53 ` Eli Zaretskii
  2013-09-26 17:00 ` Joel Brobecker
  0 siblings, 2 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2013-07-24 14:29 UTC (permalink / raw)
  To: gdb-patches

Updated patch for serial parity support:

diff -up ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog gdb/doc/ChangeLog
--- ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog  2013-07-10
21:55:24.921750052 +0400
+++ gdb/doc/ChangeLog   2013-07-16 18:46:31.425614819 +0400
@@ -1,3 +1,6 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+       * gdb.texinfo (Remote configuration): Document "set/show
+       remoteparity".
 2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Eli Zaretskii  <eliz@gnu.org>

diff -up ../../../gdb_old/gdb-7.6/gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo
--- ../../../gdb_old/gdb-7.6/gdb/doc/gdb.texinfo        2013-07-10
21:55:25.257751657 +0400
+++ gdb/doc/gdb.texinfo 2013-07-16 18:04:54.128738129 +0400
@@ -18168,6 +18168,13 @@ default is not to record at all.
 Show the current setting  of the file name on which to record the
 serial communications.

+@item set remoteparity @var{parity}
+Set the parity for the remote serial I/O. Supported values of @var{parity} are:
+@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
+
+@item show remoteparity
+Show the current parity of the serial port.
+
 @item set remotetimeout @var{num}
 @cindex timeout for serial communications
 @cindex remote timeout

diff -up ../../../gdb_old/gdb-7.6/gdb/ChangeLog gdb/ChangeLog
--- ../../../gdb_old/gdb-7.6/gdb/ChangeLog    2013-07-10
21:55:22.485750321 +0400
+++ gdb/ChangeLog    2013-07-16 17:33:47.467613587 +0400
@@ -1,3 +1,29 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+    * monitor.c (monitor_open): Add serial_setparity.
+    * remote.c (remote_open_1): Likewise.
+    * ser-base.c (ser_base_serparity): New function.
+    * ser-base.h: Add ser_base_setparity declaration.
+    * serail.c: Add serial_parity declaration and definitions of
+    parity_enums and parity.
+    (set_parity): New function.
+    (serial_setparity): New function.
+    (_initialize_serial): Add set/show remoteparity command description
+    * serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
+    definitions. Add serial_setparity declaration.
+    (serial_ops): Add setparity entry.
+    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
+    state.Parity definitions.
+    (ser_windows_setparity): New function.
+    (_initialize_ser_windows): ops->setparity setting.
+    * ser-pipe.c (_initialize_ser_pipe): Likewise.
+    * ser-tcp.c (_initialize_ser_tcp): Likewise.
+    * ser-unix.c: Add hardwire_setparity declaration.
+    (hardwire_setparity): New function.
+    (_initialize_ser_hardwire): ops->setparity setting.
+    * target.h: serial_parity declaration.
+    * top.c: serial_parity definition.
+
+
 2013-04-26  Joel Brobecker  <brobecker@adacore.com>

     * NEWS: Change "since GDB 7.5" into "in GDB 7.6".
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/cli and gdb/cli
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/common and gdb/common
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/config and gdb/config
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/contrib and gdb/contrib
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/data-directory and
gdb/data-directory
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/doc and gdb/doc
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/features and gdb/features
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/gdbserver and gdb/gdbserver
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/gnulib and gdb/gnulib
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/mi and gdb/mi
diff -up ../../../gdb_old/gdb-7.6/gdb/monitor.c gdb/monitor.c
--- ../../../gdb_old/gdb-7.6/gdb/monitor.c    2013-07-10
21:55:33.656750073 +0400
+++ gdb/monitor.c    2013-07-04 23:54:32.472595952 +0400
@@ -768,6 +768,7 @@ monitor_open (char *args, struct monitor
     }
     }

+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);

   serial_flush_input (monitor_desc);
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/po and gdb/po
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/python and gdb/python
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/regformats and
gdb/regformats
diff -up ../../../gdb_old/gdb-7.6/gdb/remote.c gdb/remote.c
--- ../../../gdb_old/gdb-7.6/gdb/remote.c    2013-07-10 21:55:34.645747970 +0400
+++ gdb/remote.c    2013-07-04 23:50:52.855721644 +0400
@@ -4256,6 +4256,7 @@ remote_open_1 (char *name, int from_tty,
     }
     }

+  serial_setparity(remote_desc, serial_parity);
   serial_raw (remote_desc);

   /* If there is something sitting in the buffer we might take it as a
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-base.c gdb/ser-base.c
--- ../../../gdb_old/gdb-7.6/gdb/ser-base.c    2013-07-10
21:55:24.161873687 +0400
+++ gdb/ser-base.c    2013-07-05 00:28:55.795720278 +0400
@@ -536,6 +536,14 @@ ser_base_setbaudrate (struct serial *scb
   return 0;            /* Never fails!  */
 }

+
+int
+ser_base_setparity (struct serial *scb, int num)
+{
+  return 0;            /* Never fails!  */
+}
+
+
 int
 ser_base_setstopbits (struct serial *scb, int num)
 {
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-base.h gdb/ser-base.h
--- ../../../gdb_old/gdb-7.6/gdb/ser-base.h    2013-07-10
21:55:24.168750025 +0400
+++ gdb/ser-base.h    2013-07-05 00:30:36.017596667 +0400
@@ -43,6 +43,7 @@ extern int ser_base_noflush_set_tty_stat
                        serial_ttystate old_ttystate);
 extern int ser_base_setbaudrate (struct serial *scb, int rate);
 extern int ser_base_setstopbits (struct serial *scb, int rate);
+extern int ser_base_setparity (struct serial *scb, int parity);
 extern int ser_base_drain_output (struct serial *scb);

 extern int ser_base_write (struct serial *scb, const char *str, int len);
diff -up ../../../gdb_old/gdb-7.6/gdb/serial.c gdb/serial.c
--- ../../../gdb_old/gdb-7.6/gdb/serial.c    2013-07-10 21:55:35.224750365 +0400
+++ gdb/serial.c    2013-07-10 20:41:31.899897384 +0400
@@ -26,6 +26,9 @@

 extern void _initialize_serial (void);

+/* Parity for serial port */
+extern int serial_parity;
+
 /* Is serial being debugged?  */

 static unsigned int global_serial_debug_p;
@@ -53,10 +56,29 @@ static const char logbase_ascii[] = "asc
 static const char *const logbase_enums[] =
 {logbase_hex, logbase_octal, logbase_ascii, NULL};
 static const char *serial_logbase = logbase_ascii;
-

 static int serial_current_type = 0;

+/* Parity for serial port */
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+{parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
+
 /* Log char CH of type CHTYPE, with TIMEOUT.  */

 /* Define bogus char to represent a BREAK.  Should be careful to choose a value
@@ -521,6 +543,12 @@ serial_setstopbits (struct serial *scb,
 }

 int
+serial_setparity (struct serial*scb, int parity)
+{
+  return scb->ops->setparity (scb, parity);
+}
+
+int
 serial_can_async_p (struct serial *scb)
 {
   return (scb->ops->async != NULL);
@@ -658,6 +686,15 @@ Show numerical base for remote session l
             NULL, /* FIXME: i18n: */
             &setlist, &showlist);

+  add_setshow_enum_cmd ("remoteparity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &setlist, &showlist);
+
+
   add_setshow_zuinteger_cmd ("serial", class_maintenance,
                  &global_serial_debug_p, _("\
 Set serial debugging."), _("\
diff -up ../../../gdb_old/gdb-7.6/gdb/serial.h gdb/serial.h
--- ../../../gdb_old/gdb-7.6/gdb/serial.h    2013-07-10 21:55:33.445749528 +0400
+++ gdb/serial.h    2013-07-10 20:17:17.705956716 +0400
@@ -177,6 +177,14 @@ extern int serial_noflush_set_tty_state

 extern int serial_setbaudrate (struct serial *scb, int rate);

+/* Set parity for serial port. Return 0 for success, -1 for failure */
+
+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Set the number of stop bits to the value specified.  Returns 0 for
    success, -1 for failure.  */

@@ -272,6 +280,7 @@ struct serial_ops
                   serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-mingw.c gdb/ser-mingw.c
--- ../../../gdb_old/gdb-7.6/gdb/ser-mingw.c    2013-07-10
21:55:24.185807109 +0400
+++ gdb/ser-mingw.c    2013-07-16 16:01:35.854613120 +0400
@@ -156,7 +156,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;

-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -166,7 +165,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;

   scb->current_timeout = 0;

@@ -202,6 +200,36 @@ ser_windows_setstopbits (struct serial *
 }

 static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      return 1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
+static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
   HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
@@ -1250,6 +1278,7 @@ _initialize_ser_windows (void)

   ops->go_raw = ser_windows_raw;
   ops->setbaudrate = ser_windows_setbaudrate;
+  ops->setparity = ser_windows_setparity;
   ops->setstopbits = ser_windows_setstopbits;
   ops->drain_output = ser_windows_drain_output;
   ops->readchar = ser_base_readchar;
@@ -1303,6 +1332,7 @@ _initialize_ser_windows (void)
   ops->print_tty_state = ser_base_print_tty_state;
   ops->noflush_set_tty_state = ser_base_noflush_set_tty_state;
   ops->setbaudrate = ser_base_setbaudrate;
+  ops->setparity = ser_base_setparity;
   ops->setstopbits = ser_base_setstopbits;
   ops->drain_output = ser_base_drain_output;
   ops->async = ser_base_async;
@@ -1338,6 +1368,7 @@ _initialize_ser_windows (void)
   ops->print_tty_state = ser_base_print_tty_state;
   ops->noflush_set_tty_state = ser_base_noflush_set_tty_state;
   ops->setbaudrate = ser_base_setbaudrate;
+  ops->setparity = ser_base_setparity;
   ops->setstopbits = ser_base_setstopbits;
   ops->drain_output = ser_base_drain_output;
   ops->async = ser_base_async;
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-pipe.c gdb/ser-pipe.c
--- ../../../gdb_old/gdb-7.6/gdb/ser-pipe.c    2013-07-10
21:55:24.185807109 +0400
+++ gdb/ser-pipe.c    2013-07-10 20:58:32.921749511 +0400
@@ -233,6 +233,7 @@ _initialize_ser_pipe (void)
   ops->print_tty_state = ser_base_print_tty_state;
   ops->noflush_set_tty_state = ser_base_noflush_set_tty_state;
   ops->setbaudrate = ser_base_setbaudrate;
+  ops->setparity = ser_base_setparity;
   ops->setstopbits = ser_base_setstopbits;
   ops->drain_output = ser_base_drain_output;
   ops->async = ser_base_async;
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-tcp.c gdb/ser-tcp.c
--- ../../../gdb_old/gdb-7.6/gdb/ser-tcp.c    2013-07-10
21:55:24.200748354 +0400
+++ gdb/ser-tcp.c    2013-07-05 00:33:53.026598227 +0400
@@ -396,6 +396,7 @@ _initialize_ser_tcp (void)
   ops->print_tty_state = ser_base_print_tty_state;
   ops->noflush_set_tty_state = ser_base_noflush_set_tty_state;
   ops->setbaudrate = ser_base_setbaudrate;
+  ops->setparity = ser_base_setparity;
   ops->setstopbits = ser_base_setstopbits;
   ops->drain_output = ser_base_drain_output;
   ops->async = ser_base_async;
diff -up ../../../gdb_old/gdb-7.6/gdb/ser-unix.c gdb/ser-unix.c
--- ../../../gdb_old/gdb-7.6/gdb/ser-unix.c    2013-07-10
21:55:24.229751815 +0400
+++ gdb/ser-unix.c    2013-07-16 16:05:07.242612139 +0400
@@ -99,6 +99,7 @@ static int hardwire_flush_output (struct
 static int hardwire_flush_input (struct serial *);
 static int hardwire_send_break (struct serial *);
 static int hardwire_setstopbits (struct serial *, int);
+static int hardwire_setparity (struct serial *, int);

 void _initialize_ser_hardwire (void);

@@ -893,6 +894,46 @@ hardwire_setstopbits (struct serial *scb
   return set_tty_state (scb, &state);
 }

+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      return 1;
+    }
+
+#ifdef HAVE_TERMIOS
+  state.termios.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_TERMIO
+  state.termio.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_SGTTY
+  return 0;            /* sgtty doesn't support this */
+#endif
+
+  return set_tty_state (scb, &state);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +970,7 @@ _initialize_ser_hardwire (void)
   ops->print_tty_state = hardwire_print_tty_state;
   ops->noflush_set_tty_state = hardwire_noflush_set_tty_state;
   ops->setbaudrate = hardwire_setbaudrate;
+  ops->setparity = hardwire_setparity;
   ops->setstopbits = hardwire_setstopbits;
   ops->drain_output = hardwire_drain_output;
   ops->async = ser_base_async;
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/stubs and gdb/stubs
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/syscalls and gdb/syscalls
diff -up ../../../gdb_old/gdb-7.6/gdb/target.h gdb/target.h
--- ../../../gdb_old/gdb-7.6/gdb/target.h    2013-07-10 21:55:36.818749395 +0400
+++ gdb/target.h    2013-07-05 00:36:15.025597655 +0400
@@ -1961,6 +1961,10 @@ extern int remote_debug;

 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;

Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/testsuite and gdb/testsuite
diff -up ../../../gdb_old/gdb-7.6/gdb/top.c gdb/top.c
--- ../../../gdb_old/gdb-7.6/gdb/top.c    2013-07-10 21:55:32.033750880 +0400
+++ gdb/top.c    2013-07-10 20:55:06.711827223 +0400
@@ -159,6 +159,9 @@ int server_command;

 int baud_rate = -1;

+/* Parity for serial port */
+int serial_parity = GDBPARITY_NONE;
+
 /* Timeout limit for response from target.  */

 /* The default value has been changed many times over the years.  It
Common subdirectories: ../../../gdb_old/gdb-7.6/gdb/tui and gdb/tui



-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

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

* Re: Setting parity for remote serial
  2013-07-24 14:29 Setting parity for remote serial Yurij Grechishhev
@ 2013-07-24 16:53 ` Eli Zaretskii
  2013-07-25  7:15   ` Yurij Grechishhev
  2013-09-26 17:00 ` Joel Brobecker
  1 sibling, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2013-07-24 16:53 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Date: Wed, 24 Jul 2013 18:29:11 +0400
> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
> 
> Updated patch for serial parity support:

Thanks.

> +++ gdb/doc/ChangeLog   2013-07-16 18:46:31.425614819 +0400
> @@ -1,3 +1,6 @@
> +2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
> +       * gdb.texinfo (Remote configuration): Document "set/show
> +       remoteparity".
>  2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
>             Eli Zaretskii  <eliz@gnu.org>

You need to leave an empty line between your ChangeLog entry and the
previous one.  Also, each line in ChangeLog should begin with TAB
character, not with spaces.

> +@item set remoteparity @var{parity}
> +Set the parity for the remote serial I/O. Supported values of @var{parity} are:
> +@code{even}, @code{none}, and @code{odd}. The default is @code{none}.

Two spaces between sentences, please.

The documentation part is okay with these changes.

What about NEWS?

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

* Re: Setting parity for remote serial
  2013-07-24 16:53 ` Eli Zaretskii
@ 2013-07-25  7:15   ` Yurij Grechishhev
  2013-07-25 16:21     ` Eli Zaretskii
  0 siblings, 1 reply; 23+ messages in thread
From: Yurij Grechishhev @ 2013-07-25  7:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Spaces in ChangeLog are due to the mail client. I could send the attachement.

--- ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog    2013-07-10
21:55:24.921750052 +0400
+++ gdb/doc/ChangeLog    2013-07-25 14:50:14.960811746 +0400
@@ -1,3 +1,8 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * gdb.texinfo (Remote configuration): Document "set/show
+    remoteparity".
+
 2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
         Eli Zaretskii  <eliz@gnu.org>


--- ../../../gdb_old/gdb-7.6/gdb/ChangeLog    2013-07-10
21:55:22.485750321 +0400
+++ gdb/ChangeLog    2013-07-25 14:24:03.806935947 +0400
@@ -1,3 +1,30 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * NEWS: Mention set/show remoteparity command.
+    * monitor.c (monitor_open): Add serial_setparity.
+    * remote.c (remote_open_1): Likewise.
+    * ser-base.c (ser_base_serparity): New function.
+    * ser-base.h: Add ser_base_setparity declaration.
+    * serail.c: Add serial_parity declaration and definitions of
+    parity_enums and parity.
+    (set_parity): New function.
+    (serial_setparity): New function.
+    (_initialize_serial): Add set/show remoteparity command description
+    * serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
+    definitions. Add serial_setparity declaration.
+    (serial_ops): Add setparity entry.
+    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
+    state.Parity definitions.
+    (ser_windows_setparity): New function.
+    (_initialize_ser_windows): ops->setparity setting.
+    * ser-pipe.c (_initialize_ser_pipe): Likewise.
+    * ser-tcp.c (_initialize_ser_tcp): Likewise.
+    * ser-unix.c: Add hardwire_setparity declaration.
+    (hardwire_setparity): New function.
+    (_initialize_ser_hardwire): ops->setparity setting.
+    * target.h: serial_parity declaration.
+    * top.c: serial_parity definition.
+
 2013-04-26  Joel Brobecker  <brobecker@adacore.com>

     * NEWS: Change "since GDB 7.5" into "in GDB 7.6".

--- ../../../gdb_old/gdb-7.6/gdb/doc/gdb.texinfo    2013-07-10
21:55:25.257751657 +0400
+++ gdb/doc/gdb.texinfo    2013-07-25 14:18:36.581811831 +0400
@@ -18168,6 +18168,13 @@ default is not to record at all.
 Show the current setting  of the file name on which to record the
 serial communications.

+@item set remoteparity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of
@var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show remoteparity
+Show the current parity of the serial port.
+
 @item set remotetimeout @var{num}
 @cindex timeout for serial communications
 @cindex remote timeout


--- ../../../gdb_old/gdb-7.6/gdb/NEWS    2013-07-10 21:55:32.402748483 +0400
+++ gdb/NEWS    2013-07-25 14:26:00.463811247 +0400
@@ -3,6 +3,10 @@

 *** Changes in GDB 7.6

+* GDB has two new commands: "set remoteparity odd|even|none" and
+  "show remoteparity". These allows to set or show parity for the
+  remote serial I/O.
+
 * Target record has been renamed to record-full.
   Record/replay is now enabled with the "record full" command.
   This also affects settings that are associated with full record/replay




-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

2013/7/24 Eli Zaretskii <eliz@gnu.org>:
>> Date: Wed, 24 Jul 2013 18:29:11 +0400
>> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
>>
>> Updated patch for serial parity support:
>
> Thanks.
>
>> +++ gdb/doc/ChangeLog   2013-07-16 18:46:31.425614819 +0400
>> @@ -1,3 +1,6 @@
>> +2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
>> +       * gdb.texinfo (Remote configuration): Document "set/show
>> +       remoteparity".
>>  2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
>>             Eli Zaretskii  <eliz@gnu.org>
>
> You need to leave an empty line between your ChangeLog entry and the
> previous one.  Also, each line in ChangeLog should begin with TAB
> character, not with spaces.
>
>> +@item set remoteparity @var{parity}
>> +Set the parity for the remote serial I/O. Supported values of @var{parity} are:
>> +@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
>
> Two spaces between sentences, please.
>
> The documentation part is okay with these changes.
>
> What about NEWS?



-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

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

* Re: Setting parity for remote serial
  2013-07-25  7:15   ` Yurij Grechishhev
@ 2013-07-25 16:21     ` Eli Zaretskii
       [not found]       ` <CAAyhtXRJaoxvfm7FH06AXeATgscXn4SrY5=ZD_h=BBmPoUdTBQ@mail.gmail.com>
  2013-07-29 19:04       ` Yurij Grechishhev
  0 siblings, 2 replies; 23+ messages in thread
From: Eli Zaretskii @ 2013-07-25 16:21 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Date: Thu, 25 Jul 2013 11:15:11 +0400
> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
> Cc: gdb-patches@sourceware.org
> 
> Spaces in ChangeLog are due to the mail client. I could send the attachement.

Well, maybe you should consider switching to another mail client,
then.  Attachments are okay, but generally less desirable.

>  *** Changes in GDB 7.6
> 
> +* GDB has two new commands: "set remoteparity odd|even|none" and
> +  "show remoteparity". These allows to set or show parity for the
> +  remote serial I/O.

Again, two spaces between sentences.

Otherwise, OK.

Thanks.

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

* Re: Setting parity for remote serial
       [not found]       ` <CAAyhtXRJaoxvfm7FH06AXeATgscXn4SrY5=ZD_h=BBmPoUdTBQ@mail.gmail.com>
@ 2013-07-29 18:34         ` Eli Zaretskii
  2013-07-29 19:25           ` Pedro Alves
  0 siblings, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2013-07-29 18:34 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Date: Mon, 29 Jul 2013 20:55:55 +0400
> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
> 
> Sorry for the mistakes. It's my first experience in gdb patching.
> Updated patch is in attachment.

Thanks.  But I only see the patches for the manual and NEWS, while the
ChangeLog entries describe a much larger set of changes.  Am I missing
something?

Also, please CC the mailing list on your messages, so that this
discussion gets archoved.

> Gmail web-client and Mozilla Thunderbird are not the best mail clients
> for sending patches. Which mail client do you use?

I use Emacs.

> Will you add my changes to the gdb CVS?

I don't see your copyright assignment on file, do you have one?
Without an assignment, there's a limit to the size of the changes we
can accept, and I think your contribution is above the limit.

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

* Re: Setting parity for remote serial
  2013-07-25 16:21     ` Eli Zaretskii
       [not found]       ` <CAAyhtXRJaoxvfm7FH06AXeATgscXn4SrY5=ZD_h=BBmPoUdTBQ@mail.gmail.com>
@ 2013-07-29 19:04       ` Yurij Grechishhev
  1 sibling, 0 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2013-07-29 19:04 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

Updated patch is in attachment.

2013/7/25 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 25 Jul 2013 11:15:11 +0400
>> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
>> Cc: gdb-patches@sourceware.org
>>
>> Spaces in ChangeLog are due to the mail client. I could send the attachement.
>
> Well, maybe you should consider switching to another mail client,
> then.  Attachments are okay, but generally less desirable.
>
>>  *** Changes in GDB 7.6
>>
>> +* GDB has two new commands: "set remoteparity odd|even|none" and
>> +  "show remoteparity". These allows to set or show parity for the
>> +  remote serial I/O.
>
> Again, two spaces between sentences.
>
> Otherwise, OK.
>
> Thanks.



-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

[-- Attachment #2: serialparity.patch --]
[-- Type: application/octet-stream, Size: 3023 bytes --]

--- ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog	2013-07-10 21:55:24.921750052 +0400
+++ gdb/doc/ChangeLog	2013-07-25 14:50:14.960811746 +0400
@@ -1,3 +1,8 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+	
+	* gdb.texinfo (Remote configuration): Document "set/show
+	remoteparity".
+	
 2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
 	    Eli Zaretskii  <eliz@gnu.org>
 

--- ../../../gdb_old/gdb-7.6/gdb/ChangeLog	2013-07-10 21:55:22.485750321 +0400
+++ gdb/ChangeLog	2013-07-25 14:24:03.806935947 +0400
@@ -1,3 +1,30 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* NEWS: Mention set/show remoteparity command.
+	* monitor.c (monitor_open): Add serial_setparity.
+	* remote.c (remote_open_1): Likewise.
+	* ser-base.c (ser_base_serparity): New function.
+	* ser-base.h: Add ser_base_setparity declaration.
+	* serail.c: Add serial_parity declaration and definitions of
+	parity_enums and parity.
+	(set_parity): New function.
+	(serial_setparity): New function.
+	(_initialize_serial): Add set/show remoteparity command description
+	* serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
+	definitions. Add serial_setparity declaration.
+	(serial_ops): Add setparity entry.
+	* ser-mingw.c (ser_windows_raw): Remove state.fParity and
+	state.Parity definitions.
+	(ser_windows_setparity): New function.
+	(_initialize_ser_windows): ops->setparity setting.
+	* ser-pipe.c (_initialize_ser_pipe): Likewise.
+	* ser-tcp.c (_initialize_ser_tcp): Likewise.
+	* ser-unix.c: Add hardwire_setparity declaration.
+	(hardwire_setparity): New function.
+	(_initialize_ser_hardwire): ops->setparity setting.
+	* target.h: serial_parity declaration.
+	* top.c: serial_parity definition.
+
 2013-04-26  Joel Brobecker  <brobecker@adacore.com>
 
 	* NEWS: Change "since GDB 7.5" into "in GDB 7.6".


--- ../../../gdb_old/gdb-7.6/gdb/doc/gdb.texinfo	2013-07-10 21:55:25.257751657 +0400
+++ gdb/doc/gdb.texinfo	2013-07-25 14:18:36.581811831 +0400
@@ -18168,6 +18168,13 @@ default is not to record at all.
 Show the current setting  of the file name on which to record the
 serial communications.
 
+@item set remoteparity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of @var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show remoteparity
+Show the current parity of the serial port.
+
 @item set remotetimeout @var{num}
 @cindex timeout for serial communications
 @cindex remote timeout

--- ../../../gdb_old/gdb-7.6/gdb/NEWS	2013-07-10 21:55:32.402748483 +0400
+++ gdb/NEWS	2013-07-30 00:16:28.440596874 +0400
@@ -3,6 +3,10 @@
 
 *** Changes in GDB 7.6
 
+* GDB has two new commands: "set remoteparity odd|even|none" and 
+  "show remoteparity".  These allows to set or show parity for the 
+  remote serial I/O.
+
 * Target record has been renamed to record-full.
   Record/replay is now enabled with the "record full" command.
   This also affects settings that are associated with full record/replay


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

* Re: Setting parity for remote serial
  2013-07-29 18:34         ` Eli Zaretskii
@ 2013-07-29 19:25           ` Pedro Alves
  2013-07-29 20:14             ` Yurij Grechishhev
  0 siblings, 1 reply; 23+ messages in thread
From: Pedro Alves @ 2013-07-29 19:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Yurij Grechishhev, gdb-patches

On 07/29/2013 07:33 PM, Eli Zaretskii wrote:
>> > Gmail web-client and Mozilla Thunderbird are not the best mail clients
>> > for sending patches. Which mail client do you use?

See this on how to teach Thunderbird (and others) to not suck for
sending patches:

http://sourceware.org/gdb/wiki/ContributionChecklist#Submitting_patches

-- 
Pedro Alves

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

* Re: Setting parity for remote serial
  2013-07-29 19:25           ` Pedro Alves
@ 2013-07-29 20:14             ` Yurij Grechishhev
  0 siblings, 0 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2013-07-29 20:14 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Thanks, it's the real goods.

2013/7/29 Pedro Alves <palves@redhat.com>:
> On 07/29/2013 07:33 PM, Eli Zaretskii wrote:
>>> > Gmail web-client and Mozilla Thunderbird are not the best mail clients
>>> > for sending patches. Which mail client do you use?
>
> See this on how to teach Thunderbird (and others) to not suck for
> sending patches:
>
> http://sourceware.org/gdb/wiki/ContributionChecklist#Submitting_patches
>
> --
> Pedro Alves
>



-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

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

* Re: Setting parity for remote serial
  2013-07-24 14:29 Setting parity for remote serial Yurij Grechishhev
  2013-07-24 16:53 ` Eli Zaretskii
@ 2013-09-26 17:00 ` Joel Brobecker
  2013-10-02 21:59   ` Yurij Grechishhev
       [not found]   ` <CAAyhtXTmrJ04BVhziaFnogGyWLz7+G+Qwbc9UnHJkrEbDgTjFw@mail.gmail.com>
  1 sibling, 2 replies; 23+ messages in thread
From: Joel Brobecker @ 2013-09-26 17:00 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Updated patch for serial parity support:
> 
> diff -up ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog gdb/doc/ChangeLog
> --- ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog  2013-07-10
> 21:55:24.921750052 +0400
> +++ gdb/doc/ChangeLog   2013-07-16 18:46:31.425614819 +0400
> @@ -1,3 +1,6 @@
> +2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
> +       * gdb.texinfo (Remote configuration): Document "set/show
> +       remoteparity".
>  2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
>             Eli Zaretskii  <eliz@gnu.org>

Any update on this patch? We just came across a platform where
such a feature would be useful?

Looking at the patch itself, I can see some trivial issues with
coding style. But before going into re-basing it for the current
head, and working on cleaning it up, I don't see you on file at
the FSF regarding copyright assignment. What's the status on this?

Thank you,
-- 
Joel

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

* Re: Setting parity for remote serial
  2013-09-26 17:00 ` Joel Brobecker
@ 2013-10-02 21:59   ` Yurij Grechishhev
       [not found]   ` <CAAyhtXTmrJ04BVhziaFnogGyWLz7+G+Qwbc9UnHJkrEbDgTjFw@mail.gmail.com>
  1 sibling, 0 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2013-10-02 21:59 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

> Any update on this patch?
No updates

> I don't see you on file at the FSF regarding copyright assignment. What's the status on this?
I think, assignment/disclaimer process with the FSF is currently complete.

2013/9/26 Joel Brobecker <brobecker@adacore.com>:
>> Updated patch for serial parity support:
>>
>> diff -up ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog gdb/doc/ChangeLog
>> --- ../../../gdb_old/gdb-7.6/gdb/doc/ChangeLog  2013-07-10
>> 21:55:24.921750052 +0400
>> +++ gdb/doc/ChangeLog   2013-07-16 18:46:31.425614819 +0400
>> @@ -1,3 +1,6 @@
>> +2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
>> +       * gdb.texinfo (Remote configuration): Document "set/show
>> +       remoteparity".
>>  2013-04-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
>>             Eli Zaretskii  <eliz@gnu.org>
>
> Any update on this patch? We just came across a platform where
> such a feature would be useful?
>
> Looking at the patch itself, I can see some trivial issues with
> coding style. But before going into re-basing it for the current
> head, and working on cleaning it up, I don't see you on file at
> the FSF regarding copyright assignment. What's the status on this?
>
> Thank you,
> --
> Joel



-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

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

* Re: Setting parity for remote serial
       [not found]   ` <CAAyhtXTmrJ04BVhziaFnogGyWLz7+G+Qwbc9UnHJkrEbDgTjFw@mail.gmail.com>
@ 2013-10-04  7:34     ` Joel Brobecker
  2013-10-09  4:11       ` Joel Brobecker
  2015-02-25 15:16       ` Joel Brobecker
  0 siblings, 2 replies; 23+ messages in thread
From: Joel Brobecker @ 2013-10-04  7:34 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

Thanks for your reply, Yurij.

> > Any update on this patch?
> No updates

Is there anything I can do to help this patch come through? I was
under the impression that it had stalled waiting for your assignment
to come through.

> > I don't see you on file at the FSF regarding copyright assignment. What's
> the status on this?
> I think, assignment/disclaimer process with the FSF is currently complete.

I had actually searched the records prior to sending the question.
Was the assignment done under a different name or maybe under a
university or employer's name?

Thank you,
-- 
Joel

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

* Re: Setting parity for remote serial
  2013-10-04  7:34     ` Joel Brobecker
@ 2013-10-09  4:11       ` Joel Brobecker
  2015-02-25 15:16       ` Joel Brobecker
  1 sibling, 0 replies; 23+ messages in thread
From: Joel Brobecker @ 2013-10-09  4:11 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> > I think, assignment/disclaimer process with the FSF is currently
> > complete.

For the record, I can confirm that Yurij's assignment is complete,
as we did receive a notification from the FSF about it back in
September.

I still cannot find his entry in the FSF records, however, and I have
sent a message to the FSF about that. But, in the meantime, we should
be able to accept Yurij's contributions.

-- 
Joel

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

* Re: Setting parity for remote serial
  2013-10-04  7:34     ` Joel Brobecker
  2013-10-09  4:11       ` Joel Brobecker
@ 2015-02-25 15:16       ` Joel Brobecker
  2015-02-26 19:50         ` Yurij Grechishhev
  1 sibling, 1 reply; 23+ messages in thread
From: Joel Brobecker @ 2015-02-25 15:16 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

Hello,

On Fri, Oct 04, 2013 at 09:34:47AM +0200, Joel Brobecker wrote:
> Thanks for your reply, Yurij.
> 
> > > Any update on this patch?
> > No updates
> 
> Is there anything I can do to help this patch come through? I was
> under the impression that it had stalled waiting for your assignment
> to come through.
> 
> > > I don't see you on file at the FSF regarding copyright assignment. What's
> > the status on this?
> > I think, assignment/disclaimer process with the FSF is currently complete.
> 
> I had actually searched the records prior to sending the question.
> Was the assignment done under a different name or maybe under a
> university or employer's name?

This is a feature that we would like to have. Unfortunately, since
we lost contact with Yurij, unless we hear from him again, we will
ask someone at AdaCore who hasn't seen the patch to implement
a similar feature. Once we have that, we'll contribute it here.

-- 
Joel

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

* Re: Setting parity for remote serial
  2015-02-25 15:16       ` Joel Brobecker
@ 2015-02-26 19:50         ` Yurij Grechishhev
  2015-02-27  8:16           ` Joel Brobecker
  0 siblings, 1 reply; 23+ messages in thread
From: Yurij Grechishhev @ 2015-02-26 19:50 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Hi Joel,
Glad to hear that this patch is still needed.
I believe, all questions with FSF copyright assignments had been resolved?
Please, let me know what I should do to complete this contribution.

Thank you

WBR,
Yury

2015-02-25 19:16 GMT+04:00 Joel Brobecker <brobecker@adacore.com>:
> Hello,
>
> On Fri, Oct 04, 2013 at 09:34:47AM +0200, Joel Brobecker wrote:
>> Thanks for your reply, Yurij.
>>
>> > > Any update on this patch?
>> > No updates
>>
>> Is there anything I can do to help this patch come through? I was
>> under the impression that it had stalled waiting for your assignment
>> to come through.
>>
>> > > I don't see you on file at the FSF regarding copyright assignment. What's
>> > the status on this?
>> > I think, assignment/disclaimer process with the FSF is currently complete.
>>
>> I had actually searched the records prior to sending the question.
>> Was the assignment done under a different name or maybe under a
>> university or employer's name?
>
> This is a feature that we would like to have. Unfortunately, since
> we lost contact with Yurij, unless we hear from him again, we will
> ask someone at AdaCore who hasn't seen the patch to implement
> a similar feature. Once we have that, we'll contribute it here.
>
> --
> Joel

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

* Re: Setting parity for remote serial
  2015-02-26 19:50         ` Yurij Grechishhev
@ 2015-02-27  8:16           ` Joel Brobecker
  2015-03-15 21:49             ` Yurij Grechishhev
  0 siblings, 1 reply; 23+ messages in thread
From: Joel Brobecker @ 2015-02-27  8:16 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Glad to hear that this patch is still needed.
> I believe, all questions with FSF copyright assignments had been resolved?
> Please, let me know what I should do to complete this contribution.

Indeed! Thanks very much for doing that.

If you could rebase the patch against master, and resubmit,
I promise to review it promptly (I will taking a week off
Mar 07-15, though). If you'd rather I took it over, I will
try to do so after I come back.

Thanks again!
-- 
Joel

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

* Re: Setting parity for remote serial
  2015-02-27  8:16           ` Joel Brobecker
@ 2015-03-15 21:49             ` Yurij Grechishhev
  2015-03-16  3:32               ` Eli Zaretskii
  2015-03-17 14:56               ` Joel Brobecker
  0 siblings, 2 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2015-03-15 21:49 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 13976 bytes --]

Hello Joel,
I kindly ask you to review this patch. Please, let me know in the case
I have missed something.
I see, you've reworked the command for baudrate setting.
Parity is set the same way now: set/show serial parity.

Thank you.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 65a0051..7b88708 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,34 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * NEWS: Mention set/show serial parity command.
+    * monitor.c (monitor_open): Add serial_setparity.
+    * remote.c (remote_open_1): Likewise.
+    * ser-base.c (ser_base_serparity): New function.
+    * ser-base.h: Add ser_base_setparity declaration.
+    * serail.c: Add serial_parity declaration and definitions of
+    parity_enums and parity.
+    (serial_parity): Definition
+    (set_parity): New function.
+    (serial_setparity): New function.
+    (_initialize_serial): Add set/show serial parity command description
+    * serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
+    definitions. Add serial_setparity declaration.
+    (serial_ops): Add setparity entry.
+    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
+    state.Parity definitions.
+    (ser_windows_setparity): New function.
+    (hardwire_ops): add ser_windows_setparity.
+    (tty_ops): add NULL for setparity field
+    (pipe_ops): add ser_base_setparity.
+    (tcp_ops): add ser_base_setparity.
+    * ser-pipe.c (pipe_ops): Likewise.
+    * ser-tcp.c (tcp_ops): Likewise.
+    * ser-unix.c: Add hardwire_setparity declaration.
+    (hardwire_setparity): New function.
+    (hardwire_ops): add hardwire_setparity.
+    * ser-go32.c (dos_ops): add dos_noop
+    * target.h: serial_parity declaration.
+
 2014-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

     Remove HPUX.
diff --git a/gdb/NEWS b/gdb/NEWS
index f08f972..cd2e82b3 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@

 *** Changes since GDB 7.9

+* GDB has two new commands: "set serial parity odd|even|none" and
+  "show serial parity".  These allows to set or show parity for the
+  remote serial I/O.
+
 * The "info source" command now displays the producer string if it was
   present in the debug info.  This typically includes the compiler version
   and may include things like its command line arguments.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5efb060..dd601fe 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * gdb.texinfo (Remote configuration): Document "set/show
+    serial parity command".
+
 2015-03-11  Gary Benson <gbenson@redhat.com>

     * gdb.texinfo (Remote Configuration): Document the
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9e71642..a818d58 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19443,6 +19443,13 @@ remote targets.
 @item show serial baud
 Show the current speed of the remote connection.

+@item set serial parity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of
@var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show serial parity
+Show the current parity of the serial port.
+
 @item set remotebreak
 @cindex interrupt remote programs
 @cindex BREAK signal instead of Ctrl-C
diff --git a/gdb/monitor.c b/gdb/monitor.c
index b040ec4..548dae3 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops
*mon_ops, int from_tty)
     }
     }

+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);

   serial_flush_input (monitor_desc);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9aaee13..1554259 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4310,6 +4310,7 @@ remote_open_1 (const char *name, int from_tty,
     }
     }

+  serial_setparity(rs->remote_desc, serial_parity);
   serial_raw (rs->remote_desc);

   /* If there is something sitting in the buffer we might take it as a
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 87817c4..93aad40 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -541,6 +541,12 @@ ser_base_setstopbits (struct serial *scb, int num)
   return 0;            /* Never fails!  */
 }

+int
+ser_base_setparity (struct serial *scb, int parity)
+{
+  return 0;            /* Never fails!  */
+}
+
 /* Put the SERIAL device into/out-of ASYNC mode.  */

 void
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 2aba66d..bb1c51d 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -42,7 +42,8 @@ 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 rate);
+extern int ser_base_setstopbits (struct serial *scb, int num);
+extern int ser_base_setparity (struct serial *scb, int parity);
 extern int ser_base_drain_output (struct serial *scb);

 extern int ser_base_write (struct serial *scb, const void *buf, size_t count);
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 6bf1b4e..bbcf6af 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -864,6 +864,7 @@ static const struct serial_ops dos_ops =
   dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
+  dos_noop,
   dos_noop,            /* Wait for output to drain.  */
   (void (*)(struct serial *, int))NULL    /* Change into async mode.  */
 };
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7f335e9..be0f990 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;

-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;

   scb->current_timeout = 0;

@@ -199,6 +197,36 @@ ser_windows_setstopbits (struct serial *scb, int num)
 }

 static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      return 1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
+static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
   HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
@@ -1227,6 +1255,7 @@ static const struct serial_ops hardwire_ops =
   ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
+  ser_windows_setparity,
   ser_windows_drain_output,
   ser_base_async,
   ser_windows_read_prim,
@@ -1257,6 +1286,7 @@ static const struct serial_ops tty_ops =
   ser_base_noflush_set_tty_state,
   NULL,
   NULL,
+  NULL,
   ser_base_drain_output,
   NULL,
   NULL,
@@ -1287,6 +1317,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   pipe_windows_read,
@@ -1317,6 +1348,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index bf5e4d4..0700132 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -224,6 +224,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 9c3dcf4..35512e6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -394,6 +394,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 4125797..88c16ba 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -83,6 +83,7 @@ static int hardwire_readchar (struct serial *scb,
int timeout);
 static int do_hardwire_readchar (struct serial *scb, int timeout);
 static int rate_to_code (int rate);
 static int hardwire_setbaudrate (struct serial *scb, int rate);
+static int hardwire_setparity (struct serial *scb, int parity);
 static void hardwire_close (struct serial *scb);
 static int get_tty_state (struct serial *scb,
               struct hardwire_ttystate * state);
@@ -893,6 +894,46 @@ hardwire_setstopbits (struct serial *scb, int num)
   return set_tty_state (scb, &state);
 }

+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      return 1;
+    }
+
+#ifdef HAVE_TERMIOS
+  state.termios.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_TERMIO
+  state.termio.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_SGTTY
+  return 0;            /* sgtty doesn't support this */
+#endif
+
+  return set_tty_state (scb, &state);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +970,7 @@ static const struct serial_ops hardwire_ops =
   hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
+  hardwire_setparity,
   hardwire_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/serial.c b/gdb/serial.c
index b7e620d..09c8b8d 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -525,6 +525,12 @@ serial_setstopbits (struct serial *scb, int num)
 }

 int
+serial_setparity (struct serial*scb, int parity)
+{
+    return scb->ops->setparity (scb, parity);
+}
+
+int
 serial_can_async_p (struct serial *scb)
 {
   return (scb->ops->async != NULL);
@@ -638,6 +644,27 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty,
             value);
 }

+/* Parity for serial port */
+int serial_parity = GDBPARITY_NONE;
+
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+{parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
 void
 _initialize_serial (void)
 {
@@ -670,6 +697,14 @@ using remote targets."),
                 serial_baud_show_cmd,
                 &serial_set_cmdlist, &serial_show_cmdlist);

+  add_setshow_enum_cmd ("parity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &serial_set_cmdlist, &serial_show_cmdlist);
+
   add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
 Set filename for remote session recording."), _("\
 Show filename for remote session recording."), _("\
diff --git a/gdb/serial.h b/gdb/serial.h
index 9eb1c39..0481ea1 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -186,6 +186,14 @@ extern int serial_setbaudrate (struct serial
*scb, int rate);

 extern int serial_setstopbits (struct serial *scb, int num);

+/* Set parity for serial port. Return 0 for success, -1 for failure */
+
+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Asynchronous serial interface: */

 /* Can the serial device support asynchronous mode?  */
@@ -271,6 +279,7 @@ struct serial_ops
                   serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff --git a/gdb/target.h b/gdb/target.h
index c95e1a4..685a37f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2236,6 +2236,10 @@ extern int remote_debug;

 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;


--
WBR,
Yury

2015-02-27 11:16 GMT+03:00 Joel Brobecker <brobecker@adacore.com>:
>> Glad to hear that this patch is still needed.
>> I believe, all questions with FSF copyright assignments had been resolved?
>> Please, let me know what I should do to complete this contribution.
>
> Indeed! Thanks very much for doing that.
>
> If you could rebase the patch against master, and resubmit,
> I promise to review it promptly (I will taking a week off
> Mar 07-15, though). If you'd rather I took it over, I will
> try to do so after I come back.
>
> Thanks again!
> --
> Joel

[-- Attachment #2: parity.patch --]
[-- Type: text/x-patch, Size: 12986 bytes --]

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 65a0051..7b88708 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,34 @@
+2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* NEWS: Mention set/show serial parity command.
+	* monitor.c (monitor_open): Add serial_setparity.
+	* remote.c (remote_open_1): Likewise.
+	* ser-base.c (ser_base_serparity): New function.
+	* ser-base.h: Add ser_base_setparity declaration.
+	* serail.c: Add serial_parity declaration and definitions of
+	parity_enums and parity.
+	(serial_parity): Definition
+	(set_parity): New function.
+	(serial_setparity): New function.
+	(_initialize_serial): Add set/show serial parity command description
+	* serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
+	definitions. Add serial_setparity declaration.
+	(serial_ops): Add setparity entry.
+	* ser-mingw.c (ser_windows_raw): Remove state.fParity and
+	state.Parity definitions.
+	(ser_windows_setparity): New function.
+	(hardwire_ops): add ser_windows_setparity.
+	(tty_ops): add NULL for setparity field
+	(pipe_ops): add ser_base_setparity.
+	(tcp_ops): add ser_base_setparity.
+	* ser-pipe.c (pipe_ops): Likewise.
+	* ser-tcp.c (tcp_ops): Likewise.
+	* ser-unix.c: Add hardwire_setparity declaration.
+	(hardwire_setparity): New function.
+	(hardwire_ops): add hardwire_setparity.
+	* ser-go32.c (dos_ops): add dos_noop
+	* target.h: serial_parity declaration.
+
 2014-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	Remove HPUX.
diff --git a/gdb/NEWS b/gdb/NEWS
index f08f972..cd2e82b3 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
 
 *** Changes since GDB 7.9
 
+* GDB has two new commands: "set serial parity odd|even|none" and
+  "show serial parity".  These allows to set or show parity for the
+  remote serial I/O.
+
 * The "info source" command now displays the producer string if it was
   present in the debug info.  This typically includes the compiler version
   and may include things like its command line arguments.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5efb060..dd601fe 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* gdb.texinfo (Remote configuration): Document "set/show
+	serial parity command".
+
 2015-03-11  Gary Benson <gbenson@redhat.com>
 
 	* gdb.texinfo (Remote Configuration): Document the
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9e71642..a818d58 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19443,6 +19443,13 @@ remote targets.
 @item show serial baud
 Show the current speed of the remote connection.
 
+@item set serial parity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of @var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show serial parity
+Show the current parity of the serial port.
+
 @item set remotebreak
 @cindex interrupt remote programs
 @cindex BREAK signal instead of Ctrl-C
diff --git a/gdb/monitor.c b/gdb/monitor.c
index b040ec4..548dae3 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops *mon_ops, int from_tty)
 	}
     }
 
+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);
 
   serial_flush_input (monitor_desc);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9aaee13..1554259 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4310,6 +4310,7 @@ remote_open_1 (const char *name, int from_tty,
 	}
     }
 
+  serial_setparity(rs->remote_desc, serial_parity);
   serial_raw (rs->remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 87817c4..93aad40 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -541,6 +541,12 @@ ser_base_setstopbits (struct serial *scb, int num)
   return 0;			/* Never fails!  */
 }
 
+int
+ser_base_setparity (struct serial *scb, int parity)
+{
+  return 0;			/* Never fails!  */
+}
+
 /* Put the SERIAL device into/out-of ASYNC mode.  */
 
 void
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 2aba66d..bb1c51d 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -42,7 +42,8 @@ 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 rate);
+extern int ser_base_setstopbits (struct serial *scb, int num);
+extern int ser_base_setparity (struct serial *scb, int parity);
 extern int ser_base_drain_output (struct serial *scb);
 
 extern int ser_base_write (struct serial *scb, const void *buf, size_t count);
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 6bf1b4e..bbcf6af 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -864,6 +864,7 @@ static const struct serial_ops dos_ops =
   dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
+  dos_noop,
   dos_noop,			/* Wait for output to drain.  */
   (void (*)(struct serial *, int))NULL	/* Change into async mode.  */
 };
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7f335e9..be0f990 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;
 
-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;
 
   scb->current_timeout = 0;
 
@@ -199,6 +197,36 @@ ser_windows_setstopbits (struct serial *scb, int num)
 }
 
 static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      return 1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
+static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
   HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
@@ -1227,6 +1255,7 @@ static const struct serial_ops hardwire_ops =
   ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
+  ser_windows_setparity,
   ser_windows_drain_output,
   ser_base_async,
   ser_windows_read_prim,
@@ -1257,6 +1286,7 @@ static const struct serial_ops tty_ops =
   ser_base_noflush_set_tty_state,
   NULL,
   NULL,
+  NULL,
   ser_base_drain_output,
   NULL,
   NULL,
@@ -1287,6 +1317,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   pipe_windows_read,
@@ -1317,6 +1348,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index bf5e4d4..0700132 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -224,6 +224,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 9c3dcf4..35512e6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -394,6 +394,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 4125797..88c16ba 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -83,6 +83,7 @@ static int hardwire_readchar (struct serial *scb, int timeout);
 static int do_hardwire_readchar (struct serial *scb, int timeout);
 static int rate_to_code (int rate);
 static int hardwire_setbaudrate (struct serial *scb, int rate);
+static int hardwire_setparity (struct serial *scb, int parity);
 static void hardwire_close (struct serial *scb);
 static int get_tty_state (struct serial *scb,
 			  struct hardwire_ttystate * state);
@@ -893,6 +894,46 @@ hardwire_setstopbits (struct serial *scb, int num)
   return set_tty_state (scb, &state);
 }
 
+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      return 1;
+    }
+
+#ifdef HAVE_TERMIOS
+  state.termios.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_TERMIO
+  state.termio.c_cflag |= newparity;
+#endif
+
+#ifdef HAVE_SGTTY
+  return 0;            /* sgtty doesn't support this */
+#endif
+
+  return set_tty_state (scb, &state);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +970,7 @@ static const struct serial_ops hardwire_ops =
   hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
+  hardwire_setparity,
   hardwire_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/serial.c b/gdb/serial.c
index b7e620d..09c8b8d 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -525,6 +525,12 @@ serial_setstopbits (struct serial *scb, int num)
 }
 
 int
+serial_setparity (struct serial*scb, int parity)
+{
+    return scb->ops->setparity (scb, parity);
+}
+
+int
 serial_can_async_p (struct serial *scb)
 {
   return (scb->ops->async != NULL);
@@ -638,6 +644,27 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty,
 		    value);
 }
 
+/* Parity for serial port */
+int serial_parity = GDBPARITY_NONE;
+
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+{parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
 void
 _initialize_serial (void)
 {
@@ -670,6 +697,14 @@ using remote targets."),
 			    serial_baud_show_cmd,
 			    &serial_set_cmdlist, &serial_show_cmdlist);
 
+  add_setshow_enum_cmd ("parity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &serial_set_cmdlist, &serial_show_cmdlist);
+
   add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
 Set filename for remote session recording."), _("\
 Show filename for remote session recording."), _("\
diff --git a/gdb/serial.h b/gdb/serial.h
index 9eb1c39..0481ea1 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -186,6 +186,14 @@ extern int serial_setbaudrate (struct serial *scb, int rate);
 
 extern int serial_setstopbits (struct serial *scb, int num);
 
+/* Set parity for serial port. Return 0 for success, -1 for failure */
+
+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Asynchronous serial interface: */
 
 /* Can the serial device support asynchronous mode?  */
@@ -271,6 +279,7 @@ struct serial_ops
 				  serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff --git a/gdb/target.h b/gdb/target.h
index c95e1a4..685a37f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2236,6 +2236,10 @@ extern int remote_debug;
 
 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;
 

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

* Re: Setting parity for remote serial
  2015-03-15 21:49             ` Yurij Grechishhev
@ 2015-03-16  3:32               ` Eli Zaretskii
  2015-03-17 14:56               ` Joel Brobecker
  1 sibling, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2015-03-16  3:32 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: brobecker, gdb-patches

> Date: Mon, 16 Mar 2015 00:49:33 +0300
> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
> Cc: gdb-patches@sourceware.org
> 
> I kindly ask you to review this patch. Please, let me know in the case
> I have missed something.
> I see, you've reworked the command for baudrate setting.
> Parity is set the same way now: set/show serial parity.

Thanks, the documentation parts are OK.

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

* Re: Setting parity for remote serial
  2015-03-15 21:49             ` Yurij Grechishhev
  2015-03-16  3:32               ` Eli Zaretskii
@ 2015-03-17 14:56               ` Joel Brobecker
  2015-03-22 22:52                 ` Yurij Grechishhev
  1 sibling, 1 reply; 23+ messages in thread
From: Joel Brobecker @ 2015-03-17 14:56 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

Yurij,

Below are my commends regarding your patch.

You'll see that I have a lot of comments, but they are very minor and
the patch essentially looks fine to me. Please forgive me if it feels
like I am nitpicking - GDB has a fairly complex coding style, which
is mostly dictated by the fact that it is part of the GNU project and
therefore following the GNU Coding Style (and then some).

Also, it would be useful for you to confirm that this patch is on top
of master, and on which platform you tested this patch (I assume that
you tested it by running the testsuite before and after your change).

Thank you!

> +2013-07-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
> +
> +    * NEWS: Mention set/show serial parity command.
> +    * monitor.c (monitor_open): Add serial_setparity.

"Add" was a little confusing to me. How about "Call serial_setparity"?

> +    * remote.c (remote_open_1): Likewise.
> +    * ser-base.c (ser_base_serparity): New function.
> +    * ser-base.h: Add ser_base_setparity declaration.

        * ser-base.h (ser_base_setparity): Add declaration.

> +    * serail.c: Add serial_parity declaration and definitions of
> +    parity_enums and parity.
> +    (serial_parity): Definition
> +    (set_parity): New function.
> +    (serial_setparity): New function.
> +    (_initialize_serial): Add set/show serial parity command description

typo: "serail.c" -> "serial.c"

Same remark as above in terms of how the entry should be formatted.
It also seems like the contents is a bit out of order with respect
to the diff, making it hard to double-check it. I suggest:

        * serial.c (serial_parity): New function.
        (serial_parity): New global.
        (parity_none, parity_odd, parity_even, parity_enums, parity):
        New static globals.
        (set_parity): New function.
        (_initialize_serial): Add set/show serial parity commands.

Also, the last comment on the ChangeLog entry is that sentences should
start with a capital letter, and end with a period.

Can you adjust the rest of the ChangeLog entry using the above
guidelines, please?

> +    * serial.h: Add GDBPARITY_NONE, GDBPARITY_ODD, GDBPARITY_EVEN
> +    definitions. Add serial_setparity declaration.
> +    (serial_ops): Add setparity entry.
> +    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
> +    state.Parity definitions.
> +    (ser_windows_setparity): New function.
> +    (hardwire_ops): add ser_windows_setparity.
> +    (tty_ops): add NULL for setparity field
> +    (pipe_ops): add ser_base_setparity.
> +    (tcp_ops): add ser_base_setparity.
> +    * ser-pipe.c (pipe_ops): Likewise.
> +    * ser-tcp.c (tcp_ops): Likewise.
> +    * ser-unix.c: Add hardwire_setparity declaration.
> +    (hardwire_setparity): New function.
> +    (hardwire_ops): add hardwire_setparity.
> +    * ser-go32.c (dos_ops): add dos_noop
> +    * target.h: serial_parity declaration.

> diff --git a/gdb/monitor.c b/gdb/monitor.c
> index b040ec4..548dae3 100644
> --- a/gdb/monitor.c
> +++ b/gdb/monitor.c
> @@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops
> *mon_ops, int from_tty)
>      }
>      }
> 
> +  serial_setparity (monitor_desc, serial_parity);
>    serial_raw (monitor_desc);
> 
>    serial_flush_input (monitor_desc);
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 9aaee13..1554259 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -4310,6 +4310,7 @@ remote_open_1 (const char *name, int from_tty,
>      }
>      }
> 
> +  serial_setparity(rs->remote_desc, serial_parity);

Missing space before the '('.

>    serial_raw (rs->remote_desc);
> 
>    /* If there is something sitting in the buffer we might take it as a
> diff --git a/gdb/ser-base.c b/gdb/ser-base.c
> index 87817c4..93aad40 100644
> --- a/gdb/ser-base.c
> +++ b/gdb/ser-base.c
> @@ -541,6 +541,12 @@ ser_base_setstopbits (struct serial *scb, int num)
>    return 0;            /* Never fails!  */
>  }
> 
> +int
> +ser_base_setparity (struct serial *scb, int parity)

We have a policy, now, that all new functions should be documented.
For functions like these, that simply implement a callback, a one-line
introductory comment is sufficient. For instance:

/* Implement the "setparity" serial_ops callback.  */

That's sufficient to show that the function's documentation is the same
as the callback's documentation.

>  extern int ser_base_setbaudrate (struct serial *scb, int rate);
> -extern int ser_base_setstopbits (struct serial *scb, int rate);
> +extern int ser_base_setstopbits (struct serial *scb, int num);

This change is unrelated, and obvious, so I pushed it on its own:
https://www.sourceware.org/ml/gdb-patches/2015-03/msg00488.html

> diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
> index 7f335e9..be0f990 100644
> --- a/gdb/ser-mingw.c
> +++ b/gdb/ser-mingw.c
> @@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
>    if (GetCommState (h, &state) == 0)
>      return;
> 
> -  state.fParity = FALSE;
>    state.fOutxCtsFlow = FALSE;
>    state.fOutxDsrFlow = FALSE;
>    state.fDtrControl = DTR_CONTROL_ENABLE;
> @@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
>    state.fNull = FALSE;
>    state.fAbortOnError = FALSE;
>    state.ByteSize = 8;
> -  state.Parity = NOPARITY;
> 
>    scb->current_timeout = 0;
> 
> @@ -199,6 +197,36 @@ ser_windows_setstopbits (struct serial *scb, int num)
>  }
> 
>  static int
> +ser_windows_setparity (struct serial *scb, int parity)

Same as above - missing function introductory comment.

> +{
> +  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
> +  DCB state;
> +
> +  if (GetCommState (h, &state) == 0)
> +    return -1;
> +
> +  switch (parity)
> +    {
> +    case GDBPARITY_NONE:
> +      state.Parity = NOPARITY;
> +      state.fParity = FALSE;
> +      break;
> +    case GDBPARITY_ODD:
> +      state.Parity = ODDPARITY;
> +      state.fParity = TRUE;
> +      break;
> +    case GDBPARITY_EVEN:
> +      state.Parity = EVENPARITY;
> +      state.fParity = TRUE;
> +      break;
> +    default:
> +      return 1;

Let's emit an internal_warning if parity has an unknown value.
PARITY should always be one of those 3, and getting anything else
is an internal_error. But the reason why I suggested the use of
an internal_warning instead of internal_error is that internal_error
is pretty-much a fatal error, but maybe we don't absolutely need it
to be fatal. Communication is probably going to be screwed up, but
anything else should still be working. We just want to warn the user
of the issue he's likely going to face.

> +    }
> +static int
> +hardwire_setparity (struct serial *scb, int parity)
> +{

Missing function documentation.

> +  struct hardwire_ttystate state;
> +  int newparity = 0;
> +
> +  if (get_tty_state (scb, &state))
> +    return -1;
> +
> +  switch (parity)
> +    {
> +    case GDBPARITY_NONE:
> +      newparity = 0;
> +      break;
> +    case GDBPARITY_ODD:
> +      newparity = PARENB | PARODD;
> +      break;
> +    case GDBPARITY_EVEN:
> +      newparity = PARENB;
> +      break;
> +    default:
> +      return 1;

Same here - internal_warning to warn the user of likely communication
issues.

> --- a/gdb/serial.c
> +++ b/gdb/serial.c
> @@ -525,6 +525,12 @@ serial_setstopbits (struct serial *scb, int num)
>  }
> 
>  int
> +serial_setparity (struct serial*scb, int parity)
> +{
> +    return scb->ops->setparity (scb, parity);
> +}

Missing function documentation.

> +/* Parity for serial port */
> +int serial_parity = GDBPARITY_NONE;
> +
> +static const char parity_none[] = "none";
> +static const char parity_odd[] = "odd";
> +static const char parity_even[] = "even";
> +static const char *const parity_enums[] =
> +{parity_none, parity_odd, parity_even,  NULL};

Two spaces before '{' (indentation).

> +static const char *parity = parity_none;

> +static void
> +set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)

When the function's documentation is in the .h file, can you add a
comment that says, Eg:

/* See serial.h.  */

?

> +/* Set parity for serial port. Return 0 for success, -1 for failure */
> +
> +#define GDBPARITY_NONE     0
> +#define GDBPARITY_ODD      1
> +#define GDBPARITY_EVEN     2
> +
> +extern int serial_setparity (struct serial *scb, int parity);

Can you move the function's documentation after the #define's?

>  /* Can the serial device support asynchronous mode?  */
> @@ -271,6 +279,7 @@ struct serial_ops
>                    serial_ttystate);
>      int (*setbaudrate) (struct serial *, int rate);
>      int (*setstopbits) (struct serial *, int num);
> +    int (*setparity) (struct serial *, int parity);

Please document here what this hook should be doing. Please name
all the arguments as well, so you can use those names in the hook's
description. Below is an example from target.h which shows how
these kinds of "methods" are now documented in GDB:

    /* Return the thread-local address at OFFSET in the
       thread-local storage for the thread PTID and the shared library
       or executable file given by OBJFILE.  If that block of
       thread-local storage hasn't been allocated yet, this function
       may return an error.  LOAD_MODULE_ADDR may be zero for statically
       linked multithreaded inferiors.  */
    CORE_ADDR (*to_get_thread_local_address) (struct target_ops *ops,
                                              ptid_t ptid,
                                              CORE_ADDR load_module_addr,
                                              CORE_ADDR offset)


> index c95e1a4..685a37f 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -2236,6 +2236,10 @@ extern int remote_debug;
> 
>  /* Speed in bits per second, or -1 which means don't mess with the speed.  */
>  extern int baud_rate;
> +
> +/* Parity for serial port */
> +extern int serial_parity;

For the global's documentation, can you add a period followed by
two spaces? Thus:

/* Parity for serial port. */

-- 
Joel

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

* Re: Setting parity for remote serial
  2015-03-17 14:56               ` Joel Brobecker
@ 2015-03-22 22:52                 ` Yurij Grechishhev
  2015-03-23 13:11                   ` Joel Brobecker
  2015-03-23 15:36                   ` Eli Zaretskii
  0 siblings, 2 replies; 23+ messages in thread
From: Yurij Grechishhev @ 2015-03-22 22:52 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Hi Joel,
It's really useful experience to follow so strict coding style. Are
there any plans to use any system for code review (like Gerrit)?
This patch is created on the top of the latest code (after the git
cloning gdb repo).
I have tested these changes with my Linux machine (Ubuntu 12.04.4
x86_64) and external USB-UART cable: I was checking tty parameters by
using stty:
Initial setup:
$ sudo stty -F /dev/ttyUSB0 --all
speed 0 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
-parenb -parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

gdb-7.9, without changes:
(gdb) set serial baud 38400
(gdb) target remote /dev/ttyUSB0
$ sudo stty -F /dev/ttyUSB0 --all
speed 38400 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
-parenb -parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

GDB, compiled with patch:
(gdb) set serial baud 19200
(gdb) show serial parity
Parity for remote serial I/O is "none".
(gdb) target remote /dev/ttyUSB0
$ sudo stty -F /dev/ttyUSB0 --all
speed 19200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
-parenb -parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

(gdb) set serial parity even
(gdb) show serial parity
Parity for remote serial I/O is "even"
(gdb) target remote /dev/ttyUSB0
speed 19200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
parenb -parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

(gdb) set serial parity odd
(gdb) show serial parity
Parity for remote serial I/O is "odd
(gdb) target remote /dev/ttyUSB0
speed 19200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
parenb parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

(gdb) set serial parity none
(gdb) show serial parity
Parity for remote serial I/O is "none".
(gdb) target remote /dev/ttyUSB0
speed 19200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 0; time = 10;
-parenb -parodd cs8 -hupcl -cstopb -cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
-ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt -echoctl -echoke

(gdb) set serial parity wrong
Undefined item: "wrong".
(gdb) show serial parity
Parity for remote serial I/O is "none".

Unfortunately, now I don't have the ability to fully-test it with
windows (but I was checking initial version one year ago, with real
hardware). Now it has been compiled by using mingw with
--host=i586-mingw32msvc.

Updated patch is below. Also I've fixed one issue with zeroing PARENB flag.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ca8bbaf..02f9ddc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,37 @@
+2015-03-21  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * NEWS: Mention set/show serial parity command.
+    * monitor.c (monitor_open): Call serial_setparity.
+    * remote.c (remote_open_1): Likewise.
+    * ser-base.c (ser_base_serparity): New function.
+    * ser-base.h (ser_base_setparity): Add  declaration.
+    * ser-go32.c (dos_ops): Add dos_noop field.
+    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
+    state.Parity definitions.
+    (ser_windows_setparity): New function.
+    (hardwire_ops): Add ser_windows_setparity.
+    (tty_ops): Add NULL for setparity field.
+    (pipe_ops): Add ser_base_setparity.
+    (tcp_ops): Likewise.
+    * ser-pipe.c (pipe_ops): Likewise.
+    * ser-tcp.c (tcp_ops): Likewise.
+    * ser-unix.c (hardwire_setparity): Add declaration.
+    (hardwire_raw): Don't reset PARENB flag.
+    (hardwire_setparity): New function.
+    (hardwire_ops): Add hardwire_setparity.
+    * serial.c (serial_setparity): New function.
+    (serial_parity): New global.
+    (parity_none, parity_odd, parity_even, parity_enums, parity):
+        New static globals.
+    (set_parity): New function.
+    (_initialize_serial): Add set/show serial parity commands.
+    * serial.h (GDBPARITY_NONE): Define.
+    (GDBPARITY_ODD): Define.
+    (GDBPARITY_EVEN): Define.
+    (serial_setparity) Add declaration.
+    (serial_ops): Add setparity entry.
+    * target.h (serial_parity): Add declaration.
+
 2015-03-17  Yurij Grechishhev  <yurij.grechishhev@gmail.com>

     * ser-base.h (ser_base_setstopbits): Change second argument name
diff --git a/gdb/NEWS b/gdb/NEWS
index bda4a35..3fa33c9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@

 *** Changes since GDB 7.9

+* GDB has two new commands: "set serial parity odd|even|none" and
+  "show serial parity".  These allows to set or show parity for the
+  remote serial I/O.
+
 * The "info source" command now displays the producer string if it was
   present in the debug info.  This typically includes the compiler version
   and may include things like its command line arguments.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5efb060..f7d6485 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+    * gdb.texinfo (Remote configuration): Document "set/show
+    serial parity" command.
+
 2015-03-11  Gary Benson <gbenson@redhat.com>

     * gdb.texinfo (Remote Configuration): Document the
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9e71642..a818d58 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19443,6 +19443,13 @@ remote targets.
 @item show serial baud
 Show the current speed of the remote connection.

+@item set serial parity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of
@var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show serial parity
+Show the current parity of the serial port.
+
 @item set remotebreak
 @cindex interrupt remote programs
 @cindex BREAK signal instead of Ctrl-C
diff --git a/gdb/monitor.c b/gdb/monitor.c
index b040ec4..548dae3 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops
*mon_ops, int from_tty)
     }
     }

+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);

   serial_flush_input (monitor_desc);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9aaee13..ed3ab57 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4310,6 +4310,7 @@ remote_open_1 (const char *name, int from_tty,
     }
     }

+  serial_setparity (rs->remote_desc, serial_parity);
   serial_raw (rs->remote_desc);

   /* If there is something sitting in the buffer we might take it as a
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 87817c4..09aacec 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -541,6 +541,14 @@ ser_base_setstopbits (struct serial *scb, int num)
   return 0;            /* Never fails!  */
 }

+/* Implement the "setparity" serial_ops callback.  */
+
+int
+ser_base_setparity (struct serial *scb, int parity)
+{
+  return 0;            /* Never fails!  */
+}
+
 /* Put the SERIAL device into/out-of ASYNC mode.  */

 void
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 6aac925..bb1c51d 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -43,6 +43,7 @@ extern int ser_base_noflush_set_tty_state (struct serial *scb,
                        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);
 extern int ser_base_drain_output (struct serial *scb);

 extern int ser_base_write (struct serial *scb, const void *buf, size_t count);
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 6bf1b4e..bbcf6af 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -864,6 +864,7 @@ static const struct serial_ops dos_ops =
   dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
+  dos_noop,
   dos_noop,            /* Wait for output to drain.  */
   (void (*)(struct serial *, int))NULL    /* Change into async mode.  */
 };
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7f335e9..cedbcd6 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;

-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;

   scb->current_timeout = 0;

@@ -198,6 +196,39 @@ ser_windows_setstopbits (struct serial *scb, int num)
   return (SetCommState (h, &state) != 0) ? 0 : -1;
 }

+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__, "Incorrect parity value:
%d", parity);
+      return -1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
 static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
@@ -1227,6 +1258,7 @@ static const struct serial_ops hardwire_ops =
   ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
+  ser_windows_setparity,
   ser_windows_drain_output,
   ser_base_async,
   ser_windows_read_prim,
@@ -1257,6 +1289,7 @@ static const struct serial_ops tty_ops =
   ser_base_noflush_set_tty_state,
   NULL,
   NULL,
+  NULL,
   ser_base_drain_output,
   NULL,
   NULL,
@@ -1287,6 +1320,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   pipe_windows_read,
@@ -1317,6 +1351,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index bf5e4d4..0700132 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -224,6 +224,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 9c3dcf4..35512e6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -394,6 +394,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 4125797..fa547b3 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -83,6 +83,7 @@ static int hardwire_readchar (struct serial *scb,
int timeout);
 static int do_hardwire_readchar (struct serial *scb, int timeout);
 static int rate_to_code (int rate);
 static int hardwire_setbaudrate (struct serial *scb, int rate);
+static int hardwire_setparity (struct serial *scb, int parity);
 static void hardwire_close (struct serial *scb);
 static int get_tty_state (struct serial *scb,
               struct hardwire_ttystate * state);
@@ -409,7 +410,7 @@ hardwire_raw (struct serial *scb)
   state.termios.c_iflag = 0;
   state.termios.c_oflag = 0;
   state.termios.c_lflag = 0;
-  state.termios.c_cflag &= ~(CSIZE | PARENB);
+  state.termios.c_cflag &= ~(CSIZE);
   state.termios.c_cflag |= CLOCAL | CS8;
 #ifdef CRTSCTS
   /* h/w flow control.  */
@@ -432,7 +433,7 @@ hardwire_raw (struct serial *scb)
   state.termio.c_iflag = 0;
   state.termio.c_oflag = 0;
   state.termio.c_lflag = 0;
-  state.termio.c_cflag &= ~(CSIZE | PARENB);
+  state.termio.c_cflag &= ~(CSIZE);
   state.termio.c_cflag |= CLOCAL | CS8;
   state.termio.c_cc[VMIN] = 0;
   state.termio.c_cc[VTIME] = 0;
@@ -893,6 +894,50 @@ hardwire_setstopbits (struct serial *scb, int num)
   return set_tty_state (scb, &state);
 }

+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__, "Incorrect parity value:
%d", 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);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +974,7 @@ static const struct serial_ops hardwire_ops =
   hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
+  hardwire_setparity,
   hardwire_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/serial.c b/gdb/serial.c
index b7e620d..5f1b5cf 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -524,6 +524,14 @@ serial_setstopbits (struct serial *scb, int num)
   return scb->ops->setstopbits (scb, num);
 }

+/* See serial.h.  */
+
+int
+serial_setparity (struct serial *scb, int parity)
+{
+    return scb->ops->setparity (scb, parity);
+}
+
 int
 serial_can_async_p (struct serial *scb)
 {
@@ -638,6 +646,30 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty,
             value);
 }

+/* Parity for serial port.  */
+
+int serial_parity = GDBPARITY_NONE;
+
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+  {parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+/* Set serial_parity value.  */
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
 void
 _initialize_serial (void)
 {
@@ -670,6 +702,14 @@ using remote targets."),
                 serial_baud_show_cmd,
                 &serial_set_cmdlist, &serial_show_cmdlist);

+  add_setshow_enum_cmd ("parity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &serial_set_cmdlist, &serial_show_cmdlist);
+
   add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
 Set filename for remote session recording."), _("\
 Show filename for remote session recording."), _("\
diff --git a/gdb/serial.h b/gdb/serial.h
index 9eb1c39..add0f15 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -186,6 +186,14 @@ extern int serial_setbaudrate (struct serial
*scb, int rate);

 extern int serial_setstopbits (struct serial *scb, int num);

+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+/* Set parity for serial port. Returns 0 for success, -1 for failure.  */
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Asynchronous serial interface: */

 /* Can the serial device support asynchronous mode?  */
@@ -271,6 +279,9 @@ struct serial_ops
                   serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    /* Set the value PARITY as parity setting for serial object.
+       Return 0 in the case of success.  */
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff --git a/gdb/target.h b/gdb/target.h
index c95e1a4..05dcd9f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2236,6 +2236,10 @@ extern int remote_debug;

 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port  */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;


--
Thanks,
Yury

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

* Re: Setting parity for remote serial
  2015-03-22 22:52                 ` Yurij Grechishhev
@ 2015-03-23 13:11                   ` Joel Brobecker
  2015-03-23 15:36                   ` Eli Zaretskii
  1 sibling, 0 replies; 23+ messages in thread
From: Joel Brobecker @ 2015-03-23 13:11 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

> Unfortunately, now I don't have the ability to fully-test it with
> windows (but I was checking initial version one year ago, with real
> hardware). Now it has been compiled by using mingw with
> --host=i586-mingw32msvc.

No problem - the code looked about right to me, and we will let those
who do work on Windows take care of fixing any bugs if they use this
feature and encounter a bug.

> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index ca8bbaf..02f9ddc 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,37 @@
> +2015-03-21  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
> +
> +    * NEWS: Mention set/show serial parity command.
> +    * monitor.c (monitor_open): Call serial_setparity.
> +    * remote.c (remote_open_1): Likewise.
> +    * ser-base.c (ser_base_serparity): New function.
> +    * ser-base.h (ser_base_setparity): Add  declaration.
> +    * ser-go32.c (dos_ops): Add dos_noop field.

The name of the struct field is actually "setparity" (instead of
"dos_noop").

> +    * ser-mingw.c (ser_windows_raw): Remove state.fParity and
> +    state.Parity definitions.

"Do not set state.fParity and state.Parity". You remmoved assignments,
rather than definitions.

> +    (ser_windows_setparity): New function.
> +    (hardwire_ops): Add ser_windows_setparity.
> +    (tty_ops): Add NULL for setparity field.
> +    (pipe_ops): Add ser_base_setparity.
> +    (tcp_ops): Likewise.
> +    * ser-pipe.c (pipe_ops): Likewise.
> +    * ser-tcp.c (tcp_ops): Likewise.
> +    * ser-unix.c (hardwire_setparity): Add declaration.
> +    (hardwire_raw): Don't reset PARENB flag.
> +    (hardwire_setparity): New function.
> +    (hardwire_ops): Add hardwire_setparity.
> +    * serial.c (serial_setparity): New function.
> +    (serial_parity): New global.
> +    (parity_none, parity_odd, parity_even, parity_enums, parity):
> +        New static globals.

Wrong indentation of "New static globals". I suspect that this is
because you used 8 spaces instead of a tab to indent that line?

> +    (set_parity): New function.
> +    (_initialize_serial): Add set/show serial parity commands.
> +    * serial.h (GDBPARITY_NONE): Define.
> +    (GDBPARITY_ODD): Define.
> +    (GDBPARITY_EVEN): Define.
> +    (serial_setparity) Add declaration.
> +    (serial_ops): Add setparity entry.

Let's say...

        (struct serial_ops): Add setparity field

... instead.

> +    * target.h (serial_parity): Add declaration.

The rest are minor comments:

> +      internal_warning (__FILE__, __LINE__, "Incorrect parity value:
> %d", parity);

This line is too long. It shouldn't exceed 79 characters.

      internal_warning (__FILE__, __LINE__, "Incorrect parity value: %d", parity);

Use instead:

      internal_warning (__FILE__, __LINE__,
			"Incorrect parity value: %d", parity);

Also, watch out for the fact that your mailer appears to have wrapped
the line. I suggest you switch to sending the patch either using
"git send-email" (the recommended method), or else sending the patch
as an attachment ("git format-patch" + attach to email).

> @@ -409,7 +410,7 @@ hardwire_raw (struct serial *scb)
>    state.termios.c_iflag = 0;
>    state.termios.c_oflag = 0;
>    state.termios.c_lflag = 0;
> -  state.termios.c_cflag &= ~(CSIZE | PARENB);
> +  state.termios.c_cflag &= ~(CSIZE);

You don't really need the parentheses anymore -> ~CSIZE

>    state.termios.c_cflag |= CLOCAL | CS8;
>  #ifdef CRTSCTS
>    /* h/w flow control.  */
> @@ -432,7 +433,7 @@ hardwire_raw (struct serial *scb)
>    state.termio.c_iflag = 0;
>    state.termio.c_oflag = 0;
>    state.termio.c_lflag = 0;
> -  state.termio.c_cflag &= ~(CSIZE | PARENB);
> +  state.termio.c_cflag &= ~(CSIZE);

Likewise.

> @@ -893,6 +894,50 @@ hardwire_setstopbits (struct serial *scb, int num)
>    return set_tty_state (scb, &state);
>  }
> 
> +/* Implement the "setparity" serial_ops callback.  */
> +
> +static int
> +hardwire_setparity (struct serial *scb, int parity)
> +{
> +  struct hardwire_ttystate state;
> +  int newparity = 0;
> +
> +  if (get_tty_state (scb, &state))
> +    return -1;
> +
> +  switch (parity)
> +    {
> +    case GDBPARITY_NONE:
> +      newparity = 0;
> +      break;
> +    case GDBPARITY_ODD:
> +      newparity = PARENB | PARODD;
> +      break;
> +    case GDBPARITY_EVEN:
> +      newparity = PARENB;
> +      break;
> +    default:
> +      internal_warning (__FILE__, __LINE__, "Incorrect parity value:
> %d", parity);

Same as above - line is too long.

> +/* See serial.h.  */
> +
> +int
> +serial_setparity (struct serial *scb, int parity)
> +{
> +    return scb->ops->setparity (scb, parity);

The indentation is wrong (we use a 2-space indentation). Hence:

    int
    serial_setparity (struct serial *scb, int parity)
    {
      return scb->ops->setparity (scb, parity);
    }

-- 
Joel

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

* Re: Setting parity for remote serial
  2015-03-22 22:52                 ` Yurij Grechishhev
  2015-03-23 13:11                   ` Joel Brobecker
@ 2015-03-23 15:36                   ` Eli Zaretskii
  2015-03-23 21:21                     ` Yurij Grechishhev
  1 sibling, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2015-03-23 15:36 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: brobecker, gdb-patches

> Date: Mon, 23 Mar 2015 01:52:26 +0300
> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
> Cc: gdb-patches@sourceware.org
> 
> Updated patch is below. Also I've fixed one issue with zeroing PARENB flag.

OK for the documentation parts.

Thanks.

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

* Re: Setting parity for remote serial
  2015-03-23 15:36                   ` Eli Zaretskii
@ 2015-03-23 21:21                     ` Yurij Grechishhev
  2015-03-23 22:52                       ` pushed: " Joel Brobecker
  0 siblings, 1 reply; 23+ messages in thread
From: Yurij Grechishhev @ 2015-03-23 21:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Joel Brobecker, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 376 bytes --]

Hello Joel,
Updated patch is attached.

--
Thanks,
Yury

2015-03-23 18:36 GMT+03:00 Eli Zaretskii <eliz@gnu.org>:
>> Date: Mon, 23 Mar 2015 01:52:26 +0300
>> From: Yurij Grechishhev <yurij.grechishhev@gmail.com>
>> Cc: gdb-patches@sourceware.org
>>
>> Updated patch is below. Also I've fixed one issue with zeroing PARENB flag.
>
> OK for the documentation parts.
>
> Thanks.

[-- Attachment #2: 0001-Add-set-show-serial-parity-command.patch --]
[-- Type: text/x-patch, Size: 15277 bytes --]

From abcc5818193f0a48cc858a4cc760fd7b15cf89cd Mon Sep 17 00:00:00 2001
From: Yury Grechishchev <yury.grechishchev@yotadevices.com>
Date: Tue, 24 Mar 2015 00:15:42 +0300
Subject: [PATCH] Add set/show serial parity command.

---
 gdb/ChangeLog       |   34 ++++++++++++++++++++++++++++++++++
 gdb/NEWS            |    4 ++++
 gdb/doc/ChangeLog   |    5 +++++
 gdb/doc/gdb.texinfo |    7 +++++++
 gdb/monitor.c       |    1 +
 gdb/remote.c        |    1 +
 gdb/ser-base.c      |    8 ++++++++
 gdb/ser-base.h      |    1 +
 gdb/ser-go32.c      |    1 +
 gdb/ser-mingw.c     |   40 ++++++++++++++++++++++++++++++++++++++--
 gdb/ser-pipe.c      |    1 +
 gdb/ser-tcp.c       |    1 +
 gdb/ser-unix.c      |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 gdb/serial.c        |   40 ++++++++++++++++++++++++++++++++++++++++
 gdb/serial.h        |   11 +++++++++++
 gdb/target.h        |    4 ++++
 16 files changed, 206 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ca8bbaf..fabadf3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,37 @@
+2015-03-21  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* NEWS: Mention set/show serial parity command.
+	* monitor.c (monitor_open): Call serial_setparity.
+	* remote.c (remote_open_1): Likewise.
+	* ser-base.c (ser_base_serparity): New function.
+	* ser-base.h (ser_base_setparity): Add  declaration.
+	* ser-go32.c (dos_ops): Set "setparity" field.
+	* ser-mingw.c (ser_windows_raw): Do not set state.fParity and
+	state.Parity.
+	(ser_windows_setparity): New function.
+	(hardwire_ops): Add ser_windows_setparity.
+	(tty_ops): Add NULL for setparity field.
+	(pipe_ops): Add ser_base_setparity.
+	(tcp_ops): Likewise.
+	* ser-pipe.c (pipe_ops): Likewise.
+	* ser-tcp.c (tcp_ops): Likewise.
+	* ser-unix.c (hardwire_setparity): Add declaration.
+	(hardwire_raw): Don't reset PARENB flag.
+	(hardwire_setparity): New function.
+	(hardwire_ops): Add hardwire_setparity.
+	* serial.c (serial_setparity): New function.
+	(serial_parity): New global.
+	(parity_none, parity_odd, parity_even, parity_enums, parity):
+	New static globals.
+	(set_parity): New function.
+	(_initialize_serial): Add set/show serial parity commands.
+	* serial.h (GDBPARITY_NONE): Define.
+	(GDBPARITY_ODD): Define.
+	(GDBPARITY_EVEN): Define.
+	(serial_setparity) Add declaration.
+	(struct serial_ops): Add setparity field.
+	* target.h (serial_parity): Add declaration.
+
 2015-03-17  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
 
 	* ser-base.h (ser_base_setstopbits): Change second argument name
diff --git a/gdb/NEWS b/gdb/NEWS
index bda4a35..3fa33c9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
 
 *** Changes since GDB 7.9
 
+* GDB has two new commands: "set serial parity odd|even|none" and
+  "show serial parity".  These allows to set or show parity for the
+  remote serial I/O.
+
 * The "info source" command now displays the producer string if it was
   present in the debug info.  This typically includes the compiler version
   and may include things like its command line arguments.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5efb060..f7d6485 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-16  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* gdb.texinfo (Remote configuration): Document "set/show
+	serial parity" command.
+
 2015-03-11  Gary Benson <gbenson@redhat.com>
 
 	* gdb.texinfo (Remote Configuration): Document the
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9e71642..a818d58 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19443,6 +19443,13 @@ remote targets.
 @item show serial baud
 Show the current speed of the remote connection.
 
+@item set serial parity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of @var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show serial parity
+Show the current parity of the serial port.
+
 @item set remotebreak
 @cindex interrupt remote programs
 @cindex BREAK signal instead of Ctrl-C
diff --git a/gdb/monitor.c b/gdb/monitor.c
index b040ec4..548dae3 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops *mon_ops, int from_tty)
 	}
     }
 
+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);
 
   serial_flush_input (monitor_desc);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9aaee13..ed3ab57 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4310,6 +4310,7 @@ remote_open_1 (const char *name, int from_tty,
 	}
     }
 
+  serial_setparity (rs->remote_desc, serial_parity);
   serial_raw (rs->remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 87817c4..09aacec 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -541,6 +541,14 @@ ser_base_setstopbits (struct serial *scb, int num)
   return 0;			/* Never fails!  */
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+int
+ser_base_setparity (struct serial *scb, int parity)
+{
+  return 0;			/* Never fails!  */
+}
+
 /* Put the SERIAL device into/out-of ASYNC mode.  */
 
 void
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 6aac925..bb1c51d 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -43,6 +43,7 @@ extern int ser_base_noflush_set_tty_state (struct serial *scb,
 					   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);
 extern int ser_base_drain_output (struct serial *scb);
 
 extern int ser_base_write (struct serial *scb, const void *buf, size_t count);
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 6bf1b4e..bbcf6af 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -864,6 +864,7 @@ static const struct serial_ops dos_ops =
   dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
+  dos_noop,
   dos_noop,			/* Wait for output to drain.  */
   (void (*)(struct serial *, int))NULL	/* Change into async mode.  */
 };
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7f335e9..6d383ac 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;
 
-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;
 
   scb->current_timeout = 0;
 
@@ -198,6 +196,40 @@ ser_windows_setstopbits (struct serial *scb, int num)
   return (SetCommState (h, &state) != 0) ? 0 : -1;
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__,
+                  "Incorrect parity value: %d", parity);
+      return -1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
 static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
@@ -1227,6 +1259,7 @@ static const struct serial_ops hardwire_ops =
   ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
+  ser_windows_setparity,
   ser_windows_drain_output,
   ser_base_async,
   ser_windows_read_prim,
@@ -1257,6 +1290,7 @@ static const struct serial_ops tty_ops =
   ser_base_noflush_set_tty_state,
   NULL,
   NULL,
+  NULL,
   ser_base_drain_output,
   NULL,
   NULL,
@@ -1287,6 +1321,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   pipe_windows_read,
@@ -1317,6 +1352,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index bf5e4d4..0700132 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -224,6 +224,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 9c3dcf4..35512e6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -394,6 +394,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 4125797..280fb6a 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -83,6 +83,7 @@ static int hardwire_readchar (struct serial *scb, int timeout);
 static int do_hardwire_readchar (struct serial *scb, int timeout);
 static int rate_to_code (int rate);
 static int hardwire_setbaudrate (struct serial *scb, int rate);
+static int hardwire_setparity (struct serial *scb, int parity);
 static void hardwire_close (struct serial *scb);
 static int get_tty_state (struct serial *scb,
 			  struct hardwire_ttystate * state);
@@ -409,7 +410,7 @@ hardwire_raw (struct serial *scb)
   state.termios.c_iflag = 0;
   state.termios.c_oflag = 0;
   state.termios.c_lflag = 0;
-  state.termios.c_cflag &= ~(CSIZE | PARENB);
+  state.termios.c_cflag &= ~CSIZE;
   state.termios.c_cflag |= CLOCAL | CS8;
 #ifdef CRTSCTS
   /* h/w flow control.  */
@@ -432,7 +433,7 @@ hardwire_raw (struct serial *scb)
   state.termio.c_iflag = 0;
   state.termio.c_oflag = 0;
   state.termio.c_lflag = 0;
-  state.termio.c_cflag &= ~(CSIZE | PARENB);
+  state.termio.c_cflag &= ~CSIZE;
   state.termio.c_cflag |= CLOCAL | CS8;
   state.termio.c_cc[VMIN] = 0;
   state.termio.c_cc[VTIME] = 0;
@@ -893,6 +894,51 @@ hardwire_setstopbits (struct serial *scb, int num)
   return set_tty_state (scb, &state);
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__,
+                  "Incorrect parity value: %d", 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);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +975,7 @@ static const struct serial_ops hardwire_ops =
   hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
+  hardwire_setparity,
   hardwire_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/serial.c b/gdb/serial.c
index b7e620d..74567db 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -524,6 +524,14 @@ serial_setstopbits (struct serial *scb, int num)
   return scb->ops->setstopbits (scb, num);
 }
 
+/* See serial.h.  */
+
+int
+serial_setparity (struct serial *scb, int parity)
+{
+  return scb->ops->setparity (scb, parity);
+}
+
 int
 serial_can_async_p (struct serial *scb)
 {
@@ -638,6 +646,30 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty,
 		    value);
 }
 
+/* Parity for serial port.  */
+
+int serial_parity = GDBPARITY_NONE;
+
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+  {parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+/* Set serial_parity value.  */
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
 void
 _initialize_serial (void)
 {
@@ -670,6 +702,14 @@ using remote targets."),
 			    serial_baud_show_cmd,
 			    &serial_set_cmdlist, &serial_show_cmdlist);
 
+  add_setshow_enum_cmd ("parity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &serial_set_cmdlist, &serial_show_cmdlist);
+
   add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
 Set filename for remote session recording."), _("\
 Show filename for remote session recording."), _("\
diff --git a/gdb/serial.h b/gdb/serial.h
index 9eb1c39..add0f15 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -186,6 +186,14 @@ extern int serial_setbaudrate (struct serial *scb, int rate);
 
 extern int serial_setstopbits (struct serial *scb, int num);
 
+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+/* Set parity for serial port. Returns 0 for success, -1 for failure.  */
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Asynchronous serial interface: */
 
 /* Can the serial device support asynchronous mode?  */
@@ -271,6 +279,9 @@ struct serial_ops
 				  serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    /* Set the value PARITY as parity setting for serial object.
+       Return 0 in the case of success.  */
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff --git a/gdb/target.h b/gdb/target.h
index c95e1a4..05dcd9f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2236,6 +2236,10 @@ extern int remote_debug;
 
 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port  */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;
 
-- 
1.7.9.5


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

* pushed: Re: Setting parity for remote serial
  2015-03-23 21:21                     ` Yurij Grechishhev
@ 2015-03-23 22:52                       ` Joel Brobecker
  0 siblings, 0 replies; 23+ messages in thread
From: Joel Brobecker @ 2015-03-23 22:52 UTC (permalink / raw)
  To: Yurij Grechishhev; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1288 bytes --]

> Updated patch is attached.

Thanks! I noticed that there was still a slight indentation error
in the calls to internal_warning, so I set about to fix those before
committing the patch for you. That's when I noticed that the ChangeLog
entries would not apply, and this, combined with enhancing a bit
the revision log to include that ChangeLog info, distracted me enough
that I forgot to fix the indentation issues!

So, attached is: first, the patch that you sent, with the revision
log a little augmented to make it a little more descriptive about
what the patch brings in; second, the indentation fixes, applied
separately, unfortunately.

gdb/ChangeLog:

        * ser-mingw.c (ser_windows_setparity): Fix indentation.
        * ser-unix.c (hardwire_setparity): Likewise.

I pushed the patch for you because I suspect you do not have
write permissions in GDB yet, and also to minimize the ping-pong
effect. I think you've worked hard on cleaning that patch up already!

If you think you might have other changes you'd like to contribute,
it might make sense for you to get write-after-approval privileges.
If you are interested, send me a private email and I'll get you
started (let me know if you have a sourceware.org account already
or not).

Thanks again for the patch!

-- 
Joel

[-- Attachment #2: 0001-GDB-Add-set-show-serial-parity-command.patch --]
[-- Type: text/x-diff, Size: 17024 bytes --]

From 236af5e336970a6b58cd17e0a2981bd96f3d09a0 Mon Sep 17 00:00:00 2001
From: Yury Grechishchev <yury.grechishchev@yotadevices.com>
Date: Tue, 24 Mar 2015 00:15:42 +0300
Subject: [PATCH] GDB: Add set/show serial parity command.

The "set serial parity" command allows the user to control which
parity to use when communicating over a serial connection, rather
than having the parity hardcoded to none.

gdb/ChangeLog:

        * NEWS: Mention set/show serial parity command.
        * monitor.c (monitor_open): Call serial_setparity.
        * remote.c (remote_open_1): Likewise.
        * ser-base.c (ser_base_serparity): New function.
        * ser-base.h (ser_base_setparity): Add  declaration.
        * ser-go32.c (dos_ops): Set "setparity" field.
        * ser-mingw.c (ser_windows_raw): Do not set state.fParity and
        state.Parity.
        (ser_windows_setparity): New function.
        (hardwire_ops): Add ser_windows_setparity.
        (tty_ops): Add NULL for setparity field.
        (pipe_ops): Add ser_base_setparity.
        (tcp_ops): Likewise.
        * ser-pipe.c (pipe_ops): Likewise.
        * ser-tcp.c (tcp_ops): Likewise.
        * ser-unix.c (hardwire_setparity): Add declaration.
        (hardwire_raw): Don't reset PARENB flag.
        (hardwire_setparity): New function.
        (hardwire_ops): Add hardwire_setparity.
        * serial.c (serial_setparity): New function.
        (serial_parity): New global.
        (parity_none, parity_odd, parity_even, parity_enums, parity):
        New static globals.
        (set_parity): New function.
        (_initialize_serial): Add set/show serial parity commands.
        * serial.h (GDBPARITY_NONE): Define.
        (GDBPARITY_ODD): Define.
        (GDBPARITY_EVEN): Define.
        (serial_setparity) Add declaration.
        (struct serial_ops): Add setparity field.
        * target.h (serial_parity): Add declaration.

gdb/doc/ChangeLog:

        * gdb.texinfo (Remote configuration): Document "set/show
        serial parity" command.
---
 gdb/ChangeLog       | 34 ++++++++++++++++++++++++++++++++++
 gdb/NEWS            |  4 ++++
 gdb/doc/ChangeLog   |  5 +++++
 gdb/doc/gdb.texinfo |  7 +++++++
 gdb/monitor.c       |  1 +
 gdb/remote.c        |  1 +
 gdb/ser-base.c      |  8 ++++++++
 gdb/ser-base.h      |  1 +
 gdb/ser-go32.c      |  1 +
 gdb/ser-mingw.c     | 40 ++++++++++++++++++++++++++++++++++++++--
 gdb/ser-pipe.c      |  1 +
 gdb/ser-tcp.c       |  1 +
 gdb/ser-unix.c      | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 gdb/serial.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 gdb/serial.h        | 11 +++++++++++
 gdb/target.h        |  4 ++++
 16 files changed, 206 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3c59d09..e5e9255 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,37 @@
+2015-03-23  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* NEWS: Mention set/show serial parity command.
+	* monitor.c (monitor_open): Call serial_setparity.
+	* remote.c (remote_open_1): Likewise.
+	* ser-base.c (ser_base_serparity): New function.
+	* ser-base.h (ser_base_setparity): Add  declaration.
+	* ser-go32.c (dos_ops): Set "setparity" field.
+	* ser-mingw.c (ser_windows_raw): Do not set state.fParity and
+	state.Parity.
+	(ser_windows_setparity): New function.
+	(hardwire_ops): Add ser_windows_setparity.
+	(tty_ops): Add NULL for setparity field.
+	(pipe_ops): Add ser_base_setparity.
+	(tcp_ops): Likewise.
+	* ser-pipe.c (pipe_ops): Likewise.
+	* ser-tcp.c (tcp_ops): Likewise.
+	* ser-unix.c (hardwire_setparity): Add declaration.
+	(hardwire_raw): Don't reset PARENB flag.
+	(hardwire_setparity): New function.
+	(hardwire_ops): Add hardwire_setparity.
+	* serial.c (serial_setparity): New function.
+	(serial_parity): New global.
+	(parity_none, parity_odd, parity_even, parity_enums, parity):
+	New static globals.
+	(set_parity): New function.
+	(_initialize_serial): Add set/show serial parity commands.
+	* serial.h (GDBPARITY_NONE): Define.
+	(GDBPARITY_ODD): Define.
+	(GDBPARITY_EVEN): Define.
+	(serial_setparity) Add declaration.
+	(struct serial_ops): Add setparity field.
+	* target.h (serial_parity): Add declaration.
+
 2015-03-23  Keith Seitz  <keiths@redhat.com>
 
 	* linespec.c (linespec_lexer_lex_keyword): Update comment.
diff --git a/gdb/NEWS b/gdb/NEWS
index bda4a35..3fa33c9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
 
 *** Changes since GDB 7.9
 
+* GDB has two new commands: "set serial parity odd|even|none" and
+  "show serial parity".  These allows to set or show parity for the
+  remote serial I/O.
+
 * The "info source" command now displays the producer string if it was
   present in the debug info.  This typically includes the compiler version
   and may include things like its command line arguments.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 1f120da..b41c5cb 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-23  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
+
+	* gdb.texinfo (Remote configuration): Document "set/show
+	serial parity" command.
+
 2015-03-18  Gary Benson <gbenson@redhat.com>
 
 	* gdb.texinfo (General Query Packets): Remove documentation
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 552da31..7117e42 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19443,6 +19443,13 @@ remote targets.
 @item show serial baud
 Show the current speed of the remote connection.
 
+@item set serial parity @var{parity}
+Set the parity for the remote serial I/O.  Supported values of @var{parity} are:
+@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
+
+@item show serial parity
+Show the current parity of the serial port.
+
 @item set remotebreak
 @cindex interrupt remote programs
 @cindex BREAK signal instead of Ctrl-C
diff --git a/gdb/monitor.c b/gdb/monitor.c
index b040ec4..548dae3 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -767,6 +767,7 @@ monitor_open (const char *args, struct monitor_ops *mon_ops, int from_tty)
 	}
     }
 
+  serial_setparity (monitor_desc, serial_parity);
   serial_raw (monitor_desc);
 
   serial_flush_input (monitor_desc);
diff --git a/gdb/remote.c b/gdb/remote.c
index dfa68b3..fd677fe 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4308,6 +4308,7 @@ remote_open_1 (const char *name, int from_tty,
 	}
     }
 
+  serial_setparity (rs->remote_desc, serial_parity);
   serial_raw (rs->remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 87817c4..09aacec 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -541,6 +541,14 @@ ser_base_setstopbits (struct serial *scb, int num)
   return 0;			/* Never fails!  */
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+int
+ser_base_setparity (struct serial *scb, int parity)
+{
+  return 0;			/* Never fails!  */
+}
+
 /* Put the SERIAL device into/out-of ASYNC mode.  */
 
 void
diff --git a/gdb/ser-base.h b/gdb/ser-base.h
index 6aac925..bb1c51d 100644
--- a/gdb/ser-base.h
+++ b/gdb/ser-base.h
@@ -43,6 +43,7 @@ extern int ser_base_noflush_set_tty_state (struct serial *scb,
 					   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);
 extern int ser_base_drain_output (struct serial *scb);
 
 extern int ser_base_write (struct serial *scb, const void *buf, size_t count);
diff --git a/gdb/ser-go32.c b/gdb/ser-go32.c
index 6bf1b4e..bbcf6af 100644
--- a/gdb/ser-go32.c
+++ b/gdb/ser-go32.c
@@ -864,6 +864,7 @@ static const struct serial_ops dos_ops =
   dos_noflush_set_tty_state,
   dos_setbaudrate,
   dos_setstopbits,
+  dos_noop,
   dos_noop,			/* Wait for output to drain.  */
   (void (*)(struct serial *, int))NULL	/* Change into async mode.  */
 };
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7f335e9..6d383ac 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -153,7 +153,6 @@ ser_windows_raw (struct serial *scb)
   if (GetCommState (h, &state) == 0)
     return;
 
-  state.fParity = FALSE;
   state.fOutxCtsFlow = FALSE;
   state.fOutxDsrFlow = FALSE;
   state.fDtrControl = DTR_CONTROL_ENABLE;
@@ -163,7 +162,6 @@ ser_windows_raw (struct serial *scb)
   state.fNull = FALSE;
   state.fAbortOnError = FALSE;
   state.ByteSize = 8;
-  state.Parity = NOPARITY;
 
   scb->current_timeout = 0;
 
@@ -198,6 +196,40 @@ ser_windows_setstopbits (struct serial *scb, int num)
   return (SetCommState (h, &state) != 0) ? 0 : -1;
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+  DCB state;
+
+  if (GetCommState (h, &state) == 0)
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      state.Parity = NOPARITY;
+      state.fParity = FALSE;
+      break;
+    case GDBPARITY_ODD:
+      state.Parity = ODDPARITY;
+      state.fParity = TRUE;
+      break;
+    case GDBPARITY_EVEN:
+      state.Parity = EVENPARITY;
+      state.fParity = TRUE;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__,
+                  "Incorrect parity value: %d", parity);
+      return -1;
+    }
+
+  return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
 static int
 ser_windows_setbaudrate (struct serial *scb, int rate)
 {
@@ -1227,6 +1259,7 @@ static const struct serial_ops hardwire_ops =
   ser_base_noflush_set_tty_state,
   ser_windows_setbaudrate,
   ser_windows_setstopbits,
+  ser_windows_setparity,
   ser_windows_drain_output,
   ser_base_async,
   ser_windows_read_prim,
@@ -1257,6 +1290,7 @@ static const struct serial_ops tty_ops =
   ser_base_noflush_set_tty_state,
   NULL,
   NULL,
+  NULL,
   ser_base_drain_output,
   NULL,
   NULL,
@@ -1287,6 +1321,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   pipe_windows_read,
@@ -1317,6 +1352,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index bf5e4d4..0700132 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -224,6 +224,7 @@ static const struct serial_ops pipe_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 9c3dcf4..35512e6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -394,6 +394,7 @@ static const struct serial_ops tcp_ops =
   ser_base_noflush_set_tty_state,
   ser_base_setbaudrate,
   ser_base_setstopbits,
+  ser_base_setparity,
   ser_base_drain_output,
   ser_base_async,
   net_read_prim,
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 4125797..280fb6a 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -83,6 +83,7 @@ static int hardwire_readchar (struct serial *scb, int timeout);
 static int do_hardwire_readchar (struct serial *scb, int timeout);
 static int rate_to_code (int rate);
 static int hardwire_setbaudrate (struct serial *scb, int rate);
+static int hardwire_setparity (struct serial *scb, int parity);
 static void hardwire_close (struct serial *scb);
 static int get_tty_state (struct serial *scb,
 			  struct hardwire_ttystate * state);
@@ -409,7 +410,7 @@ hardwire_raw (struct serial *scb)
   state.termios.c_iflag = 0;
   state.termios.c_oflag = 0;
   state.termios.c_lflag = 0;
-  state.termios.c_cflag &= ~(CSIZE | PARENB);
+  state.termios.c_cflag &= ~CSIZE;
   state.termios.c_cflag |= CLOCAL | CS8;
 #ifdef CRTSCTS
   /* h/w flow control.  */
@@ -432,7 +433,7 @@ hardwire_raw (struct serial *scb)
   state.termio.c_iflag = 0;
   state.termio.c_oflag = 0;
   state.termio.c_lflag = 0;
-  state.termio.c_cflag &= ~(CSIZE | PARENB);
+  state.termio.c_cflag &= ~CSIZE;
   state.termio.c_cflag |= CLOCAL | CS8;
   state.termio.c_cc[VMIN] = 0;
   state.termio.c_cc[VTIME] = 0;
@@ -893,6 +894,51 @@ hardwire_setstopbits (struct serial *scb, int num)
   return set_tty_state (scb, &state);
 }
 
+/* Implement the "setparity" serial_ops callback.  */
+
+static int
+hardwire_setparity (struct serial *scb, int parity)
+{
+  struct hardwire_ttystate state;
+  int newparity = 0;
+
+  if (get_tty_state (scb, &state))
+    return -1;
+
+  switch (parity)
+    {
+    case GDBPARITY_NONE:
+      newparity = 0;
+      break;
+    case GDBPARITY_ODD:
+      newparity = PARENB | PARODD;
+      break;
+    case GDBPARITY_EVEN:
+      newparity = PARENB;
+      break;
+    default:
+      internal_warning (__FILE__, __LINE__,
+                  "Incorrect parity value: %d", 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);
+}
+
+
 static void
 hardwire_close (struct serial *scb)
 {
@@ -929,6 +975,7 @@ static const struct serial_ops hardwire_ops =
   hardwire_noflush_set_tty_state,
   hardwire_setbaudrate,
   hardwire_setstopbits,
+  hardwire_setparity,
   hardwire_drain_output,
   ser_base_async,
   ser_unix_read_prim,
diff --git a/gdb/serial.c b/gdb/serial.c
index b7e620d..74567db 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -524,6 +524,14 @@ serial_setstopbits (struct serial *scb, int num)
   return scb->ops->setstopbits (scb, num);
 }
 
+/* See serial.h.  */
+
+int
+serial_setparity (struct serial *scb, int parity)
+{
+  return scb->ops->setparity (scb, parity);
+}
+
 int
 serial_can_async_p (struct serial *scb)
 {
@@ -638,6 +646,30 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty,
 		    value);
 }
 
+/* Parity for serial port.  */
+
+int serial_parity = GDBPARITY_NONE;
+
+static const char parity_none[] = "none";
+static const char parity_odd[] = "odd";
+static const char parity_even[] = "even";
+static const char *const parity_enums[] =
+  {parity_none, parity_odd, parity_even,  NULL};
+static const char *parity = parity_none;
+
+/* Set serial_parity value.  */
+
+static void
+set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
+{
+  if (parity == parity_odd)
+    serial_parity = GDBPARITY_ODD;
+  else if (parity == parity_even)
+    serial_parity = GDBPARITY_EVEN;
+  else
+    serial_parity = GDBPARITY_NONE;
+}
+
 void
 _initialize_serial (void)
 {
@@ -670,6 +702,14 @@ using remote targets."),
 			    serial_baud_show_cmd,
 			    &serial_set_cmdlist, &serial_show_cmdlist);
 
+  add_setshow_enum_cmd ("parity", no_class, parity_enums,
+                        &parity, _("\
+Set parity for remote serial I/O"), _("\
+Show parity for remote serial I/O"), NULL,
+                        set_parity,
+                        NULL, /* FIXME: i18n: */
+                        &serial_set_cmdlist, &serial_show_cmdlist);
+
   add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
 Set filename for remote session recording."), _("\
 Show filename for remote session recording."), _("\
diff --git a/gdb/serial.h b/gdb/serial.h
index 9eb1c39..add0f15 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -186,6 +186,14 @@ extern int serial_setbaudrate (struct serial *scb, int rate);
 
 extern int serial_setstopbits (struct serial *scb, int num);
 
+#define GDBPARITY_NONE     0
+#define GDBPARITY_ODD      1
+#define GDBPARITY_EVEN     2
+
+/* Set parity for serial port. Returns 0 for success, -1 for failure.  */
+
+extern int serial_setparity (struct serial *scb, int parity);
+
 /* Asynchronous serial interface: */
 
 /* Can the serial device support asynchronous mode?  */
@@ -271,6 +279,9 @@ struct serial_ops
 				  serial_ttystate);
     int (*setbaudrate) (struct serial *, int rate);
     int (*setstopbits) (struct serial *, int num);
+    /* Set the value PARITY as parity setting for serial object.
+       Return 0 in the case of success.  */
+    int (*setparity) (struct serial *, int parity);
     /* Wait for output to drain.  */
     int (*drain_output) (struct serial *);
     /* Change the serial device into/out of asynchronous mode, call
diff --git a/gdb/target.h b/gdb/target.h
index c95e1a4..05dcd9f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2236,6 +2236,10 @@ extern int remote_debug;
 
 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
 extern int baud_rate;
+
+/* Parity for serial port  */
+extern int serial_parity;
+
 /* Timeout limit for response from target.  */
 extern int remote_timeout;
 
-- 
1.9.1


[-- Attachment #3: 0002-Fix-indentation-in-ser_windows_setparity-and-hardwir.patch --]
[-- Type: text/x-diff, Size: 1704 bytes --]

From 2c8f6f16bdd7cc23cbdab1889074c004667555dc Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Mon, 23 Mar 2015 15:42:23 -0700
Subject: [PATCH] Fix indentation in ser_windows_setparity and
 hardwire_setparity.

gdb/ChangeLog:

        * ser-mingw.c (ser_windows_setparity): Fix indentation.
        * ser-unix.c (hardwire_setparity): Likewise.
---
 gdb/ChangeLog   | 5 +++++
 gdb/ser-mingw.c | 2 +-
 gdb/ser-unix.c  | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e5e9255..77de88a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-23  Joel Brobecker  <brobecker@adacore.com>
+
+	* ser-mingw.c (ser_windows_setparity): Fix indentation.
+	* ser-unix.c (hardwire_setparity): Likewise.
+
 2015-03-23  Yurij Grechishhev  <yurij.grechishhev@gmail.com>
 
 	* NEWS: Mention set/show serial parity command.
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 6d383ac..a6ec374 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -223,7 +223,7 @@ ser_windows_setparity (struct serial *scb, int parity)
       break;
     default:
       internal_warning (__FILE__, __LINE__,
-                  "Incorrect parity value: %d", parity);
+			"Incorrect parity value: %d", parity);
       return -1;
     }
 
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 280fb6a..356e5e7 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -918,7 +918,7 @@ hardwire_setparity (struct serial *scb, int parity)
       break;
     default:
       internal_warning (__FILE__, __LINE__,
-                  "Incorrect parity value: %d", parity);
+			"Incorrect parity value: %d", parity);
       return -1;
     }
 
-- 
1.9.1


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

end of thread, other threads:[~2015-03-23 22:52 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-24 14:29 Setting parity for remote serial Yurij Grechishhev
2013-07-24 16:53 ` Eli Zaretskii
2013-07-25  7:15   ` Yurij Grechishhev
2013-07-25 16:21     ` Eli Zaretskii
     [not found]       ` <CAAyhtXRJaoxvfm7FH06AXeATgscXn4SrY5=ZD_h=BBmPoUdTBQ@mail.gmail.com>
2013-07-29 18:34         ` Eli Zaretskii
2013-07-29 19:25           ` Pedro Alves
2013-07-29 20:14             ` Yurij Grechishhev
2013-07-29 19:04       ` Yurij Grechishhev
2013-09-26 17:00 ` Joel Brobecker
2013-10-02 21:59   ` Yurij Grechishhev
     [not found]   ` <CAAyhtXTmrJ04BVhziaFnogGyWLz7+G+Qwbc9UnHJkrEbDgTjFw@mail.gmail.com>
2013-10-04  7:34     ` Joel Brobecker
2013-10-09  4:11       ` Joel Brobecker
2015-02-25 15:16       ` Joel Brobecker
2015-02-26 19:50         ` Yurij Grechishhev
2015-02-27  8:16           ` Joel Brobecker
2015-03-15 21:49             ` Yurij Grechishhev
2015-03-16  3:32               ` Eli Zaretskii
2015-03-17 14:56               ` Joel Brobecker
2015-03-22 22:52                 ` Yurij Grechishhev
2015-03-23 13:11                   ` Joel Brobecker
2015-03-23 15:36                   ` Eli Zaretskii
2015-03-23 21:21                     ` Yurij Grechishhev
2015-03-23 22:52                       ` pushed: " Joel Brobecker

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).