From 62747a60cb791459a9431d3f5f49ddec771084b8 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 13 Nov 2012 21:19:11 +0000 Subject: 2012-11-13 Giuseppe Montalto * 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. --- gdb/mi/mi-main.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'gdb/mi') 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); } -- cgit v1.1