gdbserver: Remove traces of ancient Hc handling
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
index 99dedb2fed923f6be6eea3188f98e0e1c6b39928..a5743b5481874e7a2274f563e2e869aadb92ce0a 100644 (file)
@@ -969,7 +969,7 @@ gdb_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
   res = prepare_to_access_memory ();
   if (res == 0)
     {
-      if (set_desired_thread (1))
+      if (set_desired_thread ())
        res = read_inferior_memory (memaddr, myaddr, len);
       else
        res = 1;
@@ -996,7 +996,7 @@ gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
       ret = prepare_to_access_memory ();
       if (ret == 0)
        {
-         if (set_desired_thread (1))
+         if (set_desired_thread ())
            ret = write_inferior_memory (memaddr, myaddr, len);
          else
            ret = EIO;
@@ -1508,21 +1508,6 @@ handle_qxfer_features (const char *annex,
   return len;
 }
 
-/* Worker routine for handle_qxfer_libraries.
-   Add to the length pointed to by ARG a conservative estimate of the
-   length needed to transmit the file name of INF.  */
-
-static void
-accumulate_file_name_length (struct inferior_list_entry *inf, void *arg)
-{
-  struct dll_info *dll = (struct dll_info *) inf;
-  unsigned int *total_len = (unsigned int *) arg;
-
-  /* Over-estimate the necessary memory.  Assume that every character
-     in the library name must be escaped.  */
-  *total_len += 128 + 6 * strlen (dll->name);
-}
-
 /* Worker routine for handle_qxfer_libraries.
    Emit the XML to describe the library in INF.  */
 
@@ -1530,24 +1515,12 @@ static void
 emit_dll_description (struct inferior_list_entry *inf, void *arg)
 {
   struct dll_info *dll = (struct dll_info *) inf;
-  char **p_ptr = (char **) arg;
-  char *p = *p_ptr;
-  char *name;
-
-  strcpy (p, "  <library name=\"");
-  p = p + strlen (p);
-  name = xml_escape_text (dll->name);
-  strcpy (p, name);
-  free (name);
-  p = p + strlen (p);
-  strcpy (p, "\"><segment address=\"");
-  p = p + strlen (p);
-  sprintf (p, "0x%lx", (long) dll->base_addr);
-  p = p + strlen (p);
-  strcpy (p, "\"/></library>\n");
-  p = p + strlen (p);
-
-  *p_ptr = p;
+  std::string *document = (std::string *) arg;
+  std::string name = xml_escape_text (dll->name);
+
+  *document += string_printf
+    ("  <library name=\"%s\"><segment address=\"0x%lx\"/></library>\n",
+     name.c_str (), (long) dll->base_addr);
 }
 
 /* Handle qXfer:libraries:read.  */
@@ -1557,43 +1530,26 @@ handle_qxfer_libraries (const char *annex,
                        gdb_byte *readbuf, const gdb_byte *writebuf,
                        ULONGEST offset, LONGEST len)
 {
-  unsigned int total_len;
-  char *document, *p;
-
   if (writebuf != NULL)
     return -2;
 
   if (annex[0] != '\0' || current_thread == NULL)
     return -1;
 
-  total_len = 64;
-  for_each_inferior_with_data (&all_dlls, accumulate_file_name_length,
-                              &total_len);
+  std::string document = "<library-list version=\"1.0\">\n";
 
-  document = (char *) malloc (total_len);
-  if (document == NULL)
-    return -1;
+  for_each_inferior_with_data (&all_dlls, emit_dll_description, &document);
 
-  strcpy (document, "<library-list version=\"1.0\">\n");
-  p = document + strlen (document);
+  document += "</library-list>\n";
 
-  for_each_inferior_with_data (&all_dlls, emit_dll_description, &p);
+  if (offset > document.length ())
+    return -1;
 
-  strcpy (p, "</library-list>\n");
+  if (offset + len > document.length ())
+    len = document.length () - offset;
 
-  total_len = strlen (document);
+  memcpy (readbuf, &document[offset], len);
 
-  if (offset > total_len)
-    {
-      free (document);
-      return -1;
-    }
-
-  if (offset + len > total_len)
-    len = total_len - offset;
-
-  memcpy (readbuf, document + offset, len);
-  free (document);
   return len;
 }
 
@@ -3442,7 +3398,7 @@ handle_status (char *own_buf)
          /* GDB assumes the current thread is the thread we're
             reporting the status for.  */
          general_thread = thread->id;
-         set_desired_thread (1);
+         set_desired_thread ();
 
          gdb_assert (tp->last_status.kind != TARGET_WAITKIND_IGNORE);
          prepare_resume_reply (own_buf, tp->entry.id, &tp->last_status);
@@ -4183,7 +4139,7 @@ process_serial_event (void)
                }
 
              general_thread = thread_id;
-             set_desired_thread (1);
+             set_desired_thread ();
              gdb_assert (current_thread != NULL);
            }
          else if (own_buf[1] == 'c')
@@ -4216,7 +4172,7 @@ process_serial_event (void)
        {
          struct regcache *regcache;
 
-         if (!set_desired_thread (1))
+         if (!set_desired_thread ())
            write_enn (own_buf);
          else
            {
@@ -4233,7 +4189,7 @@ process_serial_event (void)
        {
          struct regcache *regcache;
 
-         if (!set_desired_thread (1))
+         if (!set_desired_thread ())
            write_enn (own_buf);
          else
            {
@@ -4464,7 +4420,7 @@ handle_serial_event (int err, gdb_client_data client_data)
 
   /* Be sure to not change the selected thread behind GDB's back.
      Important in the non-stop mode asynchronous protocol.  */
-  set_desired_thread (1);
+  set_desired_thread ();
 
   return 0;
 }
@@ -4559,7 +4515,7 @@ handle_target_event (int err, gdb_client_data client_data)
 
   /* Be sure to not change the selected thread behind GDB's back.
      Important in the non-stop mode asynchronous protocol.  */
-  set_desired_thread (1);
+  set_desired_thread ();
 
   return 0;
 }
This page took 0.028222 seconds and 4 git commands to generate.