Use gdb_bfd_sections in dwarf2/read.c
[deliverable/binutils-gdb.git] / gdb / target.c
index 897b8fdd32b85d026839f507d3f93bd6a1bd9d67..9fd6b4ba9e13d0c9f86504cc5d015c6fdf694cf8 100644 (file)
@@ -804,28 +804,24 @@ target_xfer_status_to_string (enum target_xfer_status status)
 };
 
 
-/* target_read_string -- read a null terminated string, up to LEN bytes,
-   from MEMADDR in target.  Set *ERRNOP to the errno code, or 0 if successful.
-   Set *STRING to a pointer to malloc'd memory containing the data; the caller
-   is responsible for freeing it.  Return the number of bytes successfully
-   read.  */
+/* See target.h.  */
 
-int
-target_read_string (CORE_ADDR memaddr, gdb::unique_xmalloc_ptr<char> *string,
-                   int len, int *errnop)
+gdb::unique_xmalloc_ptr<char>
+target_read_string (CORE_ADDR memaddr, int len, int *bytes_read)
 {
-  int bytes_read;
   gdb::unique_xmalloc_ptr<gdb_byte> buffer;
 
+  int ignore;
+  if (bytes_read == nullptr)
+    bytes_read = &ignore;
+
   /* Note that the endian-ness does not matter here.  */
   int errcode = read_string (memaddr, -1, 1, len, BFD_ENDIAN_LITTLE,
-                            &buffer, &bytes_read);
-
-  if (errnop != nullptr)
-    *errnop = errcode;
+                            &buffer, bytes_read);
+  if (errcode != 0)
+    return {};
 
-  string->reset ((char *) buffer.release ());
-  return bytes_read;
+  return gdb::unique_xmalloc_ptr<char> ((char *) buffer.release ());
 }
 
 struct target_section_table *
@@ -929,8 +925,11 @@ raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
       if (res == TARGET_XFER_UNAVAILABLE)
        break;
 
-      /* We want to continue past core files to executables, but not
-        past a running target's memory.  */
+      /* Don't continue past targets which have all the memory.
+         At one time, this code was necessary to read data from
+        executables / shared libraries when data for the requested
+        addresses weren't available in the core file.  But now the
+        core target handles this case itself.  */
       if (ops->has_all_memory ())
        break;
 
@@ -984,11 +983,17 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
          const char *section_name = section->the_bfd_section->name;
 
          memaddr = overlay_mapped_address (memaddr, section);
+
+         auto match_cb = [=] (const struct target_section *s)
+           {
+             return (strcmp (section_name, s->the_bfd_section->name) == 0);
+           };
+
          return section_table_xfer_memory_partial (readbuf, writebuf,
                                                    memaddr, len, xfered_len,
                                                    table->sections,
                                                    table->sections_end,
-                                                   section_name);
+                                                   match_cb);
        }
     }
 
@@ -1006,8 +1011,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
          return section_table_xfer_memory_partial (readbuf, writebuf,
                                                    memaddr, len, xfered_len,
                                                    table->sections,
-                                                   table->sections_end,
-                                                   NULL);
+                                                   table->sections_end);
        }
     }
 
@@ -2003,7 +2007,8 @@ target_disconnect (const char *args, int from_tty)
 /* See target/target.h.  */
 
 ptid_t
-target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
+target_wait (ptid_t ptid, struct target_waitstatus *status,
+            target_wait_flags options)
 {
   return current_top_target ()->wait (ptid, status, options);
 }
@@ -2013,7 +2018,7 @@ target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 ptid_t
 default_target_wait (struct target_ops *ops,
                     ptid_t ptid, struct target_waitstatus *status,
-                    int options)
+                    target_wait_flags options)
 {
   status->kind = TARGET_WAITKIND_IGNORE;
   return minus_one_ptid;
@@ -3112,7 +3117,7 @@ generic_mourn_inferior (void)
 {
   inferior *inf = current_inferior ();
 
-  inferior_ptid = null_ptid;
+  switch_to_no_thread ();
 
   /* Mark breakpoints uninserted in case something tries to delete a
      breakpoint while we delete the inferior's threads (which would
@@ -3278,7 +3283,7 @@ target_pass_ctrlc (void)
       if (proc_target == NULL)
        continue;
 
-      for (thread_info *thr : inf->threads ())
+      for (thread_info *thr : inf->non_exited_threads ())
        {
          /* A thread can be THREAD_STOPPED and executing, while
             running an infcall.  */
@@ -3356,8 +3361,8 @@ str_comma_list_concat_elem (std::string *list, const char *elem)
    OPT is removed from TARGET_OPTIONS.  */
 
 static void
-do_option (int *target_options, std::string *ret,
-          int opt, const char *opt_str)
+do_option (target_wait_flags *target_options, std::string *ret,
+          target_wait_flag opt, const char *opt_str)
 {
   if ((*target_options & opt) != 0)
     {
@@ -3369,7 +3374,7 @@ do_option (int *target_options, std::string *ret,
 /* See target.h.  */
 
 std::string
-target_options_to_string (int target_options)
+target_options_to_string (target_wait_flags target_options)
 {
   std::string ret;
 
This page took 0.028991 seconds and 4 git commands to generate.