From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22662 invoked by alias); 9 May 2012 16:18:56 -0000 Received: (qmail 22654 invoked by uid 22791); 9 May 2012 16:18:52 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_RG X-Spam-Check-By: sourceware.org Received: from eu1sys200aog102.obsmtp.com (HELO eu1sys200aog102.obsmtp.com) (207.126.144.113) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 May 2012 16:18:38 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob102.postini.com ([207.126.147.11]) with SMTP ID DSNKT6qY3F0ifHZap55Cec/5oG6v0/xgw+2V@postini.com; Wed, 09 May 2012 16:18:37 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8C8F8113 for ; Wed, 9 May 2012 16:18:36 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas4.st.com [10.75.90.69]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 326294519 for ; Wed, 9 May 2012 16:18:36 +0000 (GMT) Received: from SAFEX1MAIL1.st.com ([10.75.90.65]) by Safex1hubcas4.st.com ([10.75.90.69]) with mapi; Wed, 9 May 2012 18:18:23 +0200 From: Giuseppe MONTALTO To: "gdb-patches@sourceware.org" Date: Wed, 09 May 2012 16:18:00 -0000 Subject: [PATCH] new MI command for pattern filling of memory regions Message-ID: <76FE3225DF13124EA2D05B290B624C95E65F2D466E@SAFEX1MAIL1.st.com> x-cr-hashedpuzzle: AKuX ATf/ BFqZ BxgA B3zK B5lv Czoe FzQq Fz4p F93y GLkD GOLF HYaI Hua/ IMZE IUa/;1;ZwBkAGIALQBwAGEAdABjAGgAZQBzAEAAcwBvAHUAcgBjAGUAdwBhAHIAZQAuAG8AcgBnAA==;Sosha1_v1;7;{691FF685-ECFC-46FB-8D4D-2547527BE84E};ZwBpAHUAcwBlAHAAcABlAC4AbQBvAG4AdABhAGwAdABvAEAAcwB0AC4AYwBvAG0A;Wed, 09 May 2012 16:18:27 GMT;WwBQAEEAVABDAEgAXQAgAG4AZQB3ACAATQBJACAAYwBvAG0AbQBhAG4AZAAgAGYAbwByACAAcABhAHQAdABlAHIAbgAgAGYAaQBsAGwAaQBuAGcAIABvAGYAIABtAGUAbQBvAHIAeQAgAHIAZQBnAGkAbwBuAHMA x-cr-puzzleid: {691FF685-ECFC-46FB-8D4D-2547527BE84E} Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg00281.txt.bz2 Hi all, it's the first time I attempt a contribution to gdb, so feel free to ask for details and, please, let me know if I'm doing anything wrong! Short: the proposed enhancement is about memory filling. Rationale: Filling a memory region with a pattern of bytes so far, can only be done by= =20 sending a potentially high number of repeated commands to gdb (depending on= =20 the size of the region that we need to fill). If gdb is controlled through a GUI (e.g. Eclipse/CDT), this may cause the UI to freeze for a quite long time.=20 This is especially true when you're debugging a remote target, due to the amount of generated network traffic. Solution: Implement an MI command that allows filling, with a specific pattern of byt= es, an arbitrarily sized memory region. The proposed patch is here below, also including the related test script. Regards, Giuseppe Montalto =46rom 9a168d60e69ce7618ab74591f230172554e4bc0b Mon Sep 17 00:00:00 2001 From: Giuseppe Montalto Date: Wed, 9 May 2012 16:53:28 +0200 Subject: [PATCH] implemented a new MI command - data-fill-memory-bytes --- gdb/ChangeLog | 8 +++ gdb/mi/mi-cmds.c | 1 + gdb/mi/mi-cmds.h | 1 + gdb/mi/mi-main.c | 73 +++++++++++++++++++++++++++= ++ gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.mi/mi-fill-memory.exp | 76 +++++++++++++++++++++++++++= ++++ 6 files changed, 163 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.mi/mi-fill-memory.exp diff --git gdb/ChangeLog gdb/ChangeLog index 309473e..fe335bb 100644 --- gdb/ChangeLog +++ gdb/ChangeLog @@ -1,3 +1,11 @@ +2012-05-09 Giuseppe Montalto + + * mi/mi-cmds.h (mi_cmd_data_fill_memory_bytes): New Declaration + * mi/mi-cmds.c (data-fill-memory-bytes): New member in struct=20 + mi_cmd mi_cmds + * mi/mi-main.c (mi_cmd_data_fill_memory_bytes): new Function + implementation + 2012-05-09 Pedro Alves =20 * target.c (set_maintenance_target_async_permitted): Rename to ... diff --git gdb/mi/mi-cmds.c gdb/mi/mi-cmds.c index 9152489..020a483 100644 --- gdb/mi/mi-cmds.c +++ gdb/mi/mi-cmds.c @@ -47,6 +47,7 @@ struct mi_cmd mi_cmds[] =3D { "break-watch", { NULL, 0 }, mi_cmd_break_watch}, { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble}, { "data-evaluate-expression", { NULL, 0 }, mi_cmd_data_evaluate_expressi= on}, + { "data-fill-memory-bytes", {NULL, 0}, mi_cmd_data_fill_memory_bytes}, { "data-list-changed-registers", { NULL, 0 }, mi_cmd_data_list_changed_registers}, { "data-list-register-names", { NULL, 0 }, mi_cmd_data_list_register_nam= es}, diff --git gdb/mi/mi-cmds.h gdb/mi/mi-cmds.h index c8465f0..7a8756b 100644 --- gdb/mi/mi-cmds.h +++ gdb/mi/mi-cmds.h @@ -45,6 +45,7 @@ extern mi_cmd_argv_ftype mi_cmd_break_passcount; extern mi_cmd_argv_ftype mi_cmd_break_watch; extern mi_cmd_argv_ftype mi_cmd_disassemble; extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression; +extern mi_cmd_argv_ftype mi_cmd_data_fill_memory_bytes; extern mi_cmd_argv_ftype mi_cmd_data_list_register_names; extern mi_cmd_argv_ftype mi_cmd_data_list_register_values; extern mi_cmd_argv_ftype mi_cmd_data_list_changed_registers; diff --git gdb/mi/mi-main.c gdb/mi/mi-main.c index 90fb624..5d94333 100644 --- gdb/mi/mi-main.c +++ gdb/mi/mi-main.c @@ -1693,6 +1693,79 @@ mi_cmd_data_write_memory_bytes (char *command, char = **argv, int argc) do_cleanups (back_to); } =20 +/* DATA-MEMORY-FILL-RAW: + + ADDR: start address + COUNT: number of bytes to be filled (decimal integer) + DATA: string of bytes to write from that address. (1,2,4 or 8 bytes) */ +void +mi_cmd_data_fill_memory_bytes (char *command, char **argv, int argc) +{ + CORE_ADDR addr; + char *cdata; + gdb_byte *data; + int len, r, i, steps; + long int count, j; + struct cleanup *back_to; + + if (argc !=3D 3) + error (_("Usage: ADDR COUNT DATA.")); + + /* read parameters */ + addr =3D parse_and_eval_address (argv[0]); + /* COUNT is supposed to be a decimal integer*/ + count =3D strtol(argv[1], NULL, 10); + cdata =3D argv[2]; + + /* calculate and allocate a memory buffer for DATA parameter */ + len =3D strlen (cdata); +=20=20 + if ( len !=3D 2 && len !=3D 4 && len !=3D 8 && len !=3D 16 ) + error (_("DATA must be 2, 4, 8 or 16 characters.")); +=20=20 + len =3D len/2; +=20=20 + if ( (long int)len < count ) + { + /* pattern is made of less bytes than count:=20 + repeat pattern to fill memory */ + data =3D xmalloc (count/len); + back_to =3D make_cleanup (xfree, data); +=09 + steps =3D count/len; + for (j =3D 0; j < steps; j++) + { + for (i =3D 0; i < len; ++i) + { + int x; + sscanf (cdata + i * 2, "%02x", &x); + data[i + j * len] =3D (gdb_byte)x; + } + } + } + else + { + /* pattern is longer than (or equal to) count:=20 + just copy len bytes */ + data =3D xmalloc (len); + back_to =3D make_cleanup (xfree, data); +=09 + for (i =3D 0; i < len; ++i) + { + int x; + sscanf (cdata + i * 2, "%02x", &x); + data[i] =3D (gdb_byte)x; + } + } + + r =3D target_write_memory (addr, data, count); + + if (r !=3D 0) + error (_("Could not fill memory range with supplied pattern")); + + do_cleanups (back_to); +} + void mi_cmd_enable_timings (char *command, char **argv, int argc) { diff --git gdb/testsuite/ChangeLog gdb/testsuite/ChangeLog index 43549bf..a49274f 100644 --- gdb/testsuite/ChangeLog +++ gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2012-05-09 Giuseppe Montalto + + * gdb.mi/mi-fill-memory.exp: New test. + 2012-05-08 Maciej W. Rozycki =20 * gdb.mi/mi-var-display.exp: Check for the existence of $fp diff --git gdb/testsuite/gdb.mi/mi-fill-memory.exp gdb/testsuite/gdb.mi/mi-= fill-memory.exp new file mode 100644 index 0000000..40147e5 --- /dev/null +++ gdb/testsuite/gdb.mi/mi-fill-memory.exp @@ -0,0 +1,76 @@ +# 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 . + +# +# 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. +#=20 +# added for testing the -data-fill-memory-bytes MI command +# + +load_lib mi-support.exp +set MIFLAGS "-i=3Dmi" + +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}" executabl= e {debug additional_flags=3D-DFAKEARGV}] !=3D "" } { + 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-fill-memory-bytes" \ + "1\\^error,msg=3D\"Usage: ADDR COUNT DATA\.\""\ + "no arguments" + +mi_gdb_test "2-data-fill-memory-bytes 8" \ + "2\\^error,msg=3D\"Usage: ADDR COUNT DATA\.\""\ + "two arguments missing" + +mi_gdb_test "3-data-fill-memory-bytes 8 ab"\ + "3\\^error,msg=3D\"Usage: ADDR COUNT DATA\.\""\ + "one argument missing" + +mi_gdb_test "4-data-fill-memory-bytes \$pc 8 abc"\ + "4\\^error,msg=3D\"DATA must be 2, 4, 8 or 16 characters\.\""\ + "wrong data length" + +mi_gdb_test "5-data-fill-memory-bytes \$pc 8 ab"\ + "5\\\^done" \ + "memory successfully filled" + +mi_gdb_test "6-interpreter-exec console \"x \$pc\"" \ + ".*0xabababab.*" \ + "pattern correctly read from memory" + +mi_gdb_exit +return 0 --=20 1.7.4.msysgit.0