From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116845 invoked by alias); 12 Sep 2017 18:57:49 -0000 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 Received: (qmail 116740 invoked by uid 89); 12 Sep 2017 18:57:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 18:57:46 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 384E8176144 for ; Tue, 12 Sep 2017 12:57:45 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 8ixi1w0082f2jeq01ixloP; Tue, 12 Sep 2017 12:57:45 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=r2T8TFQGxXpV7jyHHoYA:9 a=vF4w0DvX7DsHEo3N:21 a=ol3R_IfxP0i6Vb7S:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:46142 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1drqNR-001eRR-Tw; Tue, 12 Sep 2017 12:57:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 07/11] Use gdb::byte_vector in mi_cmd_data_write_memory_bytes Date: Tue, 12 Sep 2017 18:57:00 -0000 Message-Id: <20170912185736.20436-8-tom@tromey.com> In-Reply-To: <20170912185736.20436-1-tom@tromey.com> References: <20170912185736.20436-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1drqNR-001eRR-Tw X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:46142 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-09/txt/msg00347.txt.bz2 This changes mi_cmd_data_write_memory_bytes to use gdb::byte_vector, removing some cleanups. ChangeLog 2017-09-12 Tom Tromey * mi/mi-main.c (mi_cmd_data_write_memory_bytes): Use gdb::byte_vector. --- gdb/ChangeLog | 5 +++++ gdb/mi/mi-main.c | 20 +++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 47632fa..7158579 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-09-12 Tom Tromey + * mi/mi-main.c (mi_cmd_data_write_memory_bytes): Use + gdb::byte_vector. + +2017-09-12 Tom Tromey + * thread.c (gdb_list_thread_ids, gdb_thread_select): Change error_message to std::string. * mi/mi-main.c (mi_cmd_thread_select): Use std::string. diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index d01f578..c8c4a97 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1710,11 +1710,8 @@ mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc) { CORE_ADDR addr; char *cdata; - gdb_byte *data; - gdb_byte *databuf; size_t len_hex, len_bytes, len_units, i, steps, remaining_units; long int count_units; - struct cleanup *back_to; int unit_size; if (argc != 2 && argc != 3) @@ -1738,8 +1735,7 @@ mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc) else count_units = len_units; - databuf = XNEWVEC (gdb_byte, len_bytes); - back_to = make_cleanup (xfree, databuf); + gdb::byte_vector databuf (len_bytes); for (i = 0; i < len_bytes; ++i) { @@ -1749,34 +1745,32 @@ mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc) databuf[i] = (gdb_byte) x; } + gdb::byte_vector data; if (len_units < count_units) { /* Pattern is made of less units than count: repeat pattern to fill memory. */ - data = (gdb_byte *) xmalloc (count_units * unit_size); - make_cleanup (xfree, data); + data = gdb::byte_vector (count_units * unit_size); /* Number of times the pattern is entirely repeated. */ steps = count_units / len_units; /* Number of remaining addressable memory units. */ remaining_units = count_units % len_units; for (i = 0; i < steps; i++) - memcpy (data + i * len_bytes, databuf, len_bytes); + memcpy (&data[i * len_bytes], &databuf[0], len_bytes); if (remaining_units > 0) - memcpy (data + steps * len_bytes, databuf, + memcpy (&data[steps * len_bytes], &databuf[0], remaining_units * unit_size); } else { /* Pattern is longer than or equal to count: just copy count addressable memory units. */ - data = databuf; + data = std::move (databuf); } - write_memory_with_notification (addr, data, count_units); - - do_cleanups (back_to); + write_memory_with_notification (addr, data.data (), count_units); } void -- 2.9.4