aboutsummaryrefslogtreecommitdiff
path: root/gdb/ser-unix.c
diff options
context:
space:
mode:
authorYury Grechishchev <yury.grechishchev@yotadevices.com>2015-03-24 00:15:42 +0300
committerJoel Brobecker <brobecker@adacore.com>2015-03-23 15:34:42 -0700
commit236af5e336970a6b58cd17e0a2981bd96f3d09a0 (patch)
tree82297660721160db864fe9d48fcd135af23fce10 /gdb/ser-unix.c
parent32b40af94e919e235c21486110311647cbeecf2e (diff)
downloadgdb-236af5e336970a6b58cd17e0a2981bd96f3d09a0.zip
gdb-236af5e336970a6b58cd17e0a2981bd96f3d09a0.tar.gz
gdb-236af5e336970a6b58cd17e0a2981bd96f3d09a0.tar.bz2
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.
Diffstat (limited to 'gdb/ser-unix.c')
-rw-r--r--gdb/ser-unix.c51
1 files changed, 49 insertions, 2 deletions
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,