From patchwork Tue Sep 27 04:08:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16046 Received: (qmail 84466 invoked by alias); 27 Sep 2016 04:41:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 84272 invoked by uid 89); 27 Sep 2016 04:41:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*r:4.86_1, H*F:U*tom, xfree, 7578 X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 27 Sep 2016 04:40:59 +0000 Received: (qmail 5733 invoked by uid 0); 27 Sep 2016 04:40:57 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy9.mail.unifiedlayer.com with SMTP; 27 Sep 2016 04:40:57 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id oUgu1t00U2f2jeq01Ugx0M; Mon, 26 Sep 2016 22:40:57 -0600 X-Authority-Analysis: v=2.1 cv=aaryw3Yt c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=LL0Lm6XM2RGnvHRdwGMA:9 a=ouJS55duhP5sfJ1i:21 a=trPiF995QbPr8FYG:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:56110 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bojhW-0006Nj-CR; Mon, 26 Sep 2016 22:09:02 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 15/22] Use std::string in macho_symfile_read_all_oso Date: Mon, 26 Sep 2016 22:08:43 -0600 Message-Id: <1474949330-4307-16-git-send-email-tom@tromey.com> In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bojhW-0006Nj-CR X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:56110 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes macho_symfile_read_all_oso to use std::string. This avoids a cleanup. 2016-09-26 Tom Tromey * machoread.c (macho_symfile_read_all_oso): Use std::string. --- gdb/ChangeLog | 4 ++++ gdb/machoread.c | 20 +++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 42101fc..3744387 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2016-09-26 Tom Tromey + * machoread.c (macho_symfile_read_all_oso): Use std::string. + +2016-09-26 Tom Tromey + * cli/cli-dump.c (dump_memory_to_file): Use std::vector. (restore_binary_file): Likewise. diff --git a/gdb/machoread.c b/gdb/machoread.c index df0333a..eefc1bb 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -33,6 +33,7 @@ #include "psympriv.h" #include "complaints.h" #include "gdb_bfd.h" +#include /* If non-zero displays debugging message. */ static unsigned int mach_o_debug_level = 0; @@ -636,7 +637,6 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr, int ix; VEC (oso_el) *vec = *oso_vector_ptr; oso_el *oso; - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); /* Sort oso by name so that files from libraries are gathered. */ qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec), @@ -652,37 +652,33 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr, { bfd *archive_bfd; bfd *member_bfd; - char *archive_name = XNEWVEC (char, pfx_len + 1); int last_ix; oso_el *oso2; int ix2; - memcpy (archive_name, oso->name, pfx_len); - archive_name[pfx_len] = '\0'; - - make_cleanup (xfree, archive_name); + std::string archive_name (oso->name, pfx_len); /* Compute number of oso for this archive. */ for (last_ix = ix; VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++) { - if (strncmp (oso2->name, archive_name, pfx_len) != 0) + if (strncmp (oso2->name, archive_name.c_str (), pfx_len) != 0) break; } /* Open the archive and check the format. */ - archive_bfd = gdb_bfd_open (archive_name, gnutarget, -1); + archive_bfd = gdb_bfd_open (archive_name.c_str (), gnutarget, -1); if (archive_bfd == NULL) { warning (_("Could not open OSO archive file \"%s\""), - archive_name); + archive_name.c_str ()); ix = last_ix; continue; } if (!bfd_check_format (archive_bfd, bfd_archive)) { warning (_("OSO archive file \"%s\" not an archive."), - archive_name); + archive_name.c_str ()); gdb_bfd_unref (archive_bfd); ix = last_ix; continue; @@ -693,7 +689,7 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr, if (member_bfd == NULL) { warning (_("Could not read archive members out of " - "OSO archive \"%s\""), archive_name); + "OSO archive \"%s\""), archive_name.c_str ()); gdb_bfd_unref (archive_bfd); ix = last_ix; continue; @@ -757,8 +753,6 @@ macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr, ix++; } } - - do_cleanups (cleanup); } /* DSYM (debug symbols) files contain the debug info of an executable.