]> Git Repo - binutils.git/commitdiff
* gdbarch.sh, gdbarch.c: Revert change of 2001-06-01; all
authorJim Blandy <[email protected]>
Wed, 6 Jun 2001 14:46:30 +0000 (14:46 +0000)
committerJim Blandy <[email protected]>
Wed, 6 Jun 2001 14:46:30 +0000 (14:46 +0000)
per-architecture data should be registered at initialization time,
before any gdbarch objects get used, so the generality is
unnecessary.

gdb/ChangeLog
gdb/gdbarch.c
gdb/gdbarch.sh

index ec0839ee2dd983697dca55c126319742b7ad6b10..ffa0147dbfc1dcd3cc8779a04e1c616a070bb106 100644 (file)
@@ -1,3 +1,10 @@
+2001-06-06  Jim Blandy  <[email protected]>
+
+       * gdbarch.sh, gdbarch.c: Revert change of 2001-06-01; all
+       per-architecture data should be registered at initialization time,
+       before any gdbarch objects get used, so the generality is
+       unnecessary.
+
 2001-06-06  Keith Seitz  <[email protected]>
 
        * gdb-events.sh (function_list): Add tracepoint_create,
index adf2f81c2eec6cb3cd6f50492aed215b2442667a..2bd957f6e018a66e80b7a73eb9c195a8b413a91a 100644 (file)
@@ -65,7 +65,8 @@
 /* Static function declarations */
 
 static void verify_gdbarch (struct gdbarch *gdbarch);
-static void check_gdbarch_data (struct gdbarch *);
+static void alloc_gdbarch_data (struct gdbarch *);
+static void init_gdbarch_data (struct gdbarch *);
 static void free_gdbarch_data (struct gdbarch *);
 static void init_gdbarch_swap (struct gdbarch *);
 static void swapout_gdbarch_swap (struct gdbarch *);
@@ -397,6 +398,8 @@ gdbarch_alloc (const struct gdbarch_info *info,
   struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
   memset (gdbarch, 0, sizeof (*gdbarch));
 
+  alloc_gdbarch_data (gdbarch);
+
   gdbarch->tdep = tdep;
 
   gdbarch->bfd_arch_info = info->bfd_arch_info;
@@ -4334,81 +4337,66 @@ register_gdbarch_data (gdbarch_data_init_ftype *init,
 }
 
 
-/* Delete GDBARCH's data vector. */
+/* Walk through all the registered users initializing each in turn. */
 
 static void
-free_gdbarch_data (struct gdbarch *gdbarch)
+init_gdbarch_data (struct gdbarch *gdbarch)
 {
-  if (gdbarch->data != NULL)
+  struct gdbarch_data_registration *rego;
+  for (rego = gdbarch_data_registry.registrations;
+       rego != NULL;
+       rego = rego->next)
     {
-      struct gdbarch_data_registration *rego;
-
-      for (rego = gdbarch_data_registry.registrations;
-           rego != NULL;
-           rego = rego->next)
+      struct gdbarch_data *data = rego->data;
+      gdb_assert (data->index < gdbarch->nr_data);
+      if (data->init != NULL)
         {
-          struct gdbarch_data *data = rego->data;
-      
-          if (data->index < gdbarch->nr_data
-              && data->free != NULL
-              && gdbarch->data[data->index] != NULL)
-            {
-              data->free (gdbarch, gdbarch->data[data->index]);
-              gdbarch->data[data->index] = NULL;
-            }
+          void *pointer = data->init (gdbarch);
+          set_gdbarch_data (gdbarch, data, pointer);
         }
-      xfree (gdbarch->data);
-      gdbarch->data = NULL;
     }
 }
 
+/* Create/delete the gdbarch data vector. */
 
-/* Make sure that GDBARCH has space for all registered per-
-   architecture data.  If not, expand the table and initialize the
-   data values.  */
 static void
-check_gdbarch_data (struct gdbarch *gdbarch)
+alloc_gdbarch_data (struct gdbarch *gdbarch)
 {
-  int nr_allocated = gdbarch->nr_data;
-
-  /* How many per-architecture data items are registered so far?  */
-  int nr_registered = gdbarch_data_registry.nr;
+  gdb_assert (gdbarch->data == NULL);
+  gdbarch->nr_data = gdbarch_data_registry.nr;
+  gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (void*));
+}
 
-  if (nr_allocated < nr_registered)
+static void
+free_gdbarch_data (struct gdbarch *gdbarch)
+{
+  struct gdbarch_data_registration *rego;
+  gdb_assert (gdbarch->data != NULL);
+  for (rego = gdbarch_data_registry.registrations;
+       rego != NULL;
+       rego = rego->next)
     {
-      /* Get enough room for all registered items, not just DATA.  */
-      int new_size = sizeof (gdbarch->data[0]) * nr_registered;
-      struct gdbarch_data_registration *rego;
-      
-      /* Expand the array, or perhaps allocate it for the first time.  */
-      gdbarch->data = (void **) (gdbarch->data
-                                 ? xrealloc (gdbarch->data, new_size)
-                                 : xmalloc (new_size));
-
-      /* Record the size now allocated.  */
-      gdbarch->nr_data = nr_registered;
-
-      /* Initialize the elements we just added.  */
-      for (rego = gdbarch_data_registry.registrations;
-           rego != NULL;
-           rego = rego->next)
+      struct gdbarch_data *data = rego->data;
+      gdb_assert (data->index < gdbarch->nr_data);
+      if (data->free != NULL && gdbarch->data[data->index] != NULL)
         {
-          struct gdbarch_data *data = rego->data;
-          
-          if (data->index >= nr_allocated)
-            gdbarch->data[data->index]
-              = (data->init != NULL ? data->init (gdbarch) : NULL);
+          data->free (gdbarch, gdbarch->data[data->index]);
+          gdbarch->data[data->index] = NULL;
         }
     }
+  xfree (gdbarch->data);
+  gdbarch->data = NULL;
 }
 
 
+/* Initialize the current value of thee specified per-architecture
+   data-pointer. */
+
 void
 set_gdbarch_data (struct gdbarch *gdbarch,
                   struct gdbarch_data *data,
                   void *pointer)
 {
-  check_gdbarch_data (gdbarch);
   gdb_assert (data->index < gdbarch->nr_data);
   if (data->free != NULL && gdbarch->data[data->index] != NULL)
     data->free (gdbarch, gdbarch->data[data->index]);
@@ -4421,7 +4409,6 @@ set_gdbarch_data (struct gdbarch *gdbarch,
 void *
 gdbarch_data (struct gdbarch_data *data)
 {
-  check_gdbarch_data (current_gdbarch);
   gdb_assert (data->index < current_gdbarch->nr_data);
   return current_gdbarch->data[data->index];
 }
@@ -4790,6 +4777,11 @@ gdbarch_update_p (struct gdbarch_info info)
      called. */
   init_gdbarch_swap (new_gdbarch);
   
+  /* Initialize the per-architecture data-pointer of all parties that
+     registered an interest in this architecture.  CURRENT_GDBARCH
+     must be updated before these modules are called. */
+  init_gdbarch_data (new_gdbarch);
+  
   if (gdbarch_debug)
     gdbarch_dump (current_gdbarch, gdb_stdlog);
 
index 75480900d9663e2c56efe536259b70d7459a31e0..14e88c30a83f12724de977dca7877379427805f9 100755 (executable)
@@ -1118,7 +1118,8 @@ cat <<EOF
 /* Static function declarations */
 
 static void verify_gdbarch (struct gdbarch *gdbarch);
-static void check_gdbarch_data (struct gdbarch *);
+static void alloc_gdbarch_data (struct gdbarch *);
+static void init_gdbarch_data (struct gdbarch *);
 static void free_gdbarch_data (struct gdbarch *);
 static void init_gdbarch_swap (struct gdbarch *);
 static void swapout_gdbarch_swap (struct gdbarch *);
@@ -1263,6 +1264,8 @@ gdbarch_alloc (const struct gdbarch_info *info,
   struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
   memset (gdbarch, 0, sizeof (*gdbarch));
 
+  alloc_gdbarch_data (gdbarch);
+
   gdbarch->tdep = tdep;
 EOF
 printf "\n"
@@ -1628,81 +1631,66 @@ register_gdbarch_data (gdbarch_data_init_ftype *init,
 }
 
 
-/* Delete GDBARCH's data vector. */
+/* Walk through all the registered users initializing each in turn. */
 
 static void
-free_gdbarch_data (struct gdbarch *gdbarch)
+init_gdbarch_data (struct gdbarch *gdbarch)
 {
-  if (gdbarch->data != NULL)
+  struct gdbarch_data_registration *rego;
+  for (rego = gdbarch_data_registry.registrations;
+       rego != NULL;
+       rego = rego->next)
     {
-      struct gdbarch_data_registration *rego;
-
-      for (rego = gdbarch_data_registry.registrations;
-           rego != NULL;
-           rego = rego->next)
+      struct gdbarch_data *data = rego->data;
+      gdb_assert (data->index < gdbarch->nr_data);
+      if (data->init != NULL)
         {
-          struct gdbarch_data *data = rego->data;
-      
-          if (data->index < gdbarch->nr_data
-              && data->free != NULL
-              && gdbarch->data[data->index] != NULL)
-            {
-              data->free (gdbarch, gdbarch->data[data->index]);
-              gdbarch->data[data->index] = NULL;
-            }
+          void *pointer = data->init (gdbarch);
+          set_gdbarch_data (gdbarch, data, pointer);
         }
-      xfree (gdbarch->data);
-      gdbarch->data = NULL;
     }
 }
 
+/* Create/delete the gdbarch data vector. */
 
-/* Make sure that GDBARCH has space for all registered per-
-   architecture data.  If not, expand the table and initialize the
-   data values.  */
 static void
-check_gdbarch_data (struct gdbarch *gdbarch)
+alloc_gdbarch_data (struct gdbarch *gdbarch)
 {
-  int nr_allocated = gdbarch->nr_data;
-
-  /* How many per-architecture data items are registered so far?  */
-  int nr_registered = gdbarch_data_registry.nr;
+  gdb_assert (gdbarch->data == NULL);
+  gdbarch->nr_data = gdbarch_data_registry.nr;
+  gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (void*));
+}
 
-  if (nr_allocated < nr_registered)
+static void
+free_gdbarch_data (struct gdbarch *gdbarch)
+{
+  struct gdbarch_data_registration *rego;
+  gdb_assert (gdbarch->data != NULL);
+  for (rego = gdbarch_data_registry.registrations;
+       rego != NULL;
+       rego = rego->next)
     {
-      /* Get enough room for all registered items, not just DATA.  */
-      int new_size = sizeof (gdbarch->data[0]) * nr_registered;
-      struct gdbarch_data_registration *rego;
-      
-      /* Expand the array, or perhaps allocate it for the first time.  */
-      gdbarch->data = (void **) (gdbarch->data
-                                 ? xrealloc (gdbarch->data, new_size)
-                                 : xmalloc (new_size));
-
-      /* Record the size now allocated.  */
-      gdbarch->nr_data = nr_registered;
-
-      /* Initialize the elements we just added.  */
-      for (rego = gdbarch_data_registry.registrations;
-           rego != NULL;
-           rego = rego->next)
+      struct gdbarch_data *data = rego->data;
+      gdb_assert (data->index < gdbarch->nr_data);
+      if (data->free != NULL && gdbarch->data[data->index] != NULL)
         {
-          struct gdbarch_data *data = rego->data;
-          
-          if (data->index >= nr_allocated)
-            gdbarch->data[data->index]
-              = (data->init != NULL ? data->init (gdbarch) : NULL);
+          data->free (gdbarch, gdbarch->data[data->index]);
+          gdbarch->data[data->index] = NULL;
         }
     }
+  xfree (gdbarch->data);
+  gdbarch->data = NULL;
 }
 
 
+/* Initialize the current value of thee specified per-architecture
+   data-pointer. */
+
 void
 set_gdbarch_data (struct gdbarch *gdbarch,
                   struct gdbarch_data *data,
                   void *pointer)
 {
-  check_gdbarch_data (gdbarch);
   gdb_assert (data->index < gdbarch->nr_data);
   if (data->free != NULL && gdbarch->data[data->index] != NULL)
     data->free (gdbarch, gdbarch->data[data->index]);
@@ -1715,7 +1703,6 @@ set_gdbarch_data (struct gdbarch *gdbarch,
 void *
 gdbarch_data (struct gdbarch_data *data)
 {
-  check_gdbarch_data (current_gdbarch);
   gdb_assert (data->index < current_gdbarch->nr_data);
   return current_gdbarch->data[data->index];
 }
@@ -2084,6 +2071,11 @@ gdbarch_update_p (struct gdbarch_info info)
      called. */
   init_gdbarch_swap (new_gdbarch);
   
+  /* Initialize the per-architecture data-pointer of all parties that
+     registered an interest in this architecture.  CURRENT_GDBARCH
+     must be updated before these modules are called. */
+  init_gdbarch_data (new_gdbarch);
+  
   if (gdbarch_debug)
     gdbarch_dump (current_gdbarch, gdb_stdlog);
 
This page took 0.045748 seconds and 4 git commands to generate.