From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98856 invoked by alias); 16 Oct 2017 03:04:42 -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 98696 invoked by uid 89); 16 Oct 2017 03:04:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 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=selective, lma, 20867, filtering X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Oct 2017 03:04:39 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy7.mail.unifiedlayer.com (Postfix) with ESMTP id 46B22215D2E for ; Sun, 15 Oct 2017 21:04:38 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id N34b1w00D2f2jeq0134ePJ; Sun, 15 Oct 2017 21:04:38 -0600 X-Authority-Analysis: v=2.2 cv=H76r+6Qi c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=-7PSg6oNF3EwX3GHHS8A:9 a=p7qkh1tKJZ9cZfE9:21 a=66uuFQ7Y6D0VbJyI:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 184-96-33-178.hlrn.qwest.net ([184.96.33.178]:40598 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e3vhj-003iPW-1F; Sun, 15 Oct 2017 21:04:35 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/6] Simple cleanup removals in remote.c Date: Mon, 16 Oct 2017 03:04:00 -0000 Message-Id: <20171016030427.21349-5-tom@tromey.com> In-Reply-To: <20171016030427.21349-1-tom@tromey.com> References: <20171016030427.21349-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e3vhj-003iPW-1F X-Source-Sender: 184-96-33-178.hlrn.qwest.net (bapiya.localdomain) [184.96.33.178]:40598 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-10/txt/msg00405.txt.bz2 This removes a few cleanups in remote.c using the usual techniques: std::vector, unique_xmalloc_ptr, and gdb::def_vector. ChangeLog 2017-10-15 Tom Tromey * remote.c (remote_register_number_and_offset): Use std::vector. (remote_set_syscall_catchpoint): Use gdb::unique_xmalloc_ptr. (putpkt_binary): Use gdb::def_vector. (compare_sections_command): Likewise. --- gdb/ChangeLog | 7 ++++++ gdb/remote.c | 71 +++++++++++++++++++++++------------------------------------ 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index e2bdd115f9..43cc661daf 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -803,21 +803,15 @@ int remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum, int *pnum, int *poffset) { - struct packet_reg *regs; - struct cleanup *old_chain; - gdb_assert (regnum < gdbarch_num_regs (gdbarch)); - regs = XCNEWVEC (struct packet_reg, gdbarch_num_regs (gdbarch)); - old_chain = make_cleanup (xfree, regs); + std::vector regs (gdbarch_num_regs (gdbarch)); - map_regcache_remote_table (gdbarch, regs); + map_regcache_remote_table (gdbarch, regs.data ()); *pnum = regs[regnum].pnum; *poffset = regs[regnum].offset; - do_cleanups (old_chain); - return *pnum != -1; } @@ -2062,7 +2056,7 @@ remote_set_syscall_catchpoint (struct target_ops *self, int pid, int needed, int any_count, int table_size, int *table) { - char *catch_packet; + const char *catch_packet; enum packet_result result; int n_sysno = 0; @@ -2092,6 +2086,7 @@ remote_set_syscall_catchpoint (struct target_ops *self, pid, needed, any_count, n_sysno); } + gdb::unique_xmalloc_ptr built_packet; if (needed) { /* Prepare a packet with the sysno list, assuming max 8+1 @@ -2099,46 +2094,45 @@ remote_set_syscall_catchpoint (struct target_ops *self, big, fallback on the non-selective packet. */ const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + 1; - catch_packet = (char *) xmalloc (maxpktsz); - strcpy (catch_packet, "QCatchSyscalls:1"); + built_packet.reset ((char *) xmalloc (maxpktsz)); + strcpy (built_packet.get (), "QCatchSyscalls:1"); if (!any_count) { int i; char *p; - p = catch_packet; + p = built_packet.get (); p += strlen (p); /* Add in catch_packet each syscall to be caught (table[i] != 0). */ for (i = 0; i < table_size; i++) { if (table[i] != 0) - p += xsnprintf (p, catch_packet + maxpktsz - p, ";%x", i); + p += xsnprintf (p, built_packet.get () + maxpktsz - p, + ";%x", i); } } - if (strlen (catch_packet) > get_remote_packet_size ()) + if (strlen (built_packet.get ()) > get_remote_packet_size ()) { /* catch_packet too big. Fallback to less efficient non selective mode, with GDB doing the filtering. */ - catch_packet[sizeof ("QCatchSyscalls:1") - 1] = 0; + catch_packet = "QCatchSyscalls:1"; } + else + catch_packet = built_packet.get (); } else - catch_packet = xstrdup ("QCatchSyscalls:0"); + catch_packet = "QCatchSyscalls:0"; - { - struct cleanup *old_chain = make_cleanup (xfree, catch_packet); - struct remote_state *rs = get_remote_state (); + struct remote_state *rs = get_remote_state (); - putpkt (catch_packet); - getpkt (&rs->buf, &rs->buf_size, 0); - result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_QCatchSyscalls]); - do_cleanups (old_chain); - if (result == PACKET_OK) - return 0; - else - return -1; - } + putpkt (catch_packet); + getpkt (&rs->buf, &rs->buf_size, 0); + result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_QCatchSyscalls]); + if (result == PACKET_OK) + return 0; + else + return -1; } /* If 'QProgramSignals' is supported, tell the remote stub what @@ -8762,8 +8756,8 @@ putpkt_binary (const char *buf, int cnt) struct remote_state *rs = get_remote_state (); int i; unsigned char csum = 0; - char *buf2 = (char *) xmalloc (cnt + 6); - struct cleanup *old_chain = make_cleanup (xfree, buf2); + gdb::def_vector data (cnt + 6); + char *buf2 = data.data (); int ch; int tcount = 0; @@ -8866,7 +8860,6 @@ putpkt_binary (const char *buf, int cnt) case '+': if (remote_debug) fprintf_unfiltered (gdb_stdlog, "Ack\n"); - do_cleanups (old_chain); return 1; case '-': if (remote_debug) @@ -8875,10 +8868,7 @@ putpkt_binary (const char *buf, int cnt) case SERIAL_TIMEOUT: tcount++; if (tcount > 3) - { - do_cleanups (old_chain); - return 0; - } + return 0; break; /* Retransmit buffer. */ case '$': { @@ -8962,7 +8952,6 @@ putpkt_binary (const char *buf, int cnt) #endif } - do_cleanups (old_chain); return 0; } @@ -10331,7 +10320,6 @@ static void compare_sections_command (const char *args, int from_tty) { asection *s; - struct cleanup *old_chain; gdb_byte *sectdata; const char *sectname; bfd_size_type size; @@ -10372,11 +10360,10 @@ compare_sections_command (const char *args, int from_tty) matched = 1; /* Do this section. */ lma = s->lma; - sectdata = (gdb_byte *) xmalloc (size); - old_chain = make_cleanup (xfree, sectdata); - bfd_get_section_contents (exec_bfd, s, sectdata, 0, size); + gdb::def_vector sectdata (size); + bfd_get_section_contents (exec_bfd, s, sectdata.data (), 0, size); - res = target_verify_memory (sectdata, lma, size); + res = target_verify_memory (sectdata.data (), lma, size); if (res == -1) error (_("target memory fault, section %s, range %s -- %s"), sectname, @@ -10393,8 +10380,6 @@ compare_sections_command (const char *args, int from_tty) printf_filtered ("MIS-MATCHED!\n"); mismatched++; } - - do_cleanups (old_chain); } if (mismatched > 0) warning (_("One or more sections of the target image does not match\n\ -- 2.13.6