* auto-load.c (_initialize_auto_load): Update.
authorTom Tromey <tromey@redhat.com>
Wed, 22 Aug 2012 15:17:21 +0000 (15:17 +0000)
committerTom Tromey <tromey@redhat.com>
Wed, 22 Aug 2012 15:17:21 +0000 (15:17 +0000)
* solib-svr4.c (_initialize_svr4_solib): Update
* solib-dsbt.c (_initialize_dsbt_solib): Update.
* solib-darwin.c (_initialize_darwin_solib): Update.
* registry.h: New file.
* python/py-progspace.c (gdbpy_initialize_pspace): Update.
* python/py-inferior.c (gdbpy_initialize_inferior): Update.
* progspace.h: Include registry.h.  Use DECLARE_REGISTRY.
(register_program_space_data_with_cleanup)
(register_program_space_data, program_space_alloc_data)
(clear_program_space_data, set_program_space_data)
(program_space_data): Don't declare.
* progspace.c: Use DEFINE_REGISTRY.
(struct program_space_data, struct
program_space_data_registration, struct
program_space_data_registry, program_space_data_registry)
(register_program_space_data_with_cleanup)
(register_program_space_data, program_space_alloc_data)
(program_space_free_data, clear_program_space_data)
(set_program_space_data, program_space_data): Remove.
* objfiles.h: Include registry.h.  Use DECLARE_REGISTRY.
(struct objfile) <data, num_data>: Replace with REGISTRY_FIELDS.
(register_objfile_data_with_cleanup, register_objfile_data)
(clear_objfile_data, set_objfile_data, objfile_data): Don't
declare.
* objfiles.c: Use DEFINE_REGISTRY.
(struct objfile_data, struct objfile_data_registration, struct
objfile_data_registry, objfile_data_registry)
(register_objfile_data_with_cleanup, register_objfile_data)
(objfile_alloc_data, objfile_free_data, clear_objfile_data)
(set_objfile_data, objfile_data): Remove.
(_initialize_objfiles): Update.
* jit.c (_initialize_jit): Update.
* inflow.c (_initialize_inflow): Update.
* inferior.h: Include registry.h.  Use DECLARE_REGISTRY.
(struct inferior) <data, num_data>: Replace with REGISTRY_FIELDS.
(register_inferior_data_with_cleanup, register_inferior_data)
(clear_inferior_data, set_inferior_data, inferior_data): Don't
declare.
* inferior.c: Use DEFINE_REGISTRY.
(struct inferior_data, struct inferior_data_registration, struct
inferior_data_registry, inferior_data_registry)
(register_inferior_data_with_cleanup, register_inferior_data)
(inferior_alloc_data, inferior_free_data  clear_inferior_data)
(set_inferior_data, inferior_data): Remove.
* auxv.c (_initialize_auxv): Update.
* ada-lang.c (_initialize_ada_language): Update.
* breakpoint.c (_initialize_breakpoint): Update.
* i386-nat.c (i386_use_watchpoints): Update.

20 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/auto-load.c
gdb/auxv.c
gdb/breakpoint.c
gdb/i386-nat.c
gdb/inferior.c
gdb/inferior.h
gdb/inflow.c
gdb/jit.c
gdb/objfiles.c
gdb/objfiles.h
gdb/progspace.c
gdb/progspace.h
gdb/python/py-inferior.c
gdb/python/py-progspace.c
gdb/registry.h [new file with mode: 0644]
gdb/solib-darwin.c
gdb/solib-dsbt.c
gdb/solib-svr4.c

index 964b6fdc7398224278fd1de62ba3c1333d70ba50..385e3125df1b7da014e02c79b24491d7f893aadb 100644 (file)
@@ -1,3 +1,55 @@
+2012-08-22  Tom Tromey  <tromey@redhat.com>
+
+       * auto-load.c (_initialize_auto_load): Update.
+       * solib-svr4.c (_initialize_svr4_solib): Update
+       * solib-dsbt.c (_initialize_dsbt_solib): Update.
+       * solib-darwin.c (_initialize_darwin_solib): Update.
+       * registry.h: New file.
+       * python/py-progspace.c (gdbpy_initialize_pspace): Update.
+       * python/py-inferior.c (gdbpy_initialize_inferior): Update.
+       * progspace.h: Include registry.h.  Use DECLARE_REGISTRY.
+       (register_program_space_data_with_cleanup)
+       (register_program_space_data, program_space_alloc_data)
+       (clear_program_space_data, set_program_space_data)
+       (program_space_data): Don't declare.
+       * progspace.c: Use DEFINE_REGISTRY.
+       (struct program_space_data, struct
+       program_space_data_registration, struct
+       program_space_data_registry, program_space_data_registry)
+       (register_program_space_data_with_cleanup)
+       (register_program_space_data, program_space_alloc_data)
+       (program_space_free_data, clear_program_space_data)
+       (set_program_space_data, program_space_data): Remove.
+       * objfiles.h: Include registry.h.  Use DECLARE_REGISTRY.
+       (struct objfile) <data, num_data>: Replace with REGISTRY_FIELDS.
+       (register_objfile_data_with_cleanup, register_objfile_data)
+       (clear_objfile_data, set_objfile_data, objfile_data): Don't
+       declare.
+       * objfiles.c: Use DEFINE_REGISTRY.
+       (struct objfile_data, struct objfile_data_registration, struct
+       objfile_data_registry, objfile_data_registry)
+       (register_objfile_data_with_cleanup, register_objfile_data)
+       (objfile_alloc_data, objfile_free_data, clear_objfile_data)
+       (set_objfile_data, objfile_data): Remove.
+       (_initialize_objfiles): Update.
+       * jit.c (_initialize_jit): Update.
+       * inflow.c (_initialize_inflow): Update.
+       * inferior.h: Include registry.h.  Use DECLARE_REGISTRY.
+       (struct inferior) <data, num_data>: Replace with REGISTRY_FIELDS.
+       (register_inferior_data_with_cleanup, register_inferior_data)
+       (clear_inferior_data, set_inferior_data, inferior_data): Don't
+       declare.
+       * inferior.c: Use DEFINE_REGISTRY.
+       (struct inferior_data, struct inferior_data_registration, struct
+       inferior_data_registry, inferior_data_registry)
+       (register_inferior_data_with_cleanup, register_inferior_data)
+       (inferior_alloc_data, inferior_free_data  clear_inferior_data)
+       (set_inferior_data, inferior_data): Remove.
+       * auxv.c (_initialize_auxv): Update.
+       * ada-lang.c (_initialize_ada_language): Update.
+       * breakpoint.c (_initialize_breakpoint): Update.
+       * i386-nat.c (i386_use_watchpoints): Update.
+
 2012-08-22  Tom Tromey  <tromey@redhat.com>
 
        * exec.c (exec_close, exec_file_attach): Update.
index 38bc6372fc25599202df09ac6f162f2940039f63..bba045b4ba35c2ec6ab28918c388a1a3fbcb49bf 100644 (file)
@@ -12657,5 +12657,5 @@ With an argument, catch only exceptions with the given name."),
   /* Setup per-inferior data.  */
   observer_attach_inferior_exit (ada_inferior_exit);
   ada_inferior_data
-    = register_inferior_data_with_cleanup (ada_inferior_data_cleanup);
+    = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
 }
index 03a753945830acab8a5e3f5377bb99a2405dc9fe..29711832b6b971733498f715658e88f1fdbf35c0 100644 (file)
@@ -1130,7 +1130,8 @@ _initialize_auto_load (void)
   struct cmd_list_element *cmd;
 
   auto_load_pspace_data
-    = register_program_space_data_with_cleanup (auto_load_pspace_data_cleanup);
+    = register_program_space_data_with_cleanup (NULL,
+                                               auto_load_pspace_data_cleanup);
 
   observer_attach_new_objfile (auto_load_new_objfile);
 
index 12dcb8929d0e02730db41acc08a365af988cb71e..62628c60f83ade3eeb2d0667a9b256c349d17169 100644 (file)
@@ -530,7 +530,7 @@ This is information provided by the operating system at program startup."));
 
   /* Set an auxv cache per-inferior.  */
   auxv_inferior_data
-    = register_inferior_data_with_cleanup (auxv_inferior_data_cleanup);
+    = register_inferior_data_with_cleanup (NULL, auxv_inferior_data_cleanup);
 
   /* Observers used to invalidate the auxv cache when needed.  */
   observer_attach_inferior_exit (invalidate_auxv_cache_inf);
index c693d420d5de6d27ff8aa4e7a0f0dccbf056cf1e..b2a00be020b1c9ad1d1bed9e77322f958ab7b9ae 100644 (file)
@@ -15876,7 +15876,8 @@ _initialize_breakpoint (void)
     = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
 
   catch_syscall_inferior_data
-    = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
+    = register_inferior_data_with_cleanup (NULL,
+                                          catch_syscall_inferior_data_cleanup);
 
   breakpoint_chain = 0;
   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
index 753de67d04d9ec213f1c8951e7d0b81a3790c3e8..e7d9b4d69bd031ecfea231c0e67e7dff5d901564 100644 (file)
@@ -873,7 +873,7 @@ i386_use_watchpoints (struct target_ops *t)
 
   if (i386_inferior_data == NULL)
     i386_inferior_data
-      = register_inferior_data_with_cleanup (i386_inferior_data_cleanup);
+      = register_inferior_data_with_cleanup (NULL, i386_inferior_data_cleanup);
 }
 
 void
index 805acb4e92f19bcc09197c1aeb0307a26795d18b..c812d3980ffe556e83c3dfb77f23fb981447aa2a 100644 (file)
 
 void _initialize_inferiors (void);
 
-static void inferior_alloc_data (struct inferior *inf);
-static void inferior_free_data (struct inferior *inf);
+/* Keep a registry of per-inferior data-pointers required by other GDB
+   modules.  */
+
+DEFINE_REGISTRY (inferior)
 
 struct inferior *inferior_list = NULL;
 static int highest_inferior_num;
@@ -955,105 +957,6 @@ show_print_inferior_events (struct ui_file *file, int from_tty,
 
 \f
 
-/* Keep a registry of per-inferior data-pointers required by other GDB
-   modules.  */
-
-struct inferior_data
-{
-  unsigned index;
-  void (*cleanup) (struct inferior *, void *);
-};
-
-struct inferior_data_registration
-{
-  struct inferior_data *data;
-  struct inferior_data_registration *next;
-};
-
-struct inferior_data_registry
-{
-  struct inferior_data_registration *registrations;
-  unsigned num_registrations;
-};
-
-static struct inferior_data_registry inferior_data_registry
-  = { NULL, 0 };
-
-const struct inferior_data *
-register_inferior_data_with_cleanup
-  (void (*cleanup) (struct inferior *, void *))
-{
-  struct inferior_data_registration **curr;
-
-  /* Append new registration.  */
-  for (curr = &inferior_data_registry.registrations;
-       *curr != NULL; curr = &(*curr)->next);
-
-  *curr = XMALLOC (struct inferior_data_registration);
-  (*curr)->next = NULL;
-  (*curr)->data = XMALLOC (struct inferior_data);
-  (*curr)->data->index = inferior_data_registry.num_registrations++;
-  (*curr)->data->cleanup = cleanup;
-
-  return (*curr)->data;
-}
-
-const struct inferior_data *
-register_inferior_data (void)
-{
-  return register_inferior_data_with_cleanup (NULL);
-}
-
-static void
-inferior_alloc_data (struct inferior *inf)
-{
-  gdb_assert (inf->data == NULL);
-  inf->num_data = inferior_data_registry.num_registrations;
-  inf->data = XCALLOC (inf->num_data, void *);
-}
-
-static void
-inferior_free_data (struct inferior *inf)
-{
-  gdb_assert (inf->data != NULL);
-  clear_inferior_data (inf);
-  xfree (inf->data);
-  inf->data = NULL;
-}
-
-void
-clear_inferior_data (struct inferior *inf)
-{
-  struct inferior_data_registration *registration;
-  int i;
-
-  gdb_assert (inf->data != NULL);
-
-  for (registration = inferior_data_registry.registrations, i = 0;
-       i < inf->num_data;
-       registration = registration->next, i++)
-    if (inf->data[i] != NULL && registration->data->cleanup)
-      registration->data->cleanup (inf, inf->data[i]);
-
-  memset (inf->data, 0, inf->num_data * sizeof (void *));
-}
-
-void
-set_inferior_data (struct inferior *inf,
-                      const struct inferior_data *data,
-                      void *value)
-{
-  gdb_assert (data->index < inf->num_data);
-  inf->data[data->index] = value;
-}
-
-void *
-inferior_data (struct inferior *inf, const struct inferior_data *data)
-{
-  gdb_assert (data->index < inf->num_data);
-  return inf->data[data->index];
-}
-
 void
 initialize_inferiors (void)
 {
index 86402f155e2842970f21acdd92198aa9a5bb41d2..b2607c39f502d396a033a0ec19f4c803aa71f666 100644 (file)
@@ -43,6 +43,7 @@ struct terminal_info;
 #include "frame.h"
 
 #include "progspace.h"
+#include "registry.h"
 
 struct infcall_suspend_state;
 struct infcall_control_state;
@@ -513,21 +514,13 @@ struct inferior
   int symfile_flags;
 
   /* Per inferior data-pointers required by other GDB modules.  */
-  void **data;
-  unsigned num_data;
+  REGISTRY_FIELDS;
 };
 
 /* Keep a registry of per-inferior data-pointers required by other GDB
    modules.  */
 
-extern const struct inferior_data *register_inferior_data (void);
-extern const struct inferior_data *register_inferior_data_with_cleanup
-  (void (*cleanup) (struct inferior *, void *));
-extern void clear_inferior_data (struct inferior *inf);
-extern void set_inferior_data (struct inferior *inf,
-                              const struct inferior_data *data, void *value);
-extern void *inferior_data (struct inferior *inf,
-                           const struct inferior_data *data);
+DECLARE_REGISTRY (inferior);
 
 /* Create an empty inferior list, or empty the existing one.  */
 extern void init_inferior_list (void);
index 711b2aa626d1033a9d3ae1fa6fad5ebb8893b57c..de6ee56918eeaacd5e9a8b3b7efdb989f8b2d264 100644 (file)
@@ -925,5 +925,5 @@ input settings."),
   observer_attach_inferior_exit (inflow_inferior_exit);
 
   inflow_inferior_data
-    = register_inferior_data_with_cleanup (inflow_inferior_data_cleanup);
+    = register_inferior_data_with_cleanup (NULL, inflow_inferior_data_cleanup);
 }
index 2ba6d7ef6038b8972d2da49b2dc055deafcc30cb..26de18960166c2ef1960d3ce6dd4029ac3b588cd 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1414,7 +1414,7 @@ _initialize_jit (void)
   jit_objfile_data =
     register_objfile_data_with_cleanup (NULL, free_objfile_data);
   jit_inferior_data =
-    register_inferior_data_with_cleanup (jit_inferior_data_cleanup);
+    register_inferior_data_with_cleanup (NULL, jit_inferior_data_cleanup);
   jit_gdbarch_data = gdbarch_data_register_pre_init (jit_gdbarch_data_init);
   if (is_dl_available ())
     {
index 411618f90855814ed75de3f6a4dfd40cfd11b476..b33a0cf449928fcf14bead8f22552d12694d2385 100644 (file)
 #include "solist.h"
 #include "gdb_bfd.h"
 
-/* Prototypes for local functions */
+/* Keep a registry of per-objfile data-pointers required by other GDB
+   modules.  */
 
-static void objfile_alloc_data (struct objfile *objfile);
-static void objfile_free_data (struct objfile *objfile);
+DEFINE_REGISTRY (objfile)
 
 /* Externally visible variables that are owned by this module.
    See declarations in objfile.h for more info.  */
@@ -1339,115 +1339,6 @@ in_plt_section (CORE_ADDR pc, char *name)
 }
 \f
 
-/* Keep a registry of per-objfile data-pointers required by other GDB
-   modules.  */
-
-struct objfile_data
-{
-  unsigned index;
-  void (*save) (struct objfile *, void *);
-  void (*free) (struct objfile *, void *);
-};
-
-struct objfile_data_registration
-{
-  struct objfile_data *data;
-  struct objfile_data_registration *next;
-};
-  
-struct objfile_data_registry
-{
-  struct objfile_data_registration *registrations;
-  unsigned num_registrations;
-};
-
-static struct objfile_data_registry objfile_data_registry = { NULL, 0 };
-
-const struct objfile_data *
-register_objfile_data_with_cleanup (void (*save) (struct objfile *, void *),
-                                   void (*free) (struct objfile *, void *))
-{
-  struct objfile_data_registration **curr;
-
-  /* Append new registration.  */
-  for (curr = &objfile_data_registry.registrations;
-       *curr != NULL; curr = &(*curr)->next);
-
-  *curr = XMALLOC (struct objfile_data_registration);
-  (*curr)->next = NULL;
-  (*curr)->data = XMALLOC (struct objfile_data);
-  (*curr)->data->index = objfile_data_registry.num_registrations++;
-  (*curr)->data->save = save;
-  (*curr)->data->free = free;
-
-  return (*curr)->data;
-}
-
-const struct objfile_data *
-register_objfile_data (void)
-{
-  return register_objfile_data_with_cleanup (NULL, NULL);
-}
-
-static void
-objfile_alloc_data (struct objfile *objfile)
-{
-  gdb_assert (objfile->data == NULL);
-  objfile->num_data = objfile_data_registry.num_registrations;
-  objfile->data = XCALLOC (objfile->num_data, void *);
-}
-
-static void
-objfile_free_data (struct objfile *objfile)
-{
-  gdb_assert (objfile->data != NULL);
-  clear_objfile_data (objfile);
-  xfree (objfile->data);
-  objfile->data = NULL;
-}
-
-void
-clear_objfile_data (struct objfile *objfile)
-{
-  struct objfile_data_registration *registration;
-  int i;
-
-  gdb_assert (objfile->data != NULL);
-
-  /* Process all the save handlers.  */
-
-  for (registration = objfile_data_registry.registrations, i = 0;
-       i < objfile->num_data;
-       registration = registration->next, i++)
-    if (objfile->data[i] != NULL && registration->data->save != NULL)
-      registration->data->save (objfile, objfile->data[i]);
-
-  /* Now process all the free handlers.  */
-
-  for (registration = objfile_data_registry.registrations, i = 0;
-       i < objfile->num_data;
-       registration = registration->next, i++)
-    if (objfile->data[i] != NULL && registration->data->free != NULL)
-      registration->data->free (objfile, objfile->data[i]);
-
-  memset (objfile->data, 0, objfile->num_data * sizeof (void *));
-}
-
-void
-set_objfile_data (struct objfile *objfile, const struct objfile_data *data,
-                 void *value)
-{
-  gdb_assert (data->index < objfile->num_data);
-  objfile->data[data->index] = value;
-}
-
-void *
-objfile_data (struct objfile *objfile, const struct objfile_data *data)
-{
-  gdb_assert (data->index < objfile->num_data);
-  return objfile->data[data->index];
-}
-
 /* Set objfiles_changed_p so section map will be rebuilt next time it
    is used.  Called by reread_symbols.  */
 
@@ -1490,5 +1381,6 @@ void
 _initialize_objfiles (void)
 {
   objfiles_pspace_data
-    = register_program_space_data_with_cleanup (objfiles_pspace_data_cleanup);
+    = register_program_space_data_with_cleanup (NULL,
+                                               objfiles_pspace_data_cleanup);
 }
index 0df57988646f93f52b38c0a026af799c33c0e1c2..097f4dbbd59d09ad8b3f427bbdf554be737afdef 100644 (file)
@@ -23,6 +23,7 @@
 #include "gdb_obstack.h"       /* For obstack internals.  */
 #include "symfile.h"           /* For struct psymbol_allocation_list.  */
 #include "progspace.h"
+#include "registry.h"
 
 struct bcache;
 struct htab;
@@ -323,8 +324,7 @@ struct objfile
        deprecated_sym_stab_info and deprecated_sym_private
        entirely.  */
 
-    void **data;
-    unsigned num_data;
+    REGISTRY_FIELDS;
 
     /* Set of relocation offsets to apply to each section.
        The table is indexed by the_bfd_section->index, thus it is generally
@@ -503,24 +503,7 @@ extern int in_plt_section (CORE_ADDR, char *);
 
 /* Keep a registry of per-objfile data-pointers required by other GDB
    modules.  */
-
-/* Allocate an entry in the per-objfile registry.  */
-extern const struct objfile_data *register_objfile_data (void);
-
-/* Allocate an entry in the per-objfile registry.
-   SAVE and FREE are called when clearing objfile data.
-   First all registered SAVE functions are called.
-   Then all registered FREE functions are called.
-   Either or both of SAVE, FREE may be NULL.  */
-extern const struct objfile_data *register_objfile_data_with_cleanup
-  (void (*save) (struct objfile *, void *),
-   void (*free) (struct objfile *, void *));
-
-extern void clear_objfile_data (struct objfile *objfile);
-extern void set_objfile_data (struct objfile *objfile,
-                             const struct objfile_data *data, void *value);
-extern void *objfile_data (struct objfile *objfile,
-                          const struct objfile_data *data);
+DECLARE_REGISTRY(objfile);
 
 extern void default_iterate_over_objfiles_in_search_order
   (struct gdbarch *gdbarch,
index 1065c277b9207c09b897a80f40fa6a5713e8b348..6498738909af9e97564373761b655d91b698fb4f 100644 (file)
@@ -37,10 +37,13 @@ struct program_space *current_program_space;
 /* The last address space number assigned.  */
 static int highest_address_space_num;
 
-/* Prototypes for local functions */
+\f
+
+/* Keep a registry of per-program_space data-pointers required by other GDB
+   modules.  */
+
+DEFINE_REGISTRY (program_space)
 
-static void program_space_alloc_data (struct program_space *);
-static void program_space_free_data (struct program_space *);
 \f
 
 /* An address space.  Currently this is not used for much other than
@@ -517,108 +520,6 @@ clear_program_space_solib_cache (struct program_space *pspace)
 
 \f
 
-/* Keep a registry of per-program_space data-pointers required by other GDB
-   modules.  */
-
-struct program_space_data
-{
-  unsigned index;
-  void (*cleanup) (struct program_space *, void *);
-};
-
-struct program_space_data_registration
-{
-  struct program_space_data *data;
-  struct program_space_data_registration *next;
-};
-
-struct program_space_data_registry
-{
-  struct program_space_data_registration *registrations;
-  unsigned num_registrations;
-};
-
-static struct program_space_data_registry program_space_data_registry
-  = { NULL, 0 };
-
-const struct program_space_data *
-register_program_space_data_with_cleanup
-  (void (*cleanup) (struct program_space *, void *))
-{
-  struct program_space_data_registration **curr;
-
-  /* Append new registration.  */
-  for (curr = &program_space_data_registry.registrations;
-       *curr != NULL; curr = &(*curr)->next);
-
-  *curr = XMALLOC (struct program_space_data_registration);
-  (*curr)->next = NULL;
-  (*curr)->data = XMALLOC (struct program_space_data);
-  (*curr)->data->index = program_space_data_registry.num_registrations++;
-  (*curr)->data->cleanup = cleanup;
-
-  return (*curr)->data;
-}
-
-const struct program_space_data *
-register_program_space_data (void)
-{
-  return register_program_space_data_with_cleanup (NULL);
-}
-
-static void
-program_space_alloc_data (struct program_space *pspace)
-{
-  gdb_assert (pspace->data == NULL);
-  pspace->num_data = program_space_data_registry.num_registrations;
-  pspace->data = XCALLOC (pspace->num_data, void *);
-}
-
-static void
-program_space_free_data (struct program_space *pspace)
-{
-  gdb_assert (pspace->data != NULL);
-  clear_program_space_data (pspace);
-  xfree (pspace->data);
-  pspace->data = NULL;
-}
-
-void
-clear_program_space_data (struct program_space *pspace)
-{
-  struct program_space_data_registration *registration;
-  int i;
-
-  gdb_assert (pspace->data != NULL);
-
-  for (registration = program_space_data_registry.registrations, i = 0;
-       i < pspace->num_data;
-       registration = registration->next, i++)
-    if (pspace->data[i] != NULL && registration->data->cleanup)
-      registration->data->cleanup (pspace, pspace->data[i]);
-
-  memset (pspace->data, 0, pspace->num_data * sizeof (void *));
-}
-
-void
-set_program_space_data (struct program_space *pspace,
-                      const struct program_space_data *data,
-                      void *value)
-{
-  gdb_assert (data->index < pspace->num_data);
-  pspace->data[data->index] = value;
-}
-
-void *
-program_space_data (struct program_space *pspace,
-                   const struct program_space_data *data)
-{
-  gdb_assert (data->index < pspace->num_data);
-  return pspace->data[data->index];
-}
-
-\f
-
 void
 initialize_progspace (void)
 {
index 3db3938aace7b4dd9eafaaec05453550b749a2f4..9348c3f231081b9b538b67e54b0ff42b39d87855 100644 (file)
@@ -24,6 +24,7 @@
 #include "target.h"
 #include "vec.h"
 #include "gdb_vecs.h"
+#include "registry.h"
 
 struct target_ops;
 struct bfd;
@@ -201,8 +202,7 @@ struct program_space
     VEC (char_ptr) *deleted_solibs;
 
     /* Per pspace data-pointers required by other GDB modules.  */
-    void **data;
-    unsigned num_data;
+    REGISTRY_FIELDS;
   };
 
 /* The object file that the main symbol table was loaded from (e.g. the
@@ -298,14 +298,6 @@ extern void clear_program_space_solib_cache (struct program_space *);
 /* Keep a registry of per-pspace data-pointers required by other GDB
    modules.  */
 
-extern const struct program_space_data *register_program_space_data (void);
-extern const struct program_space_data *register_program_space_data_with_cleanup
-  (void (*cleanup) (struct program_space *, void *));
-extern void clear_program_space_data (struct program_space *pspace);
-extern void set_program_space_data (struct program_space *pspace,
-                                   const struct program_space_data *data,
-                                   void *value);
-extern void *program_space_data (struct program_space *pspace,
-                          const struct program_space_data *data);
+DECLARE_REGISTRY (program_space);
 
 #endif
index 907b73e8da8ff1c64f29813fda66e94ca657a530..211a643ddaed1d4ecf3b3a31a4934941bcc7bc37 100644 (file)
@@ -725,7 +725,7 @@ gdbpy_initialize_inferior (void)
                      (PyObject *) &inferior_object_type);
 
   infpy_inf_data_key =
-    register_inferior_data_with_cleanup (py_free_inferior);
+    register_inferior_data_with_cleanup (NULL, py_free_inferior);
 
   observer_attach_new_thread (add_thread_object);
   observer_attach_thread_exit (delete_thread_object);
index 1cb82408ce6452f485290e20de102c89670ba9d5..e4b029b2070549864cd60a7fa5e1fa99f7d9818b 100644 (file)
@@ -179,7 +179,7 @@ void
 gdbpy_initialize_pspace (void)
 {
   pspy_pspace_data_key
-    = register_program_space_data_with_cleanup (py_free_pspace);
+    = register_program_space_data_with_cleanup (NULL, py_free_pspace);
 
   if (PyType_Ready (&pspace_object_type) < 0)
     return;
diff --git a/gdb/registry.h b/gdb/registry.h
new file mode 100644 (file)
index 0000000..d696781
--- /dev/null
@@ -0,0 +1,187 @@
+/* Macros for general registry objects.
+
+   Copyright (C) 2011, 2012
+   Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef REGISTRY_H
+#define REGISTRY_H
+
+/* The macros here implement a template type and functions for
+   associating some user data with a container object.
+
+   The API user requests a key from a registry during gdb
+   initialization.  Later this key can be used to associate some
+   module-specific data with a specific container object.
+
+   A registry is associated with a struct tag name.
+
+   The exported API is best used via the wrapper macros:
+   
+   - register_TAG_data(TAG)
+   Get a new key for the container type TAG.
+   
+   - register_TAG_data_with_cleanup(TAG, SAVE, FREE)
+   Get a new key for the container type TAG.
+   SAVE and FREE are defined as void (*) (struct TAG *, void *)
+   When the container is destroyed, first all registered SAVE
+   functions are called.
+   Then all FREE functions are called.
+   Either or both may be NULL.
+   
+   - clear_TAG_data(TAG, OBJECT)
+   Clear all the data associated with OBJECT.  Should be called by the
+   container implementation when a container object is destroyed.
+   
+   - set_TAG_data(TAG, OBJECT, KEY, DATA)
+   Set the data on an object.
+   
+   - TAG_data(TAG, OBJECT, KEY)
+   Fetch the data for an object; returns NULL if it has not been set.
+*/
+
+/* This macro is used in a container struct definition to define the
+   fields used by the registry code.  */
+
+#define REGISTRY_FIELDS                                \
+  void **data;                                 \
+  unsigned num_data
+
+/* Define a new registry implementation.  */
+
+#define DEFINE_REGISTRY(TAG)                                           \
+struct TAG ## _data                                                    \
+{                                                                      \
+  unsigned index;                                                      \
+  void (*save) (struct TAG *, void *);                                 \
+  void (*free) (struct TAG *, void *);                                 \
+};                                                                     \
+                                                                       \
+struct TAG ## _data_registration                                       \
+{                                                                      \
+  struct TAG ## _data *data;                                           \
+  struct TAG ## _data_registration *next;                              \
+};                                                                     \
+                                                                       \
+struct TAG ## _data_registry                                           \
+{                                                                      \
+  struct TAG ## _data_registration *registrations;                     \
+  unsigned num_registrations;                                          \
+};                                                                     \
+                                                                       \
+struct TAG ## _data_registry TAG ## _data_registry = { NULL, 0 };      \
+                                                                       \
+const struct TAG ## _data *                                            \
+register_ ## TAG ## _data_with_cleanup (void (*save) (struct TAG *, void *), \
+                                   void (*free) (struct TAG *, void *)) \
+{                                                                      \
+  struct TAG ## _data_registration **curr;                             \
+                                                                       \
+  /* Append new registration.  */                                      \
+  for (curr = &TAG ## _data_registry.registrations;                    \
+       *curr != NULL; curr = &(*curr)->next);                          \
+                                                                       \
+  *curr = XMALLOC (struct TAG ## _data_registration);                  \
+  (*curr)->next = NULL;                                                        \
+  (*curr)->data = XMALLOC (struct TAG ## _data);                       \
+  (*curr)->data->index = TAG ## _data_registry.num_registrations++;    \
+  (*curr)->data->save = save;                                          \
+  (*curr)->data->free = free;                                          \
+                                                                       \
+  return (*curr)->data;                                                        \
+}                                                                      \
+                                                                       \
+const struct TAG ## _data *                                            \
+register_ ## TAG ## _data (void)                                       \
+{                                                                      \
+  return register_ ## TAG ## _data_with_cleanup (NULL, NULL);          \
+}                                                                      \
+                                                                       \
+static void                                                            \
+TAG ## _alloc_data (struct TAG *container)                             \
+{                                                                      \
+  gdb_assert (container->data == NULL);                                        \
+  container->num_data = TAG ## _data_registry.num_registrations;       \
+  container->data = XCALLOC (container->num_data, void *);             \
+}                                                                      \
+                                                                       \
+void                                                                   \
+clear_ ## TAG ## _data (struct TAG *container)                         \
+{                                                                      \
+  struct TAG ## _data_registration *registration;                      \
+  int i;                                                               \
+                                                                       \
+  gdb_assert (container->data != NULL);                                        \
+                                                                       \
+  /* Process all the save handlers.  */                                        \
+                                                                       \
+  for (registration = TAG ## _data_registry.registrations, i = 0;      \
+       i < container->num_data;                                                \
+       registration = registration->next, i++)                         \
+    if (container->data[i] != NULL && registration->data->save != NULL)        \
+      registration->data->save (container, container->data[i]);                \
+                                                                       \
+  /* Now process all the free handlers.  */                            \
+                                                                       \
+  for (registration = TAG ## _data_registry.registrations, i = 0;      \
+       i < container->num_data;                                                \
+       registration = registration->next, i++)                         \
+    if (container->data[i] != NULL && registration->data->free != NULL)        \
+      registration->data->free (container, container->data[i]);                \
+                                                                       \
+  memset (container->data, 0, container->num_data * sizeof (void *));  \
+}                                                                      \
+                                                                       \
+static void                                                            \
+TAG ## _free_data (struct TAG *container)                              \
+{                                                                      \
+  void ***rdata = &container->data;                                    \
+  gdb_assert (*rdata != NULL);                                         \
+  clear_ ## TAG ## _data (container);                                  \
+  xfree (*rdata);                                                      \
+  *rdata = NULL;                                                       \
+}                                                                      \
+                                                                       \
+void                                                                   \
+set_ ## TAG ## _data (struct TAG *container, const struct TAG ## _data *data, \
+                 void *value)                                          \
+{                                                                      \
+  gdb_assert (data->index < container->num_data);                      \
+  container->data[data->index] = value;                                        \
+}                                                                      \
+                                                                       \
+void *                                                                 \
+TAG ## _data (struct TAG *container, const struct TAG ## _data *data)  \
+{                                                                      \
+  gdb_assert (data->index < container->num_data);                      \
+  return container->data[data->index];                                 \
+}
+
+
+/* External declarations for the registry functions.  */
+
+#define DECLARE_REGISTRY(TAG)                                          \
+extern const struct TAG ## _data *register_ ## TAG ## _data (void);    \
+extern const struct TAG ## _data *register_ ## TAG ## _data_with_cleanup \
+ (void (*save) (struct TAG *, void *), void (*free) (struct TAG *, void *)); \
+extern void clear_ ## TAG ## _data (struct TAG *);             \
+extern void set_ ## TAG ## _data (struct TAG *,                        \
+                              const struct TAG ## _data *data, void *value); \
+extern void *TAG ## _data (struct TAG *,                       \
+                          const struct TAG ## _data *data);
+
+#endif /* REGISTRY_H */
index db8f187ad0f4b0a1f82bc1c57f4270c5ca4be11e..d08bd387692fc5d0e1f5a668f749062046b45b95 100644 (file)
@@ -534,7 +534,8 @@ void
 _initialize_darwin_solib (void)
 {
   solib_darwin_pspace_data
-    = register_program_space_data_with_cleanup (darwin_pspace_data_cleanup);
+    = register_program_space_data_with_cleanup (NULL,
+                                               darwin_pspace_data_cleanup);
 
   darwin_so_ops.relocate_section_addresses = darwin_relocate_section_addresses;
   darwin_so_ops.free_so = darwin_free_so;
index 300532627c2d3a566ebee8939f37c2907eadbbe1..8276db295156938664ed1b75445b2d6d1efcc4f2 100644 (file)
@@ -1171,7 +1171,7 @@ void
 _initialize_dsbt_solib (void)
 {
   solib_dsbt_pspace_data
-    = register_program_space_data_with_cleanup (dsbt_pspace_data_cleanup);
+    = register_program_space_data_with_cleanup (NULL, dsbt_pspace_data_cleanup);
 
   dsbt_so_ops.relocate_section_addresses = dsbt_relocate_section_addresses;
   dsbt_so_ops.free_so = dsbt_free_so;
index 2f4a345d241a953a2055a5383d30112e4ff7a9a1..3d60aa1ae4f5bec6dd089940183094b2c7632e75 100644 (file)
@@ -2484,7 +2484,7 @@ _initialize_svr4_solib (void)
 {
   solib_svr4_data = gdbarch_data_register_pre_init (solib_svr4_init);
   solib_svr4_pspace_data
-    = register_program_space_data_with_cleanup (svr4_pspace_data_cleanup);
+    = register_program_space_data_with_cleanup (NULL, svr4_pspace_data_cleanup);
 
   svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses;
   svr4_so_ops.free_so = svr4_free_so;