Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Giuseppe MONTALTO <giuseppe.montalto@st.com>
To: "Abid, Hafiz" <Hafiz_Abid@mentor.com>,
	Tom Tromey <tromey@redhat.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [PATCH] enhancement of mi_cmd_data_write_memory_bytes for filling memory regions (was [PATCH] new MI command for pattern filling of memory regions)
Date: Tue, 12 Jun 2012 14:22:00 -0000	[thread overview]
Message-ID: <76FE3225DF13124EA2D05B290B624C95E6632A4256@SAFEX1MAIL1.st.com> (raw)
In-Reply-To: <EB3B29AD43CA924DA27099BC851923762992F7@EU-MBX-03.mgc.mentorg.com>

New version of the patch.

 gdb/ChangeLog                           |    5 ++
 gdb/mi/mi-main.c                        |   50 +++++++++++++++++----
 gdb/testsuite/ChangeLog                 |    4 ++
 gdb/testsuite/gdb.mi/mi-fill-memory.exp |   72 +++++++++++++++++++++++++++++++
 4 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 309473e..9ec8882 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-09  Giuseppe Montalto  <giuseppe.montalto@st.com>
+
+	* mi/mi-main.c  (mi_cmd_data_write_memory): additional
+	parameter for pattern filling of memory regions
+
 2012-05-09  Pedro Alves  <palves@redhat.com>
 
 	* target.c (set_maintenance_target_async_permitted): Rename to ...
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 90fb624..1e8fca6 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1658,7 +1658,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)
@@ -1666,27 +1667,58 @@ 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;
+  int len, r, i, steps, reminder;
+  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];
-  len = strlen (cdata)/2;
+  len = strlen (cdata) / 2;
+  if (argc == 3)
+    count = strtol (argv[2], NULL, 10);
+  else
+    count = len;
 
-  data = xmalloc (len);
-  back_to = make_cleanup (xfree, data);
+  databuf = xmalloc (len * sizeof (gdb_byte));
 
   for (i = 0; i < len; ++i)
     {
       int x;
       sscanf (cdata + i * 2, "%02x", &x);
-      data[i] = (gdb_byte) x;
+      databuf[i] = (gdb_byte) x;
     }
 
-  r = target_write_memory (addr, data, len);
+  if (len < count)
+    {
+      /* pattern is made of less bytes than count: 
+         repeat pattern to fill memory.  */
+      data = xmalloc (count);
+      back_to = make_cleanup (xfree, data);
+    
+      steps = count / len;
+      reminder = count % len; /* there may be some spare bytes.  */
+      for (j = 0; j < steps; j++)
+        memcpy (data + j * len, databuf, (size_t) len);
+
+      if (reminder > 0) /* copy spare bytes too.  */
+        memcpy (data + steps * len, databuf, (size_t) reminder);
+    }
+  else
+    {
+      /* pattern is longer than (or equal to) count: 
+         just copy len bytes.  */
+      data = xmalloc (len);
+      back_to = make_cleanup (xfree, data);
+      memcpy (data, databuf, (size_t) len);
+    }
+
+  xfree (databuf);
+
+  r = target_write_memory (addr, data, count);
   if (r != 0)
     error (_("Could not write memory"));
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 43549bf..a49274f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2012-05-09  Giuseppe Montalto  <giuseppe.montalto@st.com>
+
+	* gdb.mi/mi-fill-memory.exp: New test.
+
 2012-05-08  Maciej W. Rozycki  <macro@codesourcery.com>
 
 	* gdb.mi/mi-var-display.exp: Check for the existence of $fp
diff --git a/gdb/testsuite/gdb.mi/mi-fill-memory.exp b/gdb/testsuite/gdb.mi/mi-fill-memory.exp
new file mode 100644
index 0000000..b6961b1
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-fill-memory.exp
@@ -0,0 +1,72 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+# Copyright (C) 2012 STMicroelectronics
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#
+# test basic Machine interface (MI) operations
+#
+# Verify that, using the MI, we can load a program and do
+# other basic things that are used by all test files through  mi_gdb_exit,
+# mi_gdb_start, mi_delete_breakpoints, mi_gdb_reinitialize_dir and
+# mi_gdb_load, so we can safely use those.
+#
+# The goal is not to test gdb functionality, which is done by other tests,
+# but the command syntax and correct output response to MI operations.
+# 
+# added for testing the -data-write-memory-bytes MI command enhancements
+#
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+set testfile "mi-read-memory"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
+     untested mi-read-memory.exp
+     return -1
+}
+
+
+mi_run_to_main
+mi_next_to "main" "" "mi-read-memory.c" "20" "next at main"
+
+mi_gdb_test "1-data-write-memory-bytes"\
+	"1\\\^error,msg=\"Usage: ADDR DATA \\\[COUNT\\\]\.\""\
+	"no arguments"
+
+mi_gdb_test "2-data-write-memory-bytes 8"\
+	"2\\\^error,msg=\"Usage: ADDR DATA \\\[COUNT\\\]\.\""\
+	"one argument missing"
+
+mi_gdb_test "3-data-write-memory-bytes \$pc ab"\
+	"3\\\^done" \
+	"memory successfully written"
+
+mi_gdb_test "4-data-write-memory-bytes \$pc ab 8"\
+	"4\\\^done" \
+	"memory successfully filled (8 bytes)"
+
+mi_gdb_test "5-interpreter-exec console \"x \$pc\"" \
+    ".*0xabababab.*" \
+    "pattern correctly read from memory"
+
+mi_gdb_exit
+return 0


  parent reply	other threads:[~2012-06-12 14:22 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09 16:18 [PATCH] new MI command for pattern filling of memory regions Giuseppe MONTALTO
2012-05-09 16:30 ` Tom Tromey
2012-05-09 18:11 ` Tom Tromey
2012-05-10 11:41   ` Giuseppe MONTALTO
2012-05-10 13:57     ` Tom Tromey
2012-05-11  8:53       ` Giuseppe MONTALTO
2012-05-11 14:36         ` Tom Tromey
2012-05-11 16:06           ` Giuseppe MONTALTO
2012-05-25 14:35           ` Giuseppe MONTALTO
2012-06-12  9:07           ` Giuseppe MONTALTO
2012-06-12 10:01             ` Abid, Hafiz
2012-06-12 14:13               ` Giuseppe MONTALTO
2012-06-12 14:22               ` Giuseppe MONTALTO [this message]
2012-09-14 16:30                 ` [PATCH] enhancement of mi_cmd_data_write_memory_bytes for filling memory regions (was [PATCH] new MI command for pattern filling of memory regions) Tom Tromey
2012-09-18 15:19                   ` Giuseppe MONTALTO
2012-09-26 20:44                     ` Tom Tromey
2012-09-27 15:27                       ` Giuseppe MONTALTO
2012-09-28 20:07                         ` Tom Tromey
2012-10-01  9:29                           ` Giuseppe MONTALTO
2012-10-17 20:59                             ` Tom Tromey
2012-10-18 13:40                               ` Giuseppe MONTALTO
2012-10-18 15:41                         ` Pedro Alves
2012-10-18 16:16                           ` Giuseppe MONTALTO
2012-10-18 16:28                             ` [+docs] " Pedro Alves
2012-10-18 17:31                               ` Eli Zaretskii
2012-10-18 17:30                             ` Eli Zaretskii
2012-10-19 14:12                               ` Giuseppe MONTALTO
2012-10-19 16:34                                 ` Eli Zaretskii
2012-10-19 16:56                                 ` Pedro Alves
2012-10-22  7:02                                   ` Giuseppe MONTALTO
2012-11-08 20:37                                     ` Tom Tromey
2012-11-09  8:59                                       ` Giuseppe MONTALTO
2012-11-12 16:52                                         ` Tom Tromey
2012-11-13 10:50                                           ` Giuseppe MONTALTO
2012-11-13 21:19                                             ` Tom Tromey
2012-10-18 16:38                           ` Giuseppe MONTALTO
2012-10-18 19:45                           ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76FE3225DF13124EA2D05B290B624C95E6632A4256@SAFEX1MAIL1.st.com \
    --to=giuseppe.montalto@st.com \
    --cc=Hafiz_Abid@mentor.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox