2005-02-11 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / remote-utils.c
index 21acc2c9ec1ecdf4b51fda32b4d70ba2d749c798..d4775ad631e0016819503e920ee17c9638e161e3 100644 (file)
@@ -1,83 +1,92 @@
 /* Generic support for remote debugging interfaces.
 
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1995, 1996, 1998, 2000, 2001
+   Free Software Foundation, Inc.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 /*  This file actually contains two distinct logical "packages".  They
-    are packaged together in this one file because they are typically
-    used together.
+   are packaged together in this one file because they are typically
+   used together.
 
-    The first package is an addition to the serial package.  The
-    addition provides reading and writing with debugging output and
-    timeouts based on user settable variables.  These routines are
-    intended to support serial port based remote backends.  These
-    functions are prefixed with sr_.
+   The first package is an addition to the serial package.  The
+   addition provides reading and writing with debugging output and
+   timeouts based on user settable variables.  These routines are
+   intended to support serial port based remote backends.  These
+   functions are prefixed with sr_.
 
-    The second package is a collection of more or less generic
-    functions for use by remote backends.  They support user settable
-    variables for debugging, retries, and the like.  
+   The second package is a collection of more or less generic
+   functions for use by remote backends.  They support user settable
+   variables for debugging, retries, and the like.  
 
    Todo:
 
    * a pass through mode a la kermit or telnet.
    * autobaud.
    * ask remote to change his baud rate.
  */
+ */
 
 #include <ctype.h>
 
 #include "defs.h"
+#include "gdb_string.h"
 #include "gdbcmd.h"
 #include "target.h"
 #include "serial.h"
-#include "gdbcore.h" /* for exec_bfd */
-#include "inferior.h" /* for generic_mourn_inferior */
+#include "gdbcore.h"           /* for exec_bfd */
+#include "inferior.h"          /* for generic_mourn_inferior */
 #include "remote-utils.h"
+#include "regcache.h"
+
 
-struct _sr_settings sr_settings = {
-  4, /* timeout:
-       remote-hms.c had 2
-       remote-bug.c had "with a timeout of 2, we time out waiting for
-       the prompt after an s-record dump."
-
-       remote.c had (2): This was 5 seconds, which is a long time to
-       sit and wait. Unless this is going though some terminal server
-       or multiplexer or other form of hairy serial connection, I
-       would think 2 seconds would be plenty.
-*/
-
-  10, /* retries */
-  NULL,        /* device */
-  NULL,        /* descriptor */
+void _initialize_sr_support (void);
+
+struct _sr_settings sr_settings =
+{
+  4,                           /* timeout:
+                                  remote-hms.c had 2
+                                  remote-bug.c had "with a timeout of 2, we time out waiting for
+                                  the prompt after an s-record dump."
+
+                                  remote.c had (2): This was 5 seconds, which is a long time to
+                                  sit and wait. Unless this is going though some terminal server
+                                  or multiplexer or other form of hairy serial connection, I
+                                  would think 2 seconds would be plenty.
+                                */
+
+  10,                          /* retries */
+  NULL,                                /* device */
+  NULL,                                /* descriptor */
 };
 
 struct gr_settings *gr_settings = NULL;
 
+static void usage (char *, char *);
+static void sr_com (char *, int);
+
 static void
-usage(proto, junk)
-     char *proto;
-     char *junk;
+usage (char *proto, char *junk)
 {
   if (junk != NULL)
-    fprintf_unfiltered(gdb_stderr, "Unrecognized arguments: `%s'.\n", junk);
+    fprintf_unfiltered (gdb_stderr, "Unrecognized arguments: `%s'.\n", junk);
 
-  error ("Usage: target %s [DEVICE [SPEED [DEBUG]]]\n\
-where DEVICE is the name of a device or HOST:PORT", proto, proto);
+  error (_("Usage: target %s [DEVICE [SPEED [DEBUG]]]\n\
+where DEVICE is the name of a device or HOST:PORT"), proto);
 
   return;
 }
@@ -94,75 +103,66 @@ where DEVICE is the name of a device or HOST:PORT", proto, proto);
 }
 
 void
-sr_scan_args(proto, args)
-     char *proto;
-     char *args;
+sr_scan_args (char *proto, char *args)
 {
   int n;
   char *p, *q;
 
-  extern int strtol();
-
   /* if no args, then nothing to do. */
   if (args == NULL || *args == '\0')
     return;
 
   /* scan off white space.  */
-  for (p = args; isspace(*p); ++p) ;;
+  for (p = args; isspace (*p); ++p);;
 
   /* find end of device name.  */
-  for (q = p; *q != '\0' && !isspace(*q); ++q) ;;
+  for (q = p; *q != '\0' && !isspace (*q); ++q);;
 
   /* check for missing or empty device name.  */
-  CHECKDONE(p, q);
-  sr_set_device(savestring(p, q - p));
+  CHECKDONE (p, q);
+  sr_set_device (savestring (p, q - p));
 
   /* look for baud rate.  */
-  n = strtol(q, &p, 10);
+  n = strtol (q, &p, 10);
 
   /* check for missing or empty baud rate.  */
-  CHECKDONE(p, q);
-  sr_set_baud_rate(n);
+  CHECKDONE (p, q);
+  baud_rate = n;
 
   /* look for debug value.  */
-  n = strtol(p, &q, 10);
+  n = strtol (p, &q, 10);
 
   /* check for missing or empty debug value.  */
-  CHECKDONE(p, q);
-  sr_set_debug(n);
+  CHECKDONE (p, q);
+  sr_set_debug (n);
 
   /* scan off remaining white space.  */
-  for (p = q; isspace(*p); ++p) ;;
+  for (p = q; isspace (*p); ++p);;
 
   /* if not end of string, then there's unrecognized junk. */
   if (*p != '\0')
-    usage(proto, p);
+    usage (proto, p);
 
   return;
 }
 
 void
-gr_generic_checkin()
+gr_generic_checkin (void)
 {
-  sr_write_cr("");
-  gr_expect_prompt();
+  sr_write_cr ("");
+  gr_expect_prompt ();
 }
 
 void
-gr_open(args, from_tty, gr)
-     char *args;
-     int from_tty;
-     struct gr_settings *gr;
+gr_open (char *args, int from_tty, struct gr_settings *gr)
 {
-  target_preopen(from_tty);
-  sr_scan_args(gr->ops->to_shortname, args);
-  unpush_target(gr->ops);
+  target_preopen (from_tty);
+  sr_scan_args (gr->ops->to_shortname, args);
+  unpush_target (gr->ops);
 
   gr_settings = gr;
 
-  gr_set_dcache(dcache_init(gr->readfunc, gr->writefunc));
-
-  if (sr_get_desc() != NULL)
+  if (sr_get_desc () != NULL)
     gr_close (0);
 
   /* If no args are specified, then we use the device specified by a
@@ -172,36 +172,44 @@ gr_open(args, from_tty, gr)
   if (sr_get_device () == NULL)
     usage (gr->ops->to_shortname, NULL);
 
-  sr_set_desc(SERIAL_OPEN (sr_get_device()));
-  if (!sr_get_desc())
-    perror_with_name((char *) sr_get_device());
+  sr_set_desc (serial_open (sr_get_device ()));
+  if (!sr_get_desc ())
+    perror_with_name ((char *) sr_get_device ());
 
-  if (SERIAL_SETBAUDRATE(sr_get_desc(), sr_get_baud_rate()) != 0)
+  if (baud_rate != -1)
     {
-      SERIAL_CLOSE(sr_get_desc());
-      perror_with_name(sr_get_device());
+      if (serial_setbaudrate (sr_get_desc (), baud_rate) != 0)
+       {
+         serial_close (sr_get_desc ());
+         perror_with_name (sr_get_device ());
+       }
     }
 
-  SERIAL_RAW (sr_get_desc());
+  serial_raw (sr_get_desc ());
 
   /* If there is something sitting in the buffer we might take it as a
      response to a command, which would be bad.  */
-  SERIAL_FLUSH_INPUT (sr_get_desc ());
+  serial_flush_input (sr_get_desc ());
 
   /* default retries */
-  if (sr_get_retries() == 0)
-    sr_set_retries(1);
+  if (sr_get_retries () == 0)
+    sr_set_retries (1);
 
   /* default clear breakpoint function */
   if (gr_settings->clear_all_breakpoints == NULL)
     gr_settings->clear_all_breakpoints = remove_breakpoints;
 
   if (from_tty)
-      printf_filtered ("Remote debugging using `%s' at baud rate of %d\n",
-                      sr_get_device(), sr_get_baud_rate());
+    {
+      printf_filtered ("Remote debugging using `%s'", sr_get_device ());
+      if (baud_rate != -1)
+       printf_filtered (" at baud rate of %d",
+                        baud_rate);
+      printf_filtered ("\n");
+    }
 
-  push_target(gr->ops);
-  gr_checkin();
+  push_target (gr->ops);
+  gr_checkin ();
   gr_clear_all_breakpoints ();
   return;
 }
@@ -210,34 +218,36 @@ gr_open(args, from_tty, gr)
    and doing all the fancy timeout stuff.  */
 
 int
-sr_readchar ()
+sr_readchar (void)
 {
   int buf;
 
-  buf = SERIAL_READCHAR (sr_get_desc(), sr_get_timeout());
+  buf = serial_readchar (sr_get_desc (), sr_get_timeout ());
 
   if (buf == SERIAL_TIMEOUT)
-    error ("Timeout reading from remote system.");
+    error (_("Timeout reading from remote system."));
 
-  if (sr_get_debug() > 0)
+  if (sr_get_debug () > 0)
     printf_unfiltered ("%c", buf);
 
   return buf & 0x7f;
 }
 
 int
-sr_pollchar()
+sr_pollchar (void)
 {
   int buf;
 
-  buf = SERIAL_READCHAR (sr_get_desc(), 0);
+  buf = serial_readchar (sr_get_desc (), 0);
   if (buf == SERIAL_TIMEOUT)
     buf = 0;
-  if (sr_get_debug() > 0)
-    if (buf)
-      printf_unfiltered ("%c", buf);
-    else
-      printf_unfiltered ("<empty character poll>");
+  if (sr_get_debug () > 0)
+    {
+      if (buf)
+       printf_unfiltered ("%c", buf);
+      else
+       printf_unfiltered ("<empty character poll>");
+    }
 
   return buf & 0x7f;
 }
@@ -245,12 +255,11 @@ sr_pollchar()
 /* Keep discarding input from the remote system, until STRING is found.
    Let the user break out immediately.  */
 void
-sr_expect (string)
-     char *string;
+sr_expect (char *string)
 {
   char *p = string;
 
-  immediate_quit = 1;
+  immediate_quit++;
   while (1)
     {
       if (sr_readchar () == *p)
@@ -258,7 +267,7 @@ sr_expect (string)
          p++;
          if (*p == '\0')
            {
-             immediate_quit = 0;
+             immediate_quit--;
              return;
            }
        }
@@ -268,16 +277,14 @@ sr_expect (string)
 }
 
 void
-sr_write (a, l)
-     char *a;
-     int l;
+sr_write (char *a, int l)
 {
   int i;
 
-  if (SERIAL_WRITE (sr_get_desc(), a, l) != 0)
-    perror_with_name ("sr_write: Error writing to remote");
+  if (serial_write (sr_get_desc (), a, l) != 0)
+    perror_with_name (_("sr_write: Error writing to remote"));
 
-  if (sr_get_debug() > 0)
+  if (sr_get_debug () > 0)
     for (i = 0; i < l; i++)
       printf_unfiltered ("%c", a[i]);
 
@@ -285,8 +292,7 @@ sr_write (a, l)
 }
 
 void
-sr_write_cr (s)
-     char *s;
+sr_write_cr (char *s)
 {
   sr_write (s, strlen (s));
   sr_write ("\r", 1);
@@ -294,9 +300,7 @@ sr_write_cr (s)
 }
 
 int
-sr_timed_read (buf, n)
-     char *buf;
-     int n;
+sr_timed_read (char *buf, int n)
 {
   int i;
   char c;
@@ -319,8 +323,7 @@ sr_timed_read (buf, n)
    ignore_space is nonzero, ignore spaces (not newline, tab, etc).  */
 
 int
-sr_get_hex_digit (ignore_space)
-     int ignore_space;
+sr_get_hex_digit (int ignore_space)
 {
   int ch;
 
@@ -336,7 +339,7 @@ sr_get_hex_digit (ignore_space)
       else if (ch != ' ' || !ignore_space)
        {
          gr_expect_prompt ();
-         error ("Invalid hex digit from remote system.");
+         error (_("Invalid hex digit from remote system."));
        }
     }
 }
@@ -344,8 +347,7 @@ sr_get_hex_digit (ignore_space)
 /* Get a byte from the remote and put it in *BYT.  Accept any number
    leading spaces.  */
 void
-sr_get_hex_byte (byt)
-     char *byt;
+sr_get_hex_byte (char *byt)
 {
   int val;
 
@@ -356,7 +358,7 @@ sr_get_hex_byte (byt)
 
 /* Read a 32-bit hex word from the remote, preceded by a space  */
 long
-sr_get_hex_word ()
+sr_get_hex_word (void)
 {
   long val;
   int j;
@@ -373,10 +375,8 @@ sr_get_hex_word ()
    prompt from the remote is seen.
    FIXME: Can't handle commands that take input.  */
 
-void
-sr_com (args, fromtty)
-     char *args;
-     int fromtty;
+static void
+sr_com (char *args, int fromtty)
 {
   sr_check_open ();
 
@@ -387,19 +387,19 @@ sr_com (args, fromtty)
 
   sr_write_cr (args);
   sr_write ("\030", 1);
+  registers_changed ();
   gr_expect_prompt ();
 }
 
 void
-gr_close(quitting)
-     int quitting;
+gr_close (int quitting)
 {
-  gr_clear_all_breakpoints();
+  gr_clear_all_breakpoints ();
 
-  if (sr_is_open())
+  if (sr_is_open ())
     {
-      SERIAL_CLOSE (sr_get_desc());
-      sr_set_desc(NULL);
+      serial_close (sr_get_desc ());
+      sr_set_desc (NULL);
     }
 
   return;
@@ -414,14 +414,12 @@ gr_close(quitting)
    with your gdb.  */
 
 void
-gr_detach(args, from_tty)
-     char *args;
-     int from_tty;
+gr_detach (char *args, int from_tty)
 {
   if (args)
-    error ("Argument given to \"detach\" when remotely debugging.");
-  
-  if (sr_is_open())
+    error (_("Argument given to \"detach\" when remotely debugging."));
+
+  if (sr_is_open ())
     gr_clear_all_breakpoints ();
 
   pop_target ();
@@ -429,17 +427,18 @@ gr_detach(args, from_tty)
     puts_filtered ("Ending remote debugging.\n");
 
   return;
-}  
+}
 
 void
-gr_files_info (ops)
-     struct target_ops *ops;
+gr_files_info (struct target_ops *ops)
 {
 #ifdef __GO32__
   printf_filtered ("\tAttached to DOS asynctsr\n");
 #else
-  printf_filtered ("\tAttached to %s at %d baud\n",
-                  sr_get_device(), sr_get_baud_rate());
+  printf_filtered ("\tAttached to %s", sr_get_device ());
+  if (baud_rate != -1)
+    printf_filtered ("at %d baud", baud_rate);
+  printf_filtered ("\n");
 #endif
 
   if (exec_bfd)
@@ -451,15 +450,15 @@ gr_files_info (ops)
 }
 
 void
-gr_mourn ()
+gr_mourn (void)
 {
   gr_clear_all_breakpoints ();
-  unpush_target (gr_get_ops());
+  unpush_target (gr_get_ops ());
   generic_mourn_inferior ();
 }
 
 void
-gr_kill ()
+gr_kill (void)
 {
   return;
 }
@@ -467,18 +466,15 @@ gr_kill ()
 /* This is called not only when we first attach, but also when the
    user types "run" after having attached.  */
 void
-gr_create_inferior (execfile, args, env)
-     char *execfile;
-     char *args;
-     char **env;
+gr_create_inferior (char *execfile, char *args, char **env)
 {
   int entry_pt;
 
   if (args && *args)
-    error ("Can't pass arguments to remote process.");
+    error (_("Can't pass arguments to remote process."));
 
   if (execfile == 0 || exec_bfd == 0)
-    error ("No exec file specified");
+    error (_("No executable file specified"));
 
   entry_pt = (int) bfd_get_start_address (exec_bfd);
   sr_check_open ();
@@ -487,7 +483,7 @@ gr_create_inferior (execfile, args, env)
   gr_clear_all_breakpoints ();
 
   init_wait_for_inferior ();
-  gr_checkin();
+  gr_checkin ();
 
   insert_breakpoints ();       /* Needed to get correct instruction in cache */
   proceed (entry_pt, -1, 0);
@@ -501,12 +497,10 @@ gr_create_inferior (execfile, args, env)
    pass non-matching data on.  */
 
 int
-gr_multi_scan (list, passthrough)
-     char *list[];
-     int passthrough;
+gr_multi_scan (char *list[], int passthrough)
 {
-  char *swallowed = NULL; /* holding area */
-  char *swallowed_p = swallowed; /* Current position in swallowed.  */
+  char *swallowed = NULL;      /* holding area */
+  char *swallowed_p = swallowed;       /* Current position in swallowed.  */
   int ch;
   int ch_handled;
   int i;
@@ -521,7 +515,7 @@ gr_multi_scan (list, passthrough)
        list[i] != NULL;
        ++i, ++string_count)
     {
-      int length = strlen(list[i]);
+      int length = strlen (list[i]);
 
       if (length > max_length)
        max_length = length;
@@ -529,22 +523,22 @@ gr_multi_scan (list, passthrough)
 
   /* if we have no strings, then something is wrong. */
   if (string_count == 0)
-    return(-1);
+    return (-1);
 
   /* otherwise, we will need a holding area big enough to hold almost two
      copies of our largest string.  */
-  swallowed_p = swallowed = alloca(max_length << 1);
+  swallowed_p = swallowed = alloca (max_length << 1);
 
   /* and a list of pointers to current scan points. */
-  plist = (char **) alloca (string_count * sizeof(*plist));
+  plist = (char **) alloca (string_count * sizeof (*plist));
 
   /* and initialize */
   for (i = 0; i < string_count; ++i)
     plist[i] = list[i];
 
-  for (ch = sr_readchar(); /* loop forever */ ; ch = sr_readchar())
+  for (ch = sr_readchar (); /* loop forever */ ; ch = sr_readchar ())
     {
-      QUIT; /* Let user quit and leave process running */
+      QUIT;                    /* Let user quit and leave process running */
       ch_handled = 0;
 
       for (i = 0; i < string_count; ++i)
@@ -553,7 +547,7 @@ gr_multi_scan (list, passthrough)
            {
              ++plist[i];
              if (*plist[i] == '\0')
-               return(i);
+               return (i);
 
              if (!ch_handled)
                *swallowed_p++ = ch;
@@ -582,7 +576,7 @@ gr_multi_scan (list, passthrough)
     }
 #if 0
   /* Never reached.  */
-  return(-1);
+  return (-1);
 #endif
 }
 
@@ -593,99 +587,22 @@ gr_multi_scan (list, passthrough)
    debugged.  */
 
 void
-gr_prepare_to_store ()
+gr_prepare_to_store (void)
 {
   /* Do nothing, since we assume we can store individual regs */
 }
 
-/* Read a word from remote address ADDR and return it.
- * This goes through the data cache.
- */
-int
-gr_fetch_word (addr)
-     CORE_ADDR addr;
-{
-  return dcache_fetch (gr_get_dcache(), addr);
-}
-
-/* Write a word WORD into remote address ADDR.
-   This goes through the data cache.  */
-
-void
-gr_store_word (addr, word)
-     CORE_ADDR addr;
-     int word;
-{
-  dcache_poke (gr_get_dcache(), addr, word);
-}
-
-/* general purpose load a file specified on the command line
-   into target memory. */
-
-void
-gr_load_image (args, fromtty)
-     char *args;
-     int fromtty;
-{
-  bfd *abfd;
-
-  asection *s;
-  struct cleanup *old_cleanups;
-  int delta = 4096;
-  char *buffer = xmalloc (delta);
-
-  abfd = bfd_openr (args, (char *) 0);
-
-  if (!abfd)
-    perror_with_name (args);
-
-  old_cleanups = make_cleanup (bfd_close, abfd);
-
-  QUIT;
-
-  if (!bfd_check_format (abfd, bfd_object))
-    error ("It doesn't seem to be an object file.\n");
-
-  for (s = abfd->sections; s && !quit_flag; s = s->next)
-    {
-      if (bfd_get_section_flags (abfd, s) & SEC_LOAD)
-       {
-         int i;
-         printf_filtered ("%s\t: 0x%4x .. 0x%4x  ",
-                          s->name, s->vma, s->vma + s->_raw_size);
-         fflush (stdout);
-         for (i = 0; i < s->_raw_size && !quit_flag; i += delta)
-           {
-             int sub_delta = delta;
-             if (sub_delta > s->_raw_size - i)
-               sub_delta = s->_raw_size - i;
-             QUIT;
-             bfd_get_section_contents (abfd, s, buffer, i, sub_delta);
-             target_write_memory (s->vma + i, buffer, sub_delta);
-             printf_filtered ("*");
-             fflush (stdout);
-           }
-         printf_filtered ("\n");
-       }
-    }
-
-  free (buffer);
-  write_pc (bfd_get_start_address (abfd));
-  bfd_close (abfd);
-  discard_cleanups (old_cleanups);
-}
-
-
 void
-_initialize_sr_support ()
+_initialize_sr_support (void)
 {
 /* FIXME-now: if target is open... */
-  add_show_from_set (add_set_cmd ("remotedevice", no_class,
-                                 var_filename, (char *)&sr_settings.device,
-                                 "Set device for remote serial I/O.\n\
+  deprecated_add_show_from_set
+    (add_set_cmd ("remotedevice", no_class,
+                 var_filename, (char *) &sr_settings.device,
+                 "Set device for remote serial I/O.\n\
 This device is used as the serial port when debugging using remote\n\
 targets.", &setlist),
-                    &showlist);
+     &showlist);
 
   add_com ("remote <command>", class_obscure, sr_com,
           "Send a command to the remote monitor.");
This page took 0.034622 seconds and 4 git commands to generate.