Patchwork [v2,19/31] Convert fbsd-tdep.c to type-safe registry API

login
register
mail settings
Submitter Tom Tromey
Date May 3, 2019, 11:12 p.m.
Message ID <20190503231231.8954-20-tom@tromey.com>
Download mbox | patch
Permalink /patch/32521/
State New
Headers show

Comments

Tom Tromey - May 3, 2019, 11:12 p.m.
This changes fbsd-tdep.c to use the type-safe registry API.

2019-05-01  Tom Tromey  <tom@tromey.com>

	* fbsd-tdep.c (struct fbsd_pspace_data): Add initializers.
	(fbsd_pspace_data_handle): Move lower.  Change type.
	(get_fbsd_pspace_data): Update.
	(fbsd_pspace_data_cleanup): Remove.
	(_initialize_fbsd_tdep): Update.
---
 gdb/ChangeLog   |  8 ++++++++
 gdb/fbsd-tdep.c | 31 +++++++++----------------------
 2 files changed, 17 insertions(+), 22 deletions(-)
John Baldwin - May 6, 2019, 8:56 p.m.
On 5/3/19 4:12 PM, Tom Tromey wrote:
> This changes fbsd-tdep.c to use the type-safe registry API.
> 
> 2019-05-01  Tom Tromey  <tom@tromey.com>
> 
> 	* fbsd-tdep.c (struct fbsd_pspace_data): Add initializers.
> 	(fbsd_pspace_data_handle): Move lower.  Change type.
> 	(get_fbsd_pspace_data): Update.
> 	(fbsd_pspace_data_cleanup): Remove.
> 	(_initialize_fbsd_tdep): Update.

Thanks, this file looks good to me at least.  I'm also still in
favor of the general idea.
Tom Tromey - May 8, 2019, 5:57 p.m.
>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:

John> On 5/3/19 4:12 PM, Tom Tromey wrote:
>> This changes fbsd-tdep.c to use the type-safe registry API.
>> 
>> 2019-05-01  Tom Tromey  <tom@tromey.com>
>> 
>> * fbsd-tdep.c (struct fbsd_pspace_data): Add initializers.
>> (fbsd_pspace_data_handle): Move lower.  Change type.
>> (get_fbsd_pspace_data): Update.
>> (fbsd_pspace_data_cleanup): Remove.
>> (_initialize_fbsd_tdep): Update.

John> Thanks, this file looks good to me at least.  I'm also still in
John> favor of the general idea.

Thanks.  I'll check these in pretty soon, maybe this evening.

Tom
Tom Tromey - May 8, 2019, 10:05 p.m.
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

John> Thanks, this file looks good to me at least.  I'm also still in
John> favor of the general idea.

Tom> Thanks.  I'll check these in pretty soon, maybe this evening.

I'm doing this now.
I may convert some of the remaining ones to the type-safe API.  I'd like
to get rid of it entirely but there are a few required changes I
wouldn't be able to test :-(

Tom

Patch

diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 4efa0f7ae11..cc7c2b7ab2f 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -445,41 +445,30 @@  get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
 	  gdbarch_data (gdbarch, fbsd_gdbarch_data_handle));
 }
 
-/* Per-program-space data for FreeBSD architectures.  */
-static const struct program_space_data *fbsd_pspace_data_handle;
-
 struct fbsd_pspace_data
 {
   /* Offsets in the runtime linker's 'Obj_Entry' structure.  */
-  LONGEST off_linkmap;
-  LONGEST off_tlsindex;
-  bool rtld_offsets_valid;
+  LONGEST off_linkmap = 0;
+  LONGEST off_tlsindex = 0;
+  bool rtld_offsets_valid = false;
 };
 
+/* Per-program-space data for FreeBSD architectures.  */
+static const struct program_space_key<fbsd_pspace_data>
+  fbsd_pspace_data_handle;
+
 static struct fbsd_pspace_data *
 get_fbsd_pspace_data (struct program_space *pspace)
 {
   struct fbsd_pspace_data *data;
 
-  data = ((struct fbsd_pspace_data *)
-	  program_space_data (pspace, fbsd_pspace_data_handle));
+  data = fbsd_pspace_data_handle.get (pspace);
   if (data == NULL)
-    {
-      data = XCNEW (struct fbsd_pspace_data);
-      set_program_space_data (pspace, fbsd_pspace_data_handle, data);
-    }
+    data = fbsd_pspace_data_handle.emplace (pspace);
 
   return data;
 }
 
-/* The cleanup callback for FreeBSD architecture per-program-space data.  */
-
-static void
-fbsd_pspace_data_cleanup (struct program_space *pspace, void *data)
-{
-  xfree (data);
-}
-
 /* This is how we want PTIDs from core files to be printed.  */
 
 static std::string
@@ -2100,6 +2089,4 @@  _initialize_fbsd_tdep (void)
 {
   fbsd_gdbarch_data_handle =
     gdbarch_data_register_post_init (init_fbsd_gdbarch_data);
-  fbsd_pspace_data_handle
-    = register_program_space_data_with_cleanup (NULL, fbsd_pspace_data_cleanup);
 }