From patchwork Wed Jun 26 17:44:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33418 Received: (qmail 3043 invoked by alias); 26 Jun 2019 17:45:03 -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 2955 invoked by uid 89); 26 Jun 2019 17:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=observers, sk:_initia X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Jun 2019 17:45:01 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 39D94116723; Wed, 26 Jun 2019 13:45:00 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id To3Xh1AC-LFf; Wed, 26 Jun 2019 13:45:00 -0400 (EDT) Received: from murgatroyd.Home (75-166-12-78.hlrn.qwest.net [75.166.12.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id D8E89116716; Wed, 26 Jun 2019 13:44:59 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Change arm_objfile_data_key to use type-safe registry Date: Wed, 26 Jun 2019 11:44:58 -0600 Message-Id: <20190626174458.11242-1-tromey@adacore.com> MIME-Version: 1.0 After seeing Simon's patch to change arm_per_objfile to use new and delete, I realized it is now simple to change arm_objfile_data_key to use the type-safe registry. gdb/ChangeLog 2019-06-26 Tom Tromey * arm-tdep.c (arm_objfile_data_key): Move lower. Change type to objfile_key. (arm_find_mapping_symbol, arm_record_special_symbol) (_initialize_arm_tdep): Update. (arm_objfile_data_free): Remove. --- gdb/ChangeLog | 8 ++++++++ gdb/arm-tdep.c | 30 +++++++----------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 039b2f071b2..d2447072106 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -88,9 +88,6 @@ static int arm_debug; #define MSYMBOL_IS_SPECIAL(msym) \ MSYMBOL_TARGET_FLAG_1 (msym) -/* Per-objfile data used for mapping symbols. */ -static const struct objfile_data *arm_objfile_data_key; - struct arm_mapping_symbol { bfd_vma value; @@ -126,6 +123,9 @@ struct arm_per_objfile std::unique_ptr section_maps_sorted; }; +/* Per-objfile data used for mapping symbols. */ +static objfile_key arm_objfile_data_key; + /* The list of available "set arm ..." and "show arm ..." commands. */ static struct cmd_list_element *setarmcmdlist = NULL; static struct cmd_list_element *showarmcmdlist = NULL; @@ -356,9 +356,7 @@ arm_find_mapping_symbol (CORE_ADDR memaddr, CORE_ADDR *start) sec = find_pc_section (memaddr); if (sec != NULL) { - arm_per_objfile *data - = (struct arm_per_objfile *) objfile_data (sec->objfile, - arm_objfile_data_key); + arm_per_objfile *data = arm_objfile_data_key.get (sec->objfile); if (data != NULL) { unsigned int section_idx = sec->the_bfd_section->index; @@ -8528,14 +8526,6 @@ arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym) MSYMBOL_SET_SPECIAL (msym); } -static void -arm_objfile_data_free (struct objfile *objfile, void *arg) -{ - struct arm_per_objfile *data = (struct arm_per_objfile *) arg; - - delete data; -} - static void arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym) @@ -8548,13 +8538,10 @@ arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, if (name[1] != 'a' && name[1] != 't' && name[1] != 'd') return; - data = (struct arm_per_objfile *) objfile_data (objfile, - arm_objfile_data_key); + data = arm_objfile_data_key.get (objfile); if (data == NULL) - { - data = new arm_per_objfile (objfile->obfd->section_count); - set_objfile_data (objfile, arm_objfile_data_key, data); - } + data = arm_objfile_data_key.emplace (objfile, + objfile->obfd->section_count); arm_mapping_symbol_vec &map = data->section_maps[bfd_get_section (sym)->index]; @@ -9477,9 +9464,6 @@ _initialize_arm_tdep (void) gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep); - arm_objfile_data_key - = register_objfile_data_with_cleanup (NULL, arm_objfile_data_free); - /* Add ourselves to objfile event chain. */ gdb::observers::new_objfile.attach (arm_exidx_new_objfile); arm_exidx_data_key