(getopt): Allow full prototype when builind under FreeBSD.
[deliverable/binutils-gdb.git] / gdb / remote.c
index 2cca182370283d5b2dc13fac38828a89e6f32e48..ed57631ac80fb69228508900b2613b2de25fcc57 100644 (file)
@@ -1,7 +1,7 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
 
    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -41,6 +41,7 @@
 #include "regcache.h"
 #include "value.h"
 #include "gdb_assert.h"
+#include "observer.h"
 
 #include <ctype.h>
 #include <sys/time.h>
@@ -412,9 +413,9 @@ get_memory_packet_size (struct memory_packet_config *config)
 #ifndef MAX_REMOTE_PACKET_SIZE
 #define MAX_REMOTE_PACKET_SIZE 16384
 #endif
-  /* NOTE: 16 is just chosen at random.  */
+  /* NOTE: 20 ensures we can write at least one byte.  */
 #ifndef MIN_REMOTE_PACKET_SIZE
-#define MIN_REMOTE_PACKET_SIZE 16
+#define MIN_REMOTE_PACKET_SIZE 20
 #endif
   long what_they_get;
   if (config->fixed_p)
@@ -659,8 +660,7 @@ add_packet_config_cmd (struct packet_config *config,
   /* set/show TITLE-packet {auto,on,off} */
   cmd_name = xstrprintf ("%s-packet", title);
   add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
-                               &config->detect, set_doc, show_doc,
-                               "", NULL /* FIXME: i18n: Print message is? */,
+                               &config->detect, set_doc, show_doc, NULL, /* help_doc */
                                set_func, show_func,
                                set_remote_list, show_remote_list);
   /* set/show remote NAME-packet {auto,on,off} -- legacy.  */
@@ -2312,6 +2312,8 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target,
       remote_check_symbols (symfile_objfile);
     }
 #endif
+
+  observer_notify_inferior_created (&current_target, from_tty);
 }
 
 /* This takes a program previously attached to and detaches it.  After
@@ -3330,6 +3332,7 @@ remote_fetch_registers (int regnum)
      in the buffer is not a hex character, assume that has happened
      and try to fetch another packet to read.  */
   while ((buf[0] < '0' || buf[0] > '9')
+        && (buf[0] < 'A' || buf[0] > 'F')
         && (buf[0] < 'a' || buf[0] > 'f')
         && buf[0] != 'x')      /* New: unavailable register value.  */
     {
@@ -3657,16 +3660,18 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
   /* Verify that the target can support a binary download.  */
   check_binary_download (memaddr);
 
+  payload_size = get_memory_write_packet_size ();
+  
   /* Compute the size, and then allocate space for the largest
-     possible packet.  Include space for an extra trailing NULL.  */
-  sizeof_buf = get_memory_write_packet_size () + 1;
+     possible packet.  Include space for an extra trailing NUL.  */
+  sizeof_buf = payload_size + 1;
   buf = alloca (sizeof_buf);
 
   /* Compute the size of the actual payload by subtracting out the
-     packet header and footer overhead: "$M<memaddr>,<len>:...#nn".  */
-  payload_size = (get_memory_write_packet_size () - (strlen ("$M,:#NN")
-                                                    + hexnumlen (memaddr)
-                                                    + hexnumlen (len)));
+     packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
+     */
+  payload_size -= strlen ("$M,:#NN");
+  payload_size -= hexnumlen (memaddr);
 
   /* Construct the packet header: "[MX]<memaddr>,<len>:".   */
 
@@ -3679,11 +3684,15 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
       *p++ = 'X';
       /* Best guess at number of bytes that will fit.  */
       todo = min (len, payload_size);
+      payload_size -= hexnumlen (todo);
+      todo = min (todo, payload_size);
       break;
     case PACKET_DISABLE:
       *p++ = 'M';
       /* Num bytes that will fit.  */
       todo = min (len, payload_size / 2);
+      payload_size -= hexnumlen (todo);
+      todo = min (todo, payload_size / 2);
       break;
     case PACKET_SUPPORT_UNKNOWN:
       internal_error (__FILE__, __LINE__,
@@ -3691,6 +3700,9 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
     default:
       internal_error (__FILE__, __LINE__, _("bad switch"));
     }
+  if (todo <= 0)
+    internal_error (__FILE__, __LINE__,
+                   _("minumum packet size too small to write data"));
 
   /* Append "<memaddr>".  */
   memaddr = remote_address_masked (memaddr);
@@ -5310,9 +5322,11 @@ Fetch and print the remote list of thread identifiers, one pkt only"));
 static char *
 remote_pid_to_str (ptid_t ptid)
 {
-  static char buf[30];
+  static char buf[32];
+  int size;
 
-  sprintf (buf, "Thread %d", PIDGET (ptid));
+  size = snprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid));
+  gdb_assert (size < sizeof buf);
   return buf;
 }
 
@@ -5624,8 +5638,7 @@ terminating `#' character and checksum."),
 Set whether to send break if interrupted."), _("\
 Show whether to send break if interrupted."), _("\
 If set, a break, instead of a cntrl-c, is sent to the remote target."),
-                          NULL, /* FIXME: i18n: Whether to send break if interrupted is %s.  */
-                          NULL, NULL,
+                          NULL, NULL, /* FIXME: i18n: Whether to send break if interrupted is %s.  */
                           &setlist, &showlist);
 
   /* Install commands for configuring memory read/write packets.  */
@@ -5666,25 +5679,23 @@ further restriction and ``limit'' to enable that restriction."),
 Set the maximum number of target hardware watchpoints."), _("\
 Show the maximum number of target hardware watchpoints."), _("\
 Specify a negative limit for unlimited."),
-                           NULL, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s.  */
-                           NULL, NULL,
+                           NULL, NULL, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s.  */
                            &remote_set_cmdlist, &remote_show_cmdlist);
   add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
                            &remote_hw_breakpoint_limit, _("\
 Set the maximum number of target hardware breakpoints."), _("\
 Show the maximum number of target hardware breakpoints."), _("\
 Specify a negative limit for unlimited."),
-                           NULL, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s.  */
-                           NULL, NULL,
+                           NULL, NULL, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s.  */
                            &remote_set_cmdlist, &remote_show_cmdlist);
 
-  deprecated_add_show_from_set
-    (add_set_cmd ("remoteaddresssize", class_obscure,
-                 var_integer, (char *) &remote_address_size,
-                 "Set the maximum size of the address (in bits) \
-in a memory packet.\n",
-                 &setlist),
-     &showlist);
+  add_setshow_integer_cmd ("remoteaddresssize", class_obscure,
+                          &remote_address_size, _("\
+Set the maximum size of the address (in bits) in a memory packet."), _("\
+Show the maximum size of the address (in bits) in a memory packet."), NULL,
+                          NULL,
+                          NULL, /* FIXME: i18n: */
+                          &setlist, &showlist);
 
   add_packet_config_cmd (&remote_protocol_binary_download,
                         "X", "binary-download",
@@ -5692,15 +5703,6 @@ in a memory packet.\n",
                         show_remote_protocol_binary_download_cmd,
                         &remote_set_cmdlist, &remote_show_cmdlist,
                         1);
-#if 0
-  /* XXXX - should ``set remotebinarydownload'' be retained for
-     compatibility.  */
-  deprecated_add_show_from_set
-    (add_set_cmd ("remotebinarydownload", no_class,
-                 var_boolean, (char *) &remote_binary_download,
-                 "Set binary downloads.\n", &setlist),
-     &showlist);
-#endif
 
   add_packet_config_cmd (&remote_protocol_vcont,
                         "vCont", "verbose-resume",
@@ -5779,9 +5781,8 @@ Set use of remote protocol `Z' packets"), _("\
 Show use of remote protocol `Z' packets "), _("\
 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
 packets."),
-                               NULL, /* FIXME: i18n: Use of remote protocol `Z' packets is %s.  */
                                set_remote_protocol_Z_packet_cmd,
-                               show_remote_protocol_Z_packet_cmd,
+                               show_remote_protocol_Z_packet_cmd, /* FIXME: i18n: Use of remote protocol `Z' packets is %s.  */
                                &remote_set_cmdlist, &remote_show_cmdlist);
 
   /* Eventually initialize fileio.  See fileio.c */
This page took 0.025885 seconds and 4 git commands to generate.