From patchwork Fri Mar 9 18:33:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26258 Received: (qmail 33401 invoked by alias); 9 Mar 2018 18:34:01 -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 33378 invoked by uid 89); 9 Mar 2018 18:34:00 -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, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.145.221) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 18:33:58 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 600681ABCF15 for ; Fri, 9 Mar 2018 12:33:52 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uMq0edyTmntAouMq0eKaLH; Fri, 09 Mar 2018 12:33:52 -0600 Received: from 174-29-60-18.hlrn.qwest.net ([174.29.60.18]:59052 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1euMq0-000Vr7-57; Fri, 09 Mar 2018 12:33:52 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Use gdb::byte_vector when reading section data Date: Fri, 9 Mar 2018 11:33:49 -0700 Message-Id: <20180309183349.18352-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1euMq0-000Vr7-57 X-Source-Sender: 174-29-60-18.hlrn.qwest.net (bapiya.Home) [174.29.60.18]:59052 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes a couple of spots that read section data to use gdb::byte_vector rather than a cleanup. Regression tested by the buildbot. I am not certain that the buildbot actually tests the code in question, so I recommend careful review. gdb/ChangeLog 2018-03-09 Tom Tromey * rs6000-aix-tdep.c (rs6000_aix_core_xfer_shared_libraries_aix): Use gdb::byte_vector. * arm-tdep.c (arm_exidx_new_objfile): Use gdb::byte_vector. --- gdb/ChangeLog | 6 ++++++ gdb/arm-tdep.c | 39 +++++++++++++++------------------------ gdb/rs6000-aix-tdep.c | 15 ++++----------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index ef7e66b36a..52d3f41cee 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -2040,50 +2040,41 @@ arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma) static void arm_exidx_new_objfile (struct objfile *objfile) { - struct cleanup *cleanups; struct arm_exidx_data *data; asection *exidx, *extab; bfd_vma exidx_vma = 0, extab_vma = 0; bfd_size_type exidx_size = 0, extab_size = 0; - gdb_byte *exidx_data = NULL, *extab_data = NULL; LONGEST i; /* If we've already touched this file, do nothing. */ if (!objfile || objfile_data (objfile, arm_exidx_data_key) != NULL) return; - cleanups = make_cleanup (null_cleanup, NULL); /* Read contents of exception table and index. */ exidx = bfd_get_section_by_name (objfile->obfd, ELF_STRING_ARM_unwind); + gdb::byte_vector exidx_data; if (exidx) { exidx_vma = bfd_section_vma (objfile->obfd, exidx); exidx_size = bfd_get_section_size (exidx); - exidx_data = (gdb_byte *) xmalloc (exidx_size); - make_cleanup (xfree, exidx_data); + exidx_data.resize (exidx_size); if (!bfd_get_section_contents (objfile->obfd, exidx, - exidx_data, 0, exidx_size)) - { - do_cleanups (cleanups); - return; - } + exidx_data.data (), 0, exidx_size)) + return; } extab = bfd_get_section_by_name (objfile->obfd, ".ARM.extab"); + gdb::byte_vector extab_data; if (extab) { extab_vma = bfd_section_vma (objfile->obfd, extab); extab_size = bfd_get_section_size (extab); - extab_data = (gdb_byte *) xmalloc (extab_size); - make_cleanup (xfree, extab_data); + extab_data.resize (extab_size); if (!bfd_get_section_contents (objfile->obfd, extab, - extab_data, 0, extab_size)) - { - do_cleanups (cleanups); - return; - } + extab_data.data (), 0, extab_size)) + return; } /* Allocate exception table data structure. */ @@ -2097,8 +2088,9 @@ arm_exidx_new_objfile (struct objfile *objfile) for (i = 0; i < exidx_size / 8; i++) { struct arm_exidx_entry new_exidx_entry; - bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data + i * 8); - bfd_vma val = bfd_h_get_32 (objfile->obfd, exidx_data + i * 8 + 4); + bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data.data () + i * 8); + bfd_vma val = bfd_h_get_32 (objfile->obfd, + exidx_data.data () + i * 8 + 4); bfd_vma addr = 0, word = 0; int n_bytes = 0, n_words = 0; struct obj_section *sec; @@ -2135,7 +2127,7 @@ arm_exidx_new_objfile (struct objfile *objfile) if (addr >= extab_vma && addr + 4 <= extab_vma + extab_size) { word = bfd_h_get_32 (objfile->obfd, - extab_data + addr - extab_vma); + extab_data.data () + addr - extab_vma); addr += 4; if ((word & 0xff000000) == 0x80000000) @@ -2193,7 +2185,8 @@ arm_exidx_new_objfile (struct objfile *objfile) && addr + 4 <= extab_vma + extab_size) { word = bfd_h_get_32 (objfile->obfd, - extab_data + addr - extab_vma); + (extab_data.data () + + addr - extab_vma)); addr += 4; n_bytes = 3; n_words = ((word >> 24) & 0xff); @@ -2222,7 +2215,7 @@ arm_exidx_new_objfile (struct objfile *objfile) while (n_words--) { word = bfd_h_get_32 (objfile->obfd, - extab_data + addr - extab_vma); + extab_data.data () + addr - extab_vma); addr += 4; *p++ = (gdb_byte) ((word >> 24) & 0xff); @@ -2243,8 +2236,6 @@ arm_exidx_new_objfile (struct objfile *objfile) data->section_maps[sec->the_bfd_section->index], &new_exidx_entry); } - - do_cleanups (cleanups); } /* Search for the exception table entry covering MEMADDR. If one is found, diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index 38c86d4cd8..e3e086c210 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -1007,9 +1007,6 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, { struct bfd_section *ldinfo_sec; int ldinfo_size; - gdb_byte *ldinfo_buf; - struct cleanup *cleanup; - LONGEST result; ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo"); if (ldinfo_sec == NULL) @@ -1017,19 +1014,15 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, bfd_errmsg (bfd_get_error ())); ldinfo_size = bfd_get_section_size (ldinfo_sec); - ldinfo_buf = (gdb_byte *) xmalloc (ldinfo_size); - cleanup = make_cleanup (xfree, ldinfo_buf); + gdb::byte_vector ldinfo_buf (ldinfo_size); if (! bfd_get_section_contents (core_bfd, ldinfo_sec, - ldinfo_buf, 0, ldinfo_size)) + ldinfo_buf.data (), 0, ldinfo_size)) error (_("unable to read .ldinfo section from core file: %s"), bfd_errmsg (bfd_get_error ())); - result = rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf, readbuf, - offset, len, 0); - - do_cleanups (cleanup); - return result; + return rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf.data (), readbuf, + offset, len, 0); } static void