Robustify -data-read-memory

Vladimir Prus vladimir@codesourcery.com
Wed Jun 11 12:07:00 GMT 2008


The -data-read-memory, as presently documented, is allowed to return "N/A" for
memory if could not read. In practice, it tends to fail completely if there's
any error reading memory, and this is not very nice when trying to look at
memory of some embedded system.

-data-read-memory uses target.c:target_read internally and target_read
uses target_read_partial, which uses target_xfer_partial/memory_xfer_partial,
which ends up using to_xfer_partial target method. Both that method,
and the 'm' remote protocol packet are not very clearly specified -- 
they are allowed to return partial data and they can return error, and when
exactly they should return partial data is not clear. As result, I think
we should expect the remote stub, generally, to completely fail a memory
transfer on any error.

This patch adds a fallback on gdb side -- if we try to read memory and fail,
we try again, with half the size. This allows us to read all the data until
the address that cannot be read. To reduce the number of attempts in case
we try to read completely bogus memory, we first try to read a single
byte at the start of the block, and bail out if that fails. 

The net result is that if the stub fails entire read operation on error, this
fallback code will read smaller blocks, until the error address. If the stub
does return partial data on error, we'll do an extra 1-byte read at the error
address, which does not seem like a performance issue.

Note that with this patch, GDB will return error if we have read exactly zero
bytes; I'm not yet sure that's good, and we should not return a bunch of "N/A"
in that case too. However, if we decide we want "N/A", it's a one-line change.

OK?

- Volodya

        * target.c (target_read_until_error): New.
        * target.h (target_read_until_error): Declare.
        * mi/mi-main.c (mi_cmd_data_read_memory): Use
        target_read_until_error.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: data_read_memory.diff
Type: text/x-diff
Size: 3220 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20080611/8dbcf174/attachment.bin>


More information about the Gdb-patches mailing list