Fix all failing FPXX tests for tx39-elf.
[platform/upstream/binutils.git] / gdb / serial.c
index 3202b0f..791f12f 100644 (file)
@@ -1,6 +1,6 @@
 /* Generic serial interface routines
 
-   Copyright (C) 1992-2013 Free Software Foundation, Inc.
+   Copyright (C) 1992-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +20,6 @@
 #include "defs.h"
 #include <ctype.h>
 #include "serial.h"
-#include "gdb_string.h"
 #include "gdbcmd.h"
 #include "cli/cli-utils.h"
 
@@ -30,9 +29,12 @@ extern void _initialize_serial (void);
 
 static unsigned int global_serial_debug_p;
 
-/* Linked list of serial I/O handlers.  */
+typedef const struct serial_ops *serial_ops_p;
+DEF_VEC_P (serial_ops_p);
 
-static struct serial_ops *serial_ops_list = NULL;
+/* Serial I/O handlers.  */
+
+VEC (serial_ops_p) *serial_ops_list = NULL;
 
 /* Pointer to list of scb's.  */
 
@@ -44,7 +46,7 @@ static struct serial *scb_base;
 static char *serial_logfile = NULL;
 static struct ui_file *serial_logfp = NULL;
 
-static struct serial_ops *serial_interface_lookup (const char *);
+static const struct serial_ops *serial_interface_lookup (const char *);
 static void serial_logchar (struct ui_file *stream,
                            int ch_type, int ch, int timeout);
 static const char logbase_hex[] = "hex";
@@ -127,7 +129,7 @@ serial_logchar (struct ui_file *stream, int ch_type, int ch, int timeout)
 }
 
 void
-serial_log_command (const char *cmd)
+serial_log_command (struct target_ops *self, const char *cmd)
 {
   if (!serial_logfp)
     return;
@@ -143,12 +145,13 @@ serial_log_command (const char *cmd)
 }
 
 \f
-static struct serial_ops *
+static const struct serial_ops *
 serial_interface_lookup (const char *name)
 {
-  struct serial_ops *ops;
+  const struct serial_ops *ops;
+  int i;
 
-  for (ops = serial_ops_list; ops; ops = ops->next)
+  for (i = 0; VEC_iterate (serial_ops_p, serial_ops_list, i, ops); ++i)
     if (strcmp (name, ops->name) == 0)
       return ops;
 
@@ -156,10 +159,9 @@ serial_interface_lookup (const char *name)
 }
 
 void
-serial_add_interface (struct serial_ops *optable)
+serial_add_interface (const struct serial_ops *optable)
 {
-  optable->next = serial_ops_list;
-  serial_ops_list = optable;
+  VEC_safe_push (serial_ops_p, serial_ops_list, optable);
 }
 
 /* Return the open serial device for FD, if found, or NULL if FD is
@@ -183,7 +185,7 @@ struct serial *
 serial_open (const char *name)
 {
   struct serial *scb;
-  struct serial_ops *ops;
+  const struct serial_ops *ops;
   const char *open_name = name;
 
   if (strcmp (name, "pc") == 0)
@@ -208,7 +210,7 @@ serial_open (const char *name)
   if (!ops)
     return NULL;
 
-  scb = XMALLOC (struct serial);
+  scb = XNEW (struct serial);
 
   scb->ops = ops;
 
@@ -246,7 +248,7 @@ serial_open (const char *name)
    interface ops OPS.  */
 
 static struct serial *
-serial_fdopen_ops (const int fd, struct serial_ops *ops)
+serial_fdopen_ops (const int fd, const struct serial_ops *ops)
 {
   struct serial *scb;
 
@@ -260,7 +262,7 @@ serial_fdopen_ops (const int fd, struct serial_ops *ops)
   if (!ops)
     return NULL;
 
-  scb = XCALLOC (1, struct serial);
+  scb = XCNEW (struct serial);
 
   scb->ops = ops;
 
@@ -398,14 +400,15 @@ serial_readchar (struct serial *scb, int timeout)
 }
 
 int
-serial_write (struct serial *scb, const char *str, int len)
+serial_write (struct serial *scb, const void *buf, size_t count)
 {
   if (serial_logfp != NULL)
     {
-      int count;
+      const char *str = buf;
+      size_t c;
 
-      for (count = 0; count < len; count++)
-       serial_logchar (serial_logfp, 'w', str[count] & 0xff, 0);
+      for (c = 0; c < count; c++)
+       serial_logchar (serial_logfp, 'w', str[c] & 0xff, 0);
 
       /* Make sure that the log file is as up-to-date as possible,
          in case we are getting ready to dump core or something.  */
@@ -413,18 +416,19 @@ serial_write (struct serial *scb, const char *str, int len)
     }
   if (serial_debug_p (scb))
     {
-      int count;
+      const char *str = buf;
+      size_t c;
 
-      for (count = 0; count < len; count++)
+      for (c = 0; c < count; c++)
        {
          fprintf_unfiltered (gdb_stdlog, "[");
-         serial_logchar (gdb_stdlog, 'w', str[count] & 0xff, 0);
+         serial_logchar (gdb_stdlog, 'w', str[c] & 0xff, 0);
          fprintf_unfiltered (gdb_stdlog, "]");
        }
       gdb_flush (gdb_stdlog);
     }
 
-  return (scb->ops->write (scb, str, len));
+  return (scb->ops->write (scb, buf, count));
 }
 
 void
@@ -582,7 +586,7 @@ serial_done_wait_handle (struct serial *scb)
 int
 serial_pipe (struct serial *scbs[2])
 {
-  struct serial_ops *ops;
+  const struct serial_ops *ops;
   int fildes[2];
 
   ops = serial_interface_lookup ("pipe");
@@ -610,7 +614,7 @@ serial_set_cmd (char *args, int from_tty)
 {
   printf_unfiltered ("\"set serial\" must be followed "
                     "by the name of a command.\n");
-  help_list (serial_set_cmdlist, "set serial ", -1, gdb_stdout);
+  help_list (serial_set_cmdlist, "set serial ", all_commands, gdb_stdout);
 }
 
 static void
@@ -619,6 +623,20 @@ serial_show_cmd (char *args, int from_tty)
   cmd_show_list (serial_show_cmdlist, from_tty, "");
 }
 
+/* Baud rate specified for talking to serial target systems.  Default
+   is left as -1, so targets can choose their own defaults.  */
+/* FIXME: This means that "show serial baud" and gr_files_info can
+   print -1 or (unsigned int)-1.  This is a Bad User Interface.  */
+
+int baud_rate = -1;
+
+static void
+serial_baud_show_cmd (struct ui_file *file, int from_tty,
+                     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Baud rate for remote serial I/O is %s.\n"),
+                   value);
+}
 
 void
 _initialize_serial (void)
@@ -641,6 +659,17 @@ Show default serial/parallel port configuration."),
                  0/*allow-unknown*/,
                  &showlist);
 
+  /* If target is open when baud changes, it doesn't take effect until
+     the next open (I think, not sure).  */
+  add_setshow_zinteger_cmd ("baud", no_class, &baud_rate, _("\
+Set baud rate for remote serial I/O."), _("\
+Show baud rate for remote serial I/O."), _("\
+This value is used to set the speed of the serial port when debugging\n\
+using remote targets."),
+                           NULL,
+                           serial_baud_show_cmd,
+                           &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."), _("\