aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-11-13 21:19:11 +0000
committerTom Tromey <tromey@redhat.com>2012-11-13 21:19:11 +0000
commit62747a60cb791459a9431d3f5f49ddec771084b8 (patch)
tree4a3cc5574877f44996b3dfad6ec8629a81a269a1 /gdb/mi
parent4cd29721179a29be4f31798c5860d0964130b78c (diff)
downloadgdb-62747a60cb791459a9431d3f5f49ddec771084b8.zip
gdb-62747a60cb791459a9431d3f5f49ddec771084b8.tar.gz
gdb-62747a60cb791459a9431d3f5f49ddec771084b8.tar.bz2
2012-11-13 Giuseppe Montalto <giuseppe.montalto@st.com>
* mi/mi-main.c (mi_cmd_data_write_memory): Handle additional parameter COUNT, for pattern filling of memory regions. * NEWS: Mention it. doc * gdb.texinfo (GDB/MI Data Manipulation): Document new optional parameter "count" of -data-write-memory-bytes, and add an example. testsuite * gdb.mi/mi-fill-memory.exp: New test.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-main.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9fa1eaa..1b7d68a 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1656,7 +1656,8 @@ mi_cmd_data_write_memory (char *command, char **argv, int argc)
/* Implementation of the -data-write-memory-bytes command.
ADDR: start address
- DATA: string of bytes to write at that address. */
+ DATA: string of bytes to write at that address
+ COUNT: number of bytes to be filled (decimal integer). */
void
mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
@@ -1664,11 +1665,13 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
CORE_ADDR addr;
char *cdata;
gdb_byte *data;
- int len, r, i;
+ gdb_byte *databuf;
+ size_t len, r, i, steps, remainder;
+ long int count, j;
struct cleanup *back_to;
- if (argc != 2)
- error (_("Usage: ADDR DATA."));
+ if (argc != 2 && argc != 3)
+ error (_("Usage: ADDR DATA [COUNT]."));
addr = parse_and_eval_address (argv[0]);
cdata = argv[1];
@@ -1677,18 +1680,45 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
cdata);
len = strlen (cdata)/2;
+ if (argc == 3)
+ count = strtoul (argv[2], NULL, 10);
+ else
+ count = len;
- data = xmalloc (len);
- back_to = make_cleanup (xfree, data);
+ databuf = xmalloc (len * sizeof (gdb_byte));
+ back_to = make_cleanup (xfree, databuf);
for (i = 0; i < len; ++i)
{
int x;
- sscanf (cdata + i * 2, "%02x", &x);
- data[i] = (gdb_byte) x;
+ if (sscanf (cdata + i * 2, "%02x", &x) != 1)
+ error (_("Invalid argument"));
+ databuf[i] = (gdb_byte) x;
+ }
+
+ if (len < count)
+ {
+ /* Pattern is made of less bytes than count:
+ repeat pattern to fill memory. */
+ data = xmalloc (count);
+ make_cleanup (xfree, data);
+
+ steps = count / len;
+ remainder = count % len;
+ for (j = 0; j < steps; j++)
+ memcpy (data + j * len, databuf, len);
+
+ if (remainder > 0)
+ memcpy (data + steps * len, databuf, remainder);
+ }
+ else
+ {
+ /* Pattern is longer than or equal to count:
+ just copy len bytes. */
+ data = databuf;
}
- write_memory_with_notification (addr, data, len);
+ write_memory_with_notification (addr, data, count);
do_cleanups (back_to);
}