aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2013-10-09 17:00:00 +0000
committerPedro Alves <palves@redhat.com>2013-10-09 17:00:00 +0000
commit578d3588ee67d9beb22763b0c0ac423fb25b15ec (patch)
tree45240260f046d68fd267d7ff0c61f96efc0d58d1 /gdb/target.c
parent2bc8690cd1c70d86a137d5e2bf6919b8bbc667af (diff)
downloadgdb-578d3588ee67d9beb22763b0c0ac423fb25b15ec.zip
gdb-578d3588ee67d9beb22763b0c0ac423fb25b15ec.tar.gz
gdb-578d3588ee67d9beb22763b0c0ac423fb25b15ec.tar.bz2
Stop using errno values around target_xfer interfaces and memory errors.
target_read_memory & friends build on top of target_read (thus on top of the target_xfer machinery), but turn all errors to EIO, an errno value. I think we'd better convert all these to return a target_xfer_error too, like target_xfer_partial in a previous patch. The patch starts by doing that. (The patch does not add a enum target_xfer_error value for '0'/no error, and likewise does not change the return type of several of these functions to enum target_xfer_error, because different functions return '0' with different semantics.) I audited the tree for memory_error calls, EIO checks, places where GDB hardcodes 'errno = EIO', and also for strerror calls. What I found is that nowadays there's really no need to handle random errno values, other than the EIOs gdb itself hardcodes. No doubt errno values would appear in common code back in the day when target_xfer_memory was the main interface to access memory, but nowadays, any errno value that deprecated interface could return is just absorved by default_xfer_partial: else if (xfered == 0 && errno == 0) /* "deprecated_xfer_memory" uses 0, cross checked against ERRNO as one indication of an error. */ return 0; else return -1; There are two places in the code that check for EIO and print "out of bounds", and defer to strerror for other errors. That's c-lang.c:c_get_string, and valprint.c.:val_print_string. AFAICT, the strerror branch can never be reached nowadays, as the only error possible to get at those points is EIO, given that it's GDB itself that set that errno value (in target_read_memory, etc.). breakpoint.c:insert_bp_location always prints the error val as if an errno, returned by target_insert_breakpoint, with strerr. Now the error here is either always EIO for mem-break.c targets (again hardcoded by the target_read_memory/target_write_memory functions), so this always prints "Input/output error" or similar (depending on host), or, for remote targets (and probably others), this gem: Error accessing memory address 0x80200400: Unknown error -1. This patch makes these 3 places print the exact same error memory_error prints. This changes output, but I think this is better, for making memory error output consistent with other commands, and, it means we have a central place to tweak for memory errors. E.g., this changes: Cannot insert breakpoint 1. Error accessing memory address 0x5fc660: Input/output error. to: Cannot insert breakpoint 1. Cannot access memory at address 0x5fc660 Which I find pretty much acceptable. Surprisingly, only py-prettyprint.exp had a regression, for needing an adjustment. I also grepped the testsuite for the old errors, and found no other hits. Now that errno values aren't used anywhere in any of these memory access related routines, I made memory_error itself take a target_xfer_error instead of an errno. The new target_xfer_memory_error function added recently is no longer necessary, and is thus removed. Tested on x86_64 Fedora 17, native and gdbserver. gdb/ 2013-10-09 Pedro Alves <palves@redhat.com> * breakpoint.c (insert_bp_location): Use memory_error_message to build the memory error string. * c-lang.c: Include "gdbcore.h". (c_get_string): Use memory_error to throw error. (target_xfer_memory_error): Delete. (memory_error_message): New, factored out from target_xfer_memory_error. (memory_error): Change parameter type to target_xfer_error. Rewrite. (read_memory): Use memory_error instead of target_xfer_memory_error. * gdbcore.h: Include "target.h". (memory_error): Change parameter type to target_xfer_error. (memory_error_message): Declare function. * target.c (target_read_memory, target_read_stack) (target_write_memory, target_write_raw_memory): Return TARGET_XFER_E_IO on error. Adjust comments. (get_target_memory): Pass TARGET_XFER_E_IO to memory_error, instead of EIO. * target.h (target_read, target_insert_breakpoint) (target_remove_breakpoint): Adjust comments. * valprint.c (partial_memory_read): Rename parameter, and adjust comment. (val_print_string): Use memory_error_message to build the memory error string. gdb/testsuite/ 2013-10-09 Pedro Alves <palves@redhat.com> * gdb.python/py-prettyprint.exp (run_lang_tests): Adjust expected output.
Diffstat (limited to 'gdb/target.c')
-rw-r--r--gdb/target.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/gdb/target.c b/gdb/target.c
index 559ae0c..7279359 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1787,9 +1787,9 @@ target_xfer_partial (struct target_ops *ops,
return retval;
}
-/* Read LEN bytes of target memory at address MEMADDR, placing the results in
- GDB's memory at MYADDR. Returns either 0 for success or an errno value
- if any error occurs.
+/* Read LEN bytes of target memory at address MEMADDR, placing the
+ results in GDB's memory at MYADDR. Returns either 0 for success or
+ a target_xfer_error value if any error occurs.
If an error occurs, no guarantee is made about the contents of the data at
MYADDR. In particular, the caller should not depend upon partial reads
@@ -1808,7 +1808,7 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Like target_read_memory, but specify explicitly that this is a read from
@@ -1825,13 +1825,14 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
- Returns either 0 for success or an errno value if any error occurs.
- If an error occurs, no guarantee is made about how much data got written.
- Callers that can deal with partial writes should call target_write. */
+ Returns either 0 for success or a target_xfer_error value if any
+ error occurs. If an error occurs, no guarantee is made about how
+ much data got written. Callers that can deal with partial writes
+ should call target_write. */
int
target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
@@ -1843,14 +1844,14 @@ target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Write LEN bytes from MYADDR to target raw memory at address
- MEMADDR. Returns either 0 for success or an errno value if any
- error occurs. If an error occurs, no guarantee is made about how
- much data got written. Callers that can deal with partial writes
- should call target_write. */
+ MEMADDR. Returns either 0 for success or a target_xfer_error value
+ if any error occurs. If an error occurs, no guarantee is made
+ about how much data got written. Callers that can deal with
+ partial writes should call target_write. */
int
target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
@@ -1862,7 +1863,7 @@ target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return EIO;
+ return TARGET_XFER_E_IO;
}
/* Fetch the target's memory map. */
@@ -2440,7 +2441,7 @@ get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
for this target). */
if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len)
!= len)
- memory_error (EIO, addr);
+ memory_error (TARGET_XFER_E_IO, addr);
}
ULONGEST