From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fernando Nasser To: gdb-patches@sources.redhat.com Subject: Re: RFA: [ser-unix.c] Fix handling of baud rates [REPOST] Date: Thu, 10 May 2001 12:08:00 -0000 Message-id: <3AFAE6AF.CA1B552D@redhat.com> References: <3AE751A5.AE7633E4@redhat.com> X-SW-Source: 2001-05/msg00175.html 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); >From ac131313@cygnus.com Thu May 10 12:23:00 2001 From: Andrew Cagney To: Michael Snyder Cc: gdb-patches@sources.redhat.com, cagney@cygnus.com Subject: Re: [PATCH] factor out some functions in remote.c Date: Thu, 10 May 2001 12:23:00 -0000 Message-id: <3AFAEA9C.2070609@cygnus.com> References: <3AFAE59D.71F434B4@cygnus.com> X-SW-Source: 2001-05/msg00176.html Content-length: 199 > + /* May use a length, or a nul-terminated string as input. */ > + if (count == 0) > + count = strlen (hex) / 2; > + Michael, you've still not addressed my concern about this. Andrew