GDB/MI: Document support for -exec-run --start in -list-features
[deliverable/binutils-gdb.git] / gdb / corefile.c
index 9c795b855808c873b99026315c4f4024cd15016e..878ab3b3900a073e7150200f657c772adab12ee9 100644 (file)
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_string.h"
+#include <string.h>
 #include <errno.h>
 #include <signal.h>
 #include <fcntl.h>
@@ -30,7 +30,7 @@
 #include "target.h"
 #include "gdbcore.h"
 #include "dis-asm.h"
-#include "gdb_stat.h"
+#include <sys/stat.h>
 #include "completer.h"
 #include "exceptions.h"
 #include "observer.h"
@@ -182,8 +182,8 @@ validate_files (void)
 char *
 get_exec_file (int err)
 {
-  if (exec_bfd)
-    return bfd_get_filename (exec_bfd);
+  if (exec_filename)
+    return exec_filename;
   if (!err)
     return NULL;
 
@@ -193,22 +193,52 @@ Use the \"file\" or \"exec-file\" command."));
 }
 \f
 
-/* Report a memory error by throwing a MEMORY_ERROR error.  */
+char *
+memory_error_message (enum target_xfer_error err,
+                     struct gdbarch *gdbarch, CORE_ADDR memaddr)
+{
+  switch (err)
+    {
+    case TARGET_XFER_E_IO:
+      /* Actually, address between memaddr and memaddr + len was out of
+        bounds.  */
+      return xstrprintf (_("Cannot access memory at address %s"),
+                        paddress (gdbarch, memaddr));
+    case TARGET_XFER_E_UNAVAILABLE:
+      return xstrprintf (_("Memory at address %s unavailable."),
+                        paddress (gdbarch, memaddr));
+    default:
+      internal_error (__FILE__, __LINE__,
+                     "unhandled target_xfer_error: %s (%s)",
+                     target_xfer_error_to_string (err),
+                     plongest (err));
+    }
+}
+
+/* Report a memory error by throwing a suitable exception.  */
 
 void
-memory_error (int status, CORE_ADDR memaddr)
+memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
 {
-  if (status == EIO)
-    /* Actually, address between memaddr and memaddr + len was out of
-       bounds.  */
-    throw_error (MEMORY_ERROR,
-                _("Cannot access memory at address %s"),
-                paddress (target_gdbarch (), memaddr));
-  else
-    throw_error (MEMORY_ERROR,
-                _("Error accessing memory address %s: %s."),
-                paddress (target_gdbarch (), memaddr),
-                safe_strerror (status));
+  char *str;
+
+  /* Build error string.  */
+  str = memory_error_message (err, target_gdbarch (), memaddr);
+  make_cleanup (xfree, str);
+
+  /* Choose the right error to throw.  */
+  switch (err)
+    {
+    case TARGET_XFER_E_IO:
+      err = MEMORY_ERROR;
+      break;
+    case TARGET_XFER_E_UNAVAILABLE:
+      err = NOT_AVAILABLE_ERROR;
+      break;
+    }
+
+  /* Throw it.  */
+  throw_error (err, ("%s"), str);
 }
 
 /* Same as target_read_memory, but report an error if can't read.  */
@@ -216,11 +246,22 @@ memory_error (int status, CORE_ADDR memaddr)
 void
 read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 {
-  int status;
+  LONGEST xfered = 0;
 
-  status = target_read_memory (memaddr, myaddr, len);
-  if (status != 0)
-    memory_error (status, memaddr);
+  while (xfered < len)
+    {
+      LONGEST xfer = target_xfer_partial (current_target.beneath,
+                                         TARGET_OBJECT_MEMORY, NULL,
+                                         myaddr + xfered, NULL,
+                                         memaddr + xfered, len - xfered);
+
+      if (xfer == 0)
+       memory_error (TARGET_XFER_E_IO, memaddr + xfered);
+      if (xfer < 0)
+       memory_error (xfer, memaddr + xfered);
+      xfered += xfer;
+      QUIT;
+    }
 }
 
 /* Same as target_read_stack, but report an error if can't read.  */
@@ -434,7 +475,8 @@ set_gnutarget_command (char *ignore, int from_tty,
 /* A completion function for "set gnutarget".  */
 
 static VEC (char_ptr) *
-complete_set_gnutarget (struct cmd_list_element *cmd, char *text, char *word)
+complete_set_gnutarget (struct cmd_list_element *cmd,
+                       const char *text, const char *word)
 {
   static const char **bfd_targets;
 
This page took 0.025601 seconds and 4 git commands to generate.