[3/9] Change jit.c to use type-safe registry

Message ID 20190710153947.25721-4-tromey@adacore.com
State New
Headers show
Series
  • Use the type-safe registry in more cases
Related show

Commit Message

Tom Tromey July 10, 2019, 3:39 p.m.
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  <tromey@adacore.com>

	* 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(-)

-- 
2.20.1

Comments

Simon Marchi July 10, 2019, 5:02 p.m. | #1
> 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_data> 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;

>  }


Do the fields of jit_program_space_data need to be initialized?  The previous code used
XCNEW, initializing them to 0.

Simon
Tom Tromey July 10, 2019, 6:44 p.m. | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:


Simon> Do the fields of jit_program_space_data need to be initialized?
Simon> The previous code used XCNEW, initializing them to 0.

Yep.  I've fixed this.  Thank you.

Tom

Patch

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_data> 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 ())
     {