From patchwork Wed Apr 8 19:56:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 6102 Received: (qmail 56315 invoked by alias); 8 Apr 2015 19:56:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 56256 invoked by uid 89); 8 Apr 2015 19:56:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 08 Apr 2015 19:56:35 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id A3.C8.12456.76135255; Wed, 8 Apr 2015 15:47:20 +0200 (CEST) Received: from elxcz23q12-y4.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.96) with Microsoft SMTP Server (TLS) id 14.3.210.2; Wed, 8 Apr 2015 15:56:25 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 7/7] MI: Consider byte size when reading/writing memory Date: Wed, 8 Apr 2015 15:56:19 -0400 Message-ID: <1428522979-28709-8-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1428522979-28709-1-git-send-email-simon.marchi@ericsson.com> References: <1428522979-28709-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes As a user of the target memory read/write interface, the MI code must adjust its memory allocations to take into account the byte size of the target. gdb/ChangeLog: mi/mi-main.c (mi_cmd_data_read_memory_bytes): Consider byte size. (mi_cmd_data_write_memory_bytes): Same. --- gdb/mi/mi-main.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 2733e80..99caf67 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1595,6 +1595,7 @@ mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc) int ix; VEC(memory_read_result_s) *result; long offset = 0; + int byte_size = gdbarch_memory_byte_size (gdbarch); int oind = 0; char *oarg; enum opt @@ -1650,10 +1651,11 @@ mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc) - addr); ui_out_field_core_addr (uiout, "end", gdbarch, read_result->end); - data = xmalloc ((read_result->end - read_result->begin) * 2 + 1); + data = xmalloc ( + (read_result->end - read_result->begin) * 2 * byte_size + 1); for (i = 0, p = data; - i < (read_result->end - read_result->begin); + i < ((read_result->end - read_result->begin) * byte_size); ++i, p += 2) { sprintf (p, "%02x", read_result->data[i]); @@ -1762,29 +1764,35 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc) char *cdata; gdb_byte *data; gdb_byte *databuf; - size_t len, i, steps, remainder; - long int count, j; + size_t len_chars, len_octets, len_bytes, i, steps, remainder_bytes; + long int count_bytes; struct cleanup *back_to; + int byte_size; if (argc != 2 && argc != 3) error (_("Usage: ADDR DATA [COUNT].")); addr = parse_and_eval_address (argv[0]); cdata = argv[1]; - if (strlen (cdata) % 2) - error (_("Hex-encoded '%s' must have an even number of characters."), + len_chars = strlen (cdata); + byte_size = gdbarch_memory_byte_size (get_current_arch ()); + + if (len_chars % (byte_size * 2) != 0) + error (_("Hex-encoded '%s' must represent an integral number of bytes."), cdata); - len = strlen (cdata)/2; + len_octets = len_chars / 2; + len_bytes = len_octets / byte_size; + if (argc == 3) - count = strtoul (argv[2], NULL, 10); + count_bytes = strtoul (argv[2], NULL, 10); else - count = len; + count_bytes = len_bytes; - databuf = xmalloc (len * sizeof (gdb_byte)); + databuf = xmalloc (len_octets * sizeof (gdb_byte)); back_to = make_cleanup (xfree, databuf); - for (i = 0; i < len; ++i) + for (i = 0; i < len_octets; ++i) { int x; if (sscanf (cdata + i * 2, "%02x", &x) != 1) @@ -1792,20 +1800,23 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc) databuf[i] = (gdb_byte) x; } - if (len < count) + if (len_bytes < count_bytes) { /* Pattern is made of less bytes than count: repeat pattern to fill memory. */ - data = xmalloc (count); + data = xmalloc (count_bytes * byte_size); make_cleanup (xfree, data); - steps = count / len; - remainder = count % len; - for (j = 0; j < steps; j++) - memcpy (data + j * len, databuf, len); + /* Number of times the pattern is entirely repeated. */ + steps = count_bytes / len_bytes; + /* Number of remaining target bytes. */ + remainder_bytes = count_bytes % len_bytes; + for (i = 0; i < steps; i++) + memcpy (data + i * len_octets, databuf, len_octets); - if (remainder > 0) - memcpy (data + steps * len, databuf, remainder); + if (remainder_bytes > 0) + memcpy (data + steps * len_octets, databuf, + remainder_bytes * byte_size); } else { @@ -1814,7 +1825,7 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc) data = databuf; } - write_memory_with_notification (addr, data, count); + write_memory_with_notification (addr, data, count_bytes); do_cleanups (back_to); }