From: Fernando Nasser <fnasser@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: Re: RFA: [ser-unix.c] Fix handling of baud rates [REPOST]
Date: Fri, 11 May 2001 11:31:00 -0000 [thread overview]
Message-ID: <3AFC2F83.E7B3F3DB@redhat.com> (raw)
In-Reply-To: <3AFAE6AF.CA1B552D@redhat.com>
Well, I have already addressed JT and Eli's concerns. Eli has reviewed
this last version and said it is OK.
I could not find a specific maintainer for ser-unix.c to get a formal
approval. This has been around for a while and no one besides JT and Eli
had any objection, so I guess it is time to check it in. We can't leave
GDB dumping core for such a simple user input error.
I will commit the change.
Fernando
Fernando Nasser wrote:
>
> This patch implements what was discussed with JT and Eli. An error is
> now being issued when the set baud rate is invalid. Here is the output:
>
> ./gdb -nw -b 30
>
> (gdb) target remote /dev/ttyS0
> warning: Invalid baud rate 30. Minimum value is 50.
> /dev/ttyS0: Invalid argument.
> (gdb)
>
> ./gdb -nw -b 200000
>
> (gdb) target remote /dev/ttyS0
> warning: Invalid baud rate 200000. Closest values are 115200 and
> 230400.
> /dev/ttyS0: Invalid argument.
> (gdb)
>
> ./gdb -nw -b 500000
>
> (gdb) target remote /dev/ttyS0
> warning: Invalid baud rate 500000. Maximum value is 460800.
> /dev/ttyS0: Invalid argument.
> (gdb)
>
> The patch is attached. With it, I will fix the calls to
> SERIAL_SETBAUDRATE in the few targets that "forgot" to check for the
> return code:
> nindy-share/nindy.c
> remote-e7000.c
> remote-st.c
>
> OK to commit now?
>
> ChangeLog:
>
> * ser-unix.c (rate_to_code): Issue warning if baud rate is invalid.
> (hardwire_setbaudrate): Set errno to EINVAl and return with error
> if the conversion of the baud rate to code fails.
>
> --
> Fernando Nasser
> Red Hat Canada Ltd. E-Mail: fnasser@redhat.com
> 2323 Yonge Street, Suite #300
> Toronto, Ontario M4P 2C9
>
> ------------------------------------------------------------------------
> Index: ser-unix.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/ser-unix.c,v
> retrieving revision 1.12
> diff -c -p -r1.12 ser-unix.c
> *** ser-unix.c 2001/03/06 08:21:16 1.12
> --- ser-unix.c 2001/05/10 18:54:36
> *************** rate_to_code (int rate)
> *** 741,749 ****
> int i;
>
> for (i = 0; baudtab[i].rate != -1; i++)
> ! if (rate == baudtab[i].rate)
> ! return baudtab[i].code;
> !
> return -1;
> }
>
> --- 741,773 ----
> int i;
>
> for (i = 0; baudtab[i].rate != -1; i++)
> ! {
> ! /* test for perfect macth. */
> ! if (rate == baudtab[i].rate)
> ! return baudtab[i].code;
> ! else
> ! {
> ! /* check if it is in between valid values. */
> ! if (rate < baudtab[i].rate)
> ! {
> ! if (i)
> ! {
> ! warning ("Invalid baud rate %d. Closest values are %d and %d.",
> ! rate, baudtab[i - 1].rate, baudtab[i].rate);
> ! }
> ! else
> ! {
> ! warning ("Invalid baud rate %d. Minimum value is %d.",
> ! rate, baudtab[0].rate);
> ! }
> ! return -1;
> ! }
> ! }
> ! }
> !
> ! /* The requested speed was too large. */
> ! warning ("Invalid baud rate %d. Maximum value is %d.",
> ! rate, baudtab[i - 1].rate);
> return -1;
> }
>
> *************** static int
> *** 751,763 ****
> hardwire_setbaudrate (serial_t scb, int rate)
> {
> struct hardwire_ttystate state;
>
> if (get_tty_state (scb, &state))
> return -1;
>
> #ifdef HAVE_TERMIOS
> ! cfsetospeed (&state.termios, rate_to_code (rate));
> ! cfsetispeed (&state.termios, rate_to_code (rate));
> #endif
>
> #ifdef HAVE_TERMIO
> --- 775,796 ----
> hardwire_setbaudrate (serial_t scb, int rate)
> {
> struct hardwire_ttystate state;
> + int baud_code = rate_to_code (rate);
> +
> + if (baud_code < 0)
> + {
> + /* The baud rate was not valid.
> + A warning has already been issued. */
> + errno = EINVAL;
> + return -1;
> + }
>
> if (get_tty_state (scb, &state))
> return -1;
>
> #ifdef HAVE_TERMIOS
> ! cfsetospeed (&state.termios, baud_code);
> ! cfsetispeed (&state.termios, baud_code);
> #endif
>
> #ifdef HAVE_TERMIO
> *************** hardwire_setbaudrate (serial_t scb, int
> *** 766,777 ****
> #endif
>
> state.termio.c_cflag &= ~(CBAUD | CIBAUD);
> ! state.termio.c_cflag |= rate_to_code (rate);
> #endif
>
> #ifdef HAVE_SGTTY
> ! state.sgttyb.sg_ispeed = rate_to_code (rate);
> ! state.sgttyb.sg_ospeed = rate_to_code (rate);
> #endif
>
> return set_tty_state (scb, &state);
> --- 799,810 ----
> #endif
>
> state.termio.c_cflag &= ~(CBAUD | CIBAUD);
> ! state.termio.c_cflag |= baud_code;
> #endif
>
> #ifdef HAVE_SGTTY
> ! state.sgttyb.sg_ispeed = baud_code;
> ! state.sgttyb.sg_ospeed = baud_code;
> #endif
>
> return set_tty_state (scb, &state);
--
Fernando Nasser
Red Hat Canada Ltd. E-Mail: fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario M4P 2C9
prev parent reply other threads:[~2001-05-11 11:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-25 15:39 RFA: [ser-unix.c] Fix handling of baud rates Fernando Nasser
2001-04-26 0:29 ` Eli Zaretskii
2001-04-26 7:17 ` Fernando Nasser
[not found] ` <1659-Thu26Apr2001173526+0300-eliz@is.elta.co.il>
2001-04-26 7:47 ` Fernando Nasser
2001-04-26 9:44 ` Eli Zaretskii
2001-05-10 12:08 ` RFA: [ser-unix.c] Fix handling of baud rates [REPOST] Fernando Nasser
2001-05-11 1:17 ` Eli Zaretskii
2001-05-11 11:31 ` Fernando Nasser [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3AFC2F83.E7B3F3DB@redhat.com \
--to=fnasser@redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox