- 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 (memaddr));
- else
- throw_error (MEMORY_ERROR,
- _("Error accessing memory address %s: %s."),
- paddress (memaddr),
- safe_strerror (status));
+ enum errors exception = GDB_NO_ERROR;
+
+ /* Build error string. */
+ std::string str = memory_error_message (err, target_gdbarch (), memaddr);
+
+ /* Choose the right error to throw. */
+ switch (err)
+ {
+ case TARGET_XFER_E_IO:
+ exception = MEMORY_ERROR;
+ break;
+ case TARGET_XFER_UNAVAILABLE:
+ exception = NOT_AVAILABLE_ERROR;
+ break;
+ }
+
+ /* Throw it. */
+ throw_error (exception, ("%s"), str.c_str ());
+}
+
+/* Helper function. */
+
+static void
+read_memory_object (enum target_object object, CORE_ADDR memaddr,
+ gdb_byte *myaddr, ssize_t len)
+{
+ ULONGEST xfered = 0;
+
+ while (xfered < len)
+ {
+ enum target_xfer_status status;
+ ULONGEST xfered_len;
+
+ status = target_xfer_partial (current_top_target (), object, NULL,
+ myaddr + xfered, NULL,
+ memaddr + xfered, len - xfered,
+ &xfered_len);
+
+ if (status != TARGET_XFER_OK)
+ memory_error (status == TARGET_XFER_EOF ? TARGET_XFER_E_IO : status,
+ memaddr + xfered);
+
+ xfered += xfered_len;
+ QUIT;
+ }