GDB/MI: Document support for -exec-run --start in -list-features
[deliverable/binutils-gdb.git] / gdb / corefile.c
index 1b733e2db056f1c771043b3e46355db8d7d57128..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"
@@ -193,24 +193,20 @@ Use the \"file\" or \"exec-file\" command."));
 }
 \f
 
-/* Report a target xfer memory error by throwing a suitable
-   exception.  */
-
-static void
-target_xfer_memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
+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.  */
-      throw_error (MEMORY_ERROR,
-                  _("Cannot access memory at address %s"),
-                  paddress (target_gdbarch (), memaddr));
+      return xstrprintf (_("Cannot access memory at address %s"),
+                        paddress (gdbarch, memaddr));
     case TARGET_XFER_E_UNAVAILABLE:
-      throw_error (NOT_AVAILABLE_ERROR,
-                  _("Memory at address %s unavailable."),
-                  paddress (target_gdbarch (), memaddr));
+      return xstrprintf (_("Memory at address %s unavailable."),
+                        paddress (gdbarch, memaddr));
     default:
       internal_error (__FILE__, __LINE__,
                      "unhandled target_xfer_error: %s (%s)",
@@ -219,18 +215,30 @@ target_xfer_memory_error (enum target_xfer_error err, CORE_ADDR memaddr)
     }
 }
 
-/* Report a memory error by throwing a MEMORY_ERROR error.  */
+/* 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)
-    target_xfer_memory_error (TARGET_XFER_E_IO, 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.  */
@@ -248,9 +256,9 @@ read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
                                          memaddr + xfered, len - xfered);
 
       if (xfer == 0)
-       target_xfer_memory_error (TARGET_XFER_E_IO, memaddr + xfered);
+       memory_error (TARGET_XFER_E_IO, memaddr + xfered);
       if (xfer < 0)
-       target_xfer_memory_error (xfer, memaddr + xfered);
+       memory_error (xfer, memaddr + xfered);
       xfered += xfer;
       QUIT;
     }
This page took 0.026214 seconds and 4 git commands to generate.