From patchwork Thu Mar 7 20:57:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31774 Received: (qmail 53485 invoked by alias); 7 Mar 2019 20:57: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 53446 invoked by uid 89); 7 Mar 2019 20:57:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 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.1 spammy=ctor, trivially, 2172, 2.17.2 X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.163) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Mar 2019 20:57:14 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway21.websitewelcome.com (Postfix) with ESMTP id BC9D94010A57C for ; Thu, 7 Mar 2019 14:57:12 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 204mh7HegiQer204mhIK9N; Thu, 07 Mar 2019 14:57:12 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lfEOT1Qm/HTBk+jz2h1PPKmrZ70ISgmHKRUP2+MJWF0=; b=PVcQVWLyCE+KImM8TRSJehEJcx pofDx6msvHOoMTzyR5+iDZpILJB2WSioQGRb2qbkUqM3CwG2gzhqoZOtGwjFMTSfiZsmOC5nL55zy RfTwBe88sKYqftAVrxmXKo1p3; Received: from 75-166-85-218.hlrn.qwest.net ([75.166.85.218]:53182 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1h204m-002TOW-Hn; Thu, 07 Mar 2019 14:57:12 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/9] Simplify per-BFD storage management Date: Thu, 7 Mar 2019 13:57:05 -0700 Message-Id: <20190307205709.21919-6-tom@tromey.com> In-Reply-To: <20190307205709.21919-1-tom@tromey.com> References: <20190307205709.21919-1-tom@tromey.com> There's no reason that the objfile_per_bfd_storage must be allocated via bfd_alloc. This patch changes objfile_per_bfd_storage to be managed more simply, via ordinary new and delete; and moves some code into its (new) destructor. While doing this I also noticed an extra initialization of language_of_main, and removed it. gdb/ChangeLog 2019-03-07 Tom Tromey * objfiles.h (struct objfile_per_bfd_storage): Declare destructor. * objfiles.c (objfile_per_bfd_storage::~objfile_per_bfd_storage): New. (get_objfile_bfd_data): Use new. Don't initialize language_of_main. (free_objfile_per_bfd_storage): Remove. (objfile_bfd_data_free, objfile::~objfile): Use delete. --- gdb/ChangeLog | 11 +++++++++++ gdb/objfiles.c | 46 ++++++++++++++-------------------------------- gdb/objfiles.h | 2 ++ 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 2468ca7a3f7..ff8b6fc72cf 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -117,13 +117,17 @@ get_objfile_pspace_data (struct program_space *pspace) static const struct bfd_data *objfiles_bfd_data; +objfile_per_bfd_storage::~objfile_per_bfd_storage () +{ + if (demangled_names_hash) + htab_delete (demangled_names_hash); +} + /* Create the per-BFD storage object for OBJFILE. If ABFD is not NULL, and it already has a per-BFD storage object, use that. - Otherwise, allocate a new per-BFD storage object. If ABFD is not - NULL, the object is allocated on the BFD; otherwise it is allocated - on OBJFILE's obstack. Note that it is not safe to call this - multiple times for a given OBJFILE -- it can only be called when - allocating or re-initializing OBJFILE. */ + Otherwise, allocate a new per-BFD storage object. Note that it is + not safe to call this multiple times for a given OBJFILE -- it can + only be called when allocating or re-initializing OBJFILE. */ static struct objfile_per_bfd_storage * get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) @@ -136,50 +140,28 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) if (storage == NULL) { + storage = new objfile_per_bfd_storage; /* If the object requires gdb to do relocations, we simply fall back to not sharing data across users. These cases are rare enough that this seems reasonable. */ if (abfd != NULL && !gdb_bfd_requires_relocations (abfd)) - { - storage - = ((struct objfile_per_bfd_storage *) - bfd_alloc (abfd, sizeof (struct objfile_per_bfd_storage))); - /* objfile_per_bfd_storage is not trivially constructible, must - call the ctor manually. */ - storage = new (storage) objfile_per_bfd_storage (); - set_bfd_data (abfd, objfiles_bfd_data, storage); - } - else - storage - = obstack_new (&objfile->objfile_obstack); + set_bfd_data (abfd, objfiles_bfd_data, storage); /* Look up the gdbarch associated with the BFD. */ if (abfd != NULL) storage->gdbarch = gdbarch_from_bfd (abfd); - - storage->language_of_main = language_unknown; } return storage; } -/* Free STORAGE. */ - -static void -free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage) -{ - if (storage->demangled_names_hash) - htab_delete (storage->demangled_names_hash); - storage->~objfile_per_bfd_storage (); -} - -/* A wrapper for free_objfile_per_bfd_storage that can be passed as a +/* A deleter for objfile_per_bfd_storage that can be passed as a cleanup function to the BFD registry. */ static void objfile_bfd_data_free (struct bfd *unused, void *d) { - free_objfile_per_bfd_storage ((struct objfile_per_bfd_storage *) d); + delete (struct objfile_per_bfd_storage *) d; } /* See objfiles.h. */ @@ -670,7 +652,7 @@ objfile::~objfile () if (obfd) gdb_bfd_unref (obfd); else - free_objfile_per_bfd_storage (per_bfd); + delete per_bfd; /* Remove it from the chain of all objfiles. */ diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 843c44e1d24..9db212a1d13 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -234,6 +234,8 @@ struct objfile_per_bfd_storage : minsyms_read (false) {} + ~objfile_per_bfd_storage (); + /* The storage has an obstack of its own. */ auto_obstack storage_obstack;