diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2015-06-18 13:12:39 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2015-06-18 13:12:39 -0400 |
commit | 124e13d9e753ef307d6fe478e2cd6dd738de1a0f (patch) | |
tree | 1e3ded1039355e3d4e2e5c3d7df1a591d4b73b6f /gdb/common/rsp-low.c | |
parent | 74bd41ce65c6c2c30ff67519bfc1d00b61826d96 (diff) | |
download | gdb-124e13d9e753ef307d6fe478e2cd6dd738de1a0f.zip gdb-124e13d9e753ef307d6fe478e2cd6dd738de1a0f.tar.gz gdb-124e13d9e753ef307d6fe478e2cd6dd738de1a0f.tar.bz2 |
remote: consider addressable unit size when reading/writing memory
Adapt code in remote.c to take into account addressable unit size when
reading/writing memory.
A few variables are renamed and suffixed with _bytes or _units. This
way, it's more obvious if there is any place where we add or compare
values of different kinds (which would be a mistake).
gdb/ChangeLog:
* common/rsp-low.c (needs_escaping): New.
(remote_escape_output): Add unit_size parameter. Refactor to
support multi-byte addressable units. Rename parameters.
* common/rsp-low.h (remote_escape_output): Add unit_size
parameter and rename others. Update doc.
* remote.c (align_for_efficient_write): New.
(remote_write_bytes_aux): Add unit_size parameter and use it.
Rename some variables. Update doc.
(remote_xfer_partial): Get unit size and use it.
(remote_read_bytes_1): Add unit_size parameter and use it.
Rename some variables. Update doc.
(remote_write_bytes): Same.
(remote_xfer_live_readonly_partial): Same.
(remote_read_bytes): Same.
(remote_flash_write): Update call to remote_write_bytes_aux.
(remote_write_qxfer): Update call to remote_escape_output.
(remote_search_memory): Same.
(remote_hostio_pwrite): Same.
gdb/gdbserver/ChangeLog:
* server.c (write_qxfer_response): Update call to
remote_escape_output.
Diffstat (limited to 'gdb/common/rsp-low.c')
-rw-r--r-- | gdb/common/rsp-low.c | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/gdb/common/rsp-low.c b/gdb/common/rsp-low.c index d3d3d65..178c698 100644 --- a/gdb/common/rsp-low.c +++ b/gdb/common/rsp-low.c @@ -146,38 +146,67 @@ bin2hex (const gdb_byte *bin, char *hex, int count) return i; } +/* Return whether byte B needs escaping when sent as part of binary data. */ + +static int +needs_escaping (gdb_byte b) +{ + return b == '$' || b == '#' || b == '}' || b == '*'; +} + /* See rsp-low.h. */ int -remote_escape_output (const gdb_byte *buffer, int len, - gdb_byte *out_buf, int *out_len, - int out_maxlen) +remote_escape_output (const gdb_byte *buffer, int len_units, int unit_size, + gdb_byte *out_buf, int *out_len_units, + int out_maxlen_bytes) { - int input_index, output_index; - - output_index = 0; - for (input_index = 0; input_index < len; input_index++) + int input_unit_index, output_byte_index = 0, byte_index_in_unit; + int number_escape_bytes_needed; + + /* Try to copy integral addressable memory units until + (1) we run out of space or + (2) we copied all of them. */ + for (input_unit_index = 0; + input_unit_index < len_units; + input_unit_index++) { - gdb_byte b = buffer[input_index]; - - if (b == '$' || b == '#' || b == '}' || b == '*') + /* Find out how many escape bytes we need for this unit. */ + number_escape_bytes_needed = 0; + for (byte_index_in_unit = 0; + byte_index_in_unit < unit_size; + byte_index_in_unit++) { - /* These must be escaped. */ - if (output_index + 2 > out_maxlen) - break; - out_buf[output_index++] = '}'; - out_buf[output_index++] = b ^ 0x20; + int idx = input_unit_index * unit_size + byte_index_in_unit; + gdb_byte b = buffer[idx]; + if (needs_escaping (b)) + number_escape_bytes_needed++; } - else + + /* Check if we have room to fit this escaped unit. */ + if (output_byte_index + unit_size + number_escape_bytes_needed > + out_maxlen_bytes) + break; + + /* Copy the unit byte per byte, adding escapes. */ + for (byte_index_in_unit = 0; + byte_index_in_unit < unit_size; + byte_index_in_unit++) { - if (output_index + 1 > out_maxlen) - break; - out_buf[output_index++] = b; + int idx = input_unit_index * unit_size + byte_index_in_unit; + gdb_byte b = buffer[idx]; + if (needs_escaping (b)) + { + out_buf[output_byte_index++] = '}'; + out_buf[output_byte_index++] = b ^ 0x20; + } + else + out_buf[output_byte_index++] = b; } } - *out_len = input_index; - return output_index; + *out_len_units = input_unit_index; + return output_byte_index; } /* See rsp-low.h. */ |