This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RFA: [ser-unix.c] Fix handling of baud rates


If the user requests an invalid baud rate (with -b or set remotebaud),
GDB will try to set the serial port speed to -1 and eventually dump
core.

The following patch will cause GDB to use only legal values for the
serial line speed.  If the speed requested is not one of the valid
speeds, the best speed that is less than the value requested will be
used.  However, if the requested speed is less than 50, 50 bauds will be
used.

OK to commit?


-- 
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/04/25 21:54:59
*************** rate_to_code (int rate)
*** 741,750 ****
    int i;
  
    for (i = 0; baudtab[i].rate != -1; i++)
!     if (rate == baudtab[i].rate)
!       return baudtab[i].code;
! 
!   return -1;
  }
  
  static int
--- 741,768 ----
    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)
! 	    {
! 	      /* set to the valid speed immediately below
! 	         or to B50 if the value requested was less
! 		 than 50 bauds. */
! 	      if (i)
! 	        return baudtab[i - 1].code;
! 	      else
! 	        return baudtab[0].code;
! 	    }
!         }
!     }
!  
!   /* If the requested speed was too large, set to the best we can do. */
!   return baudtab[i - 1].code;
  }
  
  static int

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]