From patchwork Wed Jul 10 15:39:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33655 Received: (qmail 124801 invoked by alias); 10 Jul 2019 15:39:53 -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 124694 invoked by uid 89); 10 Jul 2019 15:39:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit 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, 10 Jul 2019 15:39:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B8CDF561DE; Wed, 10 Jul 2019 11:39:50 -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 qnF8hUm2HDrO; Wed, 10 Jul 2019 11:39:50 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (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 64CFB56128; Wed, 10 Jul 2019 11:39:50 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/9] Change jit.c to use type-safe registry Date: Wed, 10 Jul 2019 09:39:41 -0600 Message-Id: <20190710153947.25721-4-tromey@adacore.com> In-Reply-To: <20190710153947.25721-1-tromey@adacore.com> References: <20190710153947.25721-1-tromey@adacore.com> MIME-Version: 1.0 This changes jit.c to use the type-safe registry. Only one of the registry keys in jit.c is converted; the other is trickier and so I've left it be for now. gdb/ChangeLog 2019-07-10 Tom Tromey * jit.c (jit_program_space_key): Change type. Move lower. (get_jit_program_space_data): Update. (jit_program_space_data_cleanup): Remove. (jit_breakpoint_deleted, free_objfile_data, _initialize_jit): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/jit.c | 33 +++++++-------------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/gdb/jit.c b/gdb/jit.c index 62942fc7ab0..fba2482ff13 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -50,8 +50,6 @@ static const char *const jit_break_name = "__jit_debug_register_code"; static const char *const jit_descriptor_name = "__jit_debug_descriptor"; -static const struct program_space_data *jit_program_space_data = NULL; - static void jit_inferior_init (struct gdbarch *gdbarch); static void jit_inferior_exit_hook (struct inferior *inf); @@ -263,6 +261,8 @@ struct jit_program_space_data struct breakpoint *jit_breakpoint; }; +static program_space_key jit_program_space_key; + /* Per-objfile structure recording the addresses in the program space. This object serves two purposes: for ordinary objfiles, it may cache some symbols related to the JIT interface; and for @@ -316,29 +316,16 @@ add_objfile_entry (struct objfile *objfile, CORE_ADDR entry) if not already present. */ static struct jit_program_space_data * -get_jit_program_space_data (void) +get_jit_program_space_data () { struct jit_program_space_data *ps_data; - ps_data - = ((struct jit_program_space_data *) - program_space_data (current_program_space, jit_program_space_data)); + ps_data = jit_program_space_key.get (current_program_space); if (ps_data == NULL) - { - ps_data = XCNEW (struct jit_program_space_data); - set_program_space_data (current_program_space, jit_program_space_data, - ps_data); - } - + ps_data = jit_program_space_key.emplace (current_program_space); return ps_data; } -static void -jit_program_space_data_cleanup (struct program_space *ps, void *arg) -{ - xfree (arg); -} - /* Helper function for reading the global JIT descriptor from remote memory. Returns 1 if all went well, 0 otherwise. */ @@ -1008,8 +995,7 @@ jit_breakpoint_deleted (struct breakpoint *b) { struct jit_program_space_data *ps_data; - ps_data = ((struct jit_program_space_data *) - program_space_data (iter->pspace, jit_program_space_data)); + ps_data = jit_program_space_key.get (iter->pspace); if (ps_data != NULL && ps_data->jit_breakpoint == iter->owner) { ps_data->cached_code_address = 0; @@ -1448,9 +1434,7 @@ free_objfile_data (struct objfile *objfile, void *data) { struct jit_program_space_data *ps_data; - ps_data - = ((struct jit_program_space_data *) - program_space_data (objfile->pspace, jit_program_space_data)); + ps_data = jit_program_space_key.get (objfile->pspace); if (ps_data != NULL && ps_data->objfile == objfile) { ps_data->objfile = NULL; @@ -1496,9 +1480,6 @@ _initialize_jit (void) jit_objfile_data = register_objfile_data_with_cleanup (NULL, free_objfile_data); - jit_program_space_data = - register_program_space_data_with_cleanup (NULL, - jit_program_space_data_cleanup); jit_gdbarch_data = gdbarch_data_register_pre_init (jit_gdbarch_data_init); if (is_dl_available ()) {