Addd set_gdbarch_data() method. Update register_gdbarch_data() interface.
[deliverable/binutils-gdb.git] / gdb / gdbarch.c
index 6bf83bb0121df523eac0dad9d1d4d51adfcb67f3..44c26a841fd05b6be1ad1044fc7c9c5d7ce36ffe 100644 (file)
@@ -1,7 +1,7 @@
 /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
 
 /* Dynamic architecture support for GDB, the GNU debugger.
-   Copyright 1998-1999, Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #include "floatformat.h"
 
+#include "gdb_assert.h"
+
 /* Static function declarations */
 
 static void verify_gdbarch (struct gdbarch *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 *);
 static void swapin_gdbarch_swap (struct gdbarch *);
@@ -96,7 +100,7 @@ struct gdbarch
   gdbarch_dump_tdep_ftype *dump_tdep;
 
   /* per-architecture data-pointers */
-  int nr_data;
+  unsigned nr_data;
   void **data;
 
   /* per-architecture swap-regions */
@@ -117,7 +121,7 @@ struct gdbarch
      verify_gdbarch(): Confirm that the target updated the field
      correctly.
 
-     gdbarch_dump(): Add a fprintf_unfiltered call to so that the new
+     gdbarch_dump(): Add a fprintf_unfiltered call so that the new
      field is dumped out
 
      ``startup_gdbarch()'': Append an initial value to the static
@@ -153,6 +157,11 @@ struct gdbarch
   int fp0_regnum;
   int npc_regnum;
   int nnpc_regnum;
+  gdbarch_stab_reg_to_regnum_ftype *stab_reg_to_regnum;
+  gdbarch_ecoff_reg_to_regnum_ftype *ecoff_reg_to_regnum;
+  gdbarch_dwarf_reg_to_regnum_ftype *dwarf_reg_to_regnum;
+  gdbarch_sdb_reg_to_regnum_ftype *sdb_reg_to_regnum;
+  gdbarch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum;
   gdbarch_register_name_ftype *register_name;
   int register_size;
   int register_bytes;
@@ -164,6 +173,7 @@ struct gdbarch
   gdbarch_register_virtual_type_ftype *register_virtual_type;
   gdbarch_do_registers_info_ftype *do_registers_info;
   gdbarch_register_sim_regno_ftype *register_sim_regno;
+  gdbarch_register_bytes_ok_ftype *register_bytes_ok;
   int use_generic_dummy_frames;
   int call_dummy_location;
   gdbarch_call_dummy_address_ftype *call_dummy_address;
@@ -229,9 +239,11 @@ struct gdbarch
   int extra_stack_alignment_needed;
   gdbarch_reg_struct_has_addr_ftype *reg_struct_has_addr;
   gdbarch_save_dummy_frame_tos_ftype *save_dummy_frame_tos;
+  int parm_boundary;
   const struct floatformat * float_format;
   const struct floatformat * double_format;
   const struct floatformat * long_double_format;
+  gdbarch_convert_from_func_ptr_addr_ftype *convert_from_func_ptr_addr;
 };
 
 
@@ -303,6 +315,12 @@ struct gdbarch startup_gdbarch =
   0,
   0,
   0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
   generic_get_saved_register,
   0,
   0,
@@ -354,6 +372,8 @@ struct gdbarch startup_gdbarch =
   0,
   0,
   0,
+  0,
+  0,
   /* startup_gdbarch() */
 };
 
@@ -370,6 +390,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;
@@ -398,6 +420,11 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->fp0_regnum = -1;
   gdbarch->npc_regnum = -1;
   gdbarch->nnpc_regnum = -1;
+  gdbarch->stab_reg_to_regnum = no_op_reg_to_regnum;
+  gdbarch->ecoff_reg_to_regnum = no_op_reg_to_regnum;
+  gdbarch->dwarf_reg_to_regnum = no_op_reg_to_regnum;
+  gdbarch->sdb_reg_to_regnum = no_op_reg_to_regnum;
+  gdbarch->dwarf2_reg_to_regnum = no_op_reg_to_regnum;
   gdbarch->register_name = legacy_register_name;
   gdbarch->register_size = -1;
   gdbarch->register_bytes = -1;
@@ -429,6 +456,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->frame_args_skip = -1;
   gdbarch->frameless_function_invocation = generic_frameless_function_invocation_not;
   gdbarch->extra_stack_alignment_needed = 1;
+  gdbarch->convert_from_func_ptr_addr = default_convert_from_func_ptr_addr;
   /* gdbarch_alloc() */
 
   return gdbarch;
@@ -444,8 +472,9 @@ gdbarch_alloc (const struct gdbarch_info *info,
 void
 gdbarch_free (struct gdbarch *arch)
 {
-  /* At the moment, this is trivial.  */
-  free (arch);
+  gdb_assert (arch != NULL);
+  free_gdbarch_data (arch);
+  xfree (arch);
 }
 
 
@@ -497,6 +526,11 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of fp0_regnum, invalid_p == 0 */
   /* Skip verify of npc_regnum, invalid_p == 0 */
   /* Skip verify of nnpc_regnum, invalid_p == 0 */
+  /* Skip verify of stab_reg_to_regnum, invalid_p == 0 */
+  /* Skip verify of ecoff_reg_to_regnum, invalid_p == 0 */
+  /* Skip verify of dwarf_reg_to_regnum, invalid_p == 0 */
+  /* Skip verify of sdb_reg_to_regnum, invalid_p == 0 */
+  /* Skip verify of dwarf2_reg_to_regnum, invalid_p == 0 */
   /* Skip verify of register_name, invalid_p == 0 */
   if ((GDB_MULTI_ARCH >= 2)
       && (gdbarch->register_size == -1))
@@ -524,6 +558,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
     internal_error ("gdbarch: verify_gdbarch: register_virtual_type invalid");
   /* Skip verify of do_registers_info, invalid_p == 0 */
   /* Skip verify of register_sim_regno, invalid_p == 0 */
+  /* Skip verify of register_bytes_ok, has predicate */
   if ((GDB_MULTI_ARCH >= 1)
       && (gdbarch->use_generic_dummy_frames == -1))
     internal_error ("gdbarch: verify_gdbarch: use_generic_dummy_frames invalid");
@@ -665,6 +700,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
     gdbarch->double_format = default_double_format (gdbarch);
   if (gdbarch->long_double_format == 0)
     gdbarch->long_double_format = &floatformat_unknown;
+  /* Skip verify of convert_from_func_ptr_addr, invalid_p == 0 */
 }
 
 
@@ -826,6 +862,36 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: NNPC_REGNUM # %s\n",
                       XSTRING (NNPC_REGNUM));
 #endif
+#ifdef STAB_REG_TO_REGNUM
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "STAB_REG_TO_REGNUM(stab_regnr)",
+                      XSTRING (STAB_REG_TO_REGNUM (stab_regnr)));
+#endif
+#ifdef ECOFF_REG_TO_REGNUM
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "ECOFF_REG_TO_REGNUM(ecoff_regnr)",
+                      XSTRING (ECOFF_REG_TO_REGNUM (ecoff_regnr)));
+#endif
+#ifdef DWARF_REG_TO_REGNUM
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "DWARF_REG_TO_REGNUM(dwarf_regnr)",
+                      XSTRING (DWARF_REG_TO_REGNUM (dwarf_regnr)));
+#endif
+#ifdef SDB_REG_TO_REGNUM
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "SDB_REG_TO_REGNUM(sdb_regnr)",
+                      XSTRING (SDB_REG_TO_REGNUM (sdb_regnr)));
+#endif
+#ifdef DWARF2_REG_TO_REGNUM
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "DWARF2_REG_TO_REGNUM(dwarf2_regnr)",
+                      XSTRING (DWARF2_REG_TO_REGNUM (dwarf2_regnr)));
+#endif
 #ifdef REGISTER_NAME
   fprintf_unfiltered (file,
                       "gdbarch_dump: %s # %s\n",
@@ -889,6 +955,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "REGISTER_SIM_REGNO(reg_nr)",
                       XSTRING (REGISTER_SIM_REGNO (reg_nr)));
 #endif
+#ifdef REGISTER_BYTES_OK
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "REGISTER_BYTES_OK(nr_bytes)",
+                      XSTRING (REGISTER_BYTES_OK (nr_bytes)));
+#endif
 #ifdef USE_GENERIC_DUMMY_FRAMES
   fprintf_unfiltered (file,
                       "gdbarch_dump: USE_GENERIC_DUMMY_FRAMES # %s\n",
@@ -1278,6 +1350,11 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "SAVE_DUMMY_FRAME_TOS(sp)",
                       XSTRING (SAVE_DUMMY_FRAME_TOS (sp)));
 #endif
+#ifdef PARM_BOUNDARY
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: PARM_BOUNDARY # %s\n",
+                      XSTRING (PARM_BOUNDARY));
+#endif
 #ifdef TARGET_FLOAT_FORMAT
   fprintf_unfiltered (file,
                       "gdbarch_dump: TARGET_FLOAT_FORMAT # %s\n",
@@ -1293,6 +1370,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: TARGET_LONG_DOUBLE_FORMAT # %s\n",
                       XSTRING (TARGET_LONG_DOUBLE_FORMAT));
 #endif
+#ifdef CONVERT_FROM_FUNC_PTR_ADDR
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "CONVERT_FROM_FUNC_PTR_ADDR(addr)",
+                      XSTRING (CONVERT_FROM_FUNC_PTR_ADDR (addr)));
+#endif
 #ifdef TARGET_ARCHITECTURE
   if (TARGET_ARCHITECTURE != NULL)
     fprintf_unfiltered (file,
@@ -1441,6 +1524,41 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       "gdbarch_dump: NNPC_REGNUM = %ld\n",
                       (long) NNPC_REGNUM);
 #endif
+#ifdef STAB_REG_TO_REGNUM
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: STAB_REG_TO_REGNUM = 0x%08lx\n",
+                        (long) current_gdbarch->stab_reg_to_regnum
+                        /*STAB_REG_TO_REGNUM ()*/);
+#endif
+#ifdef ECOFF_REG_TO_REGNUM
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: ECOFF_REG_TO_REGNUM = 0x%08lx\n",
+                        (long) current_gdbarch->ecoff_reg_to_regnum
+                        /*ECOFF_REG_TO_REGNUM ()*/);
+#endif
+#ifdef DWARF_REG_TO_REGNUM
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: DWARF_REG_TO_REGNUM = 0x%08lx\n",
+                        (long) current_gdbarch->dwarf_reg_to_regnum
+                        /*DWARF_REG_TO_REGNUM ()*/);
+#endif
+#ifdef SDB_REG_TO_REGNUM
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: SDB_REG_TO_REGNUM = 0x%08lx\n",
+                        (long) current_gdbarch->sdb_reg_to_regnum
+                        /*SDB_REG_TO_REGNUM ()*/);
+#endif
+#ifdef DWARF2_REG_TO_REGNUM
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: DWARF2_REG_TO_REGNUM = 0x%08lx\n",
+                        (long) current_gdbarch->dwarf2_reg_to_regnum
+                        /*DWARF2_REG_TO_REGNUM ()*/);
+#endif
 #ifdef REGISTER_NAME
   if (GDB_MULTI_ARCH)
     fprintf_unfiltered (file,
@@ -1510,6 +1628,13 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                         (long) current_gdbarch->register_sim_regno
                         /*REGISTER_SIM_REGNO ()*/);
 #endif
+#ifdef REGISTER_BYTES_OK
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: REGISTER_BYTES_OK = 0x%08lx\n",
+                        (long) current_gdbarch->register_bytes_ok
+                        /*REGISTER_BYTES_OK ()*/);
+#endif
 #ifdef USE_GENERIC_DUMMY_FRAMES
   fprintf_unfiltered (file,
                       "gdbarch_dump: USE_GENERIC_DUMMY_FRAMES = %ld\n",
@@ -1934,6 +2059,11 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                         (long) current_gdbarch->save_dummy_frame_tos
                         /*SAVE_DUMMY_FRAME_TOS ()*/);
 #endif
+#ifdef PARM_BOUNDARY
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: PARM_BOUNDARY = %ld\n",
+                      (long) PARM_BOUNDARY);
+#endif
 #ifdef TARGET_FLOAT_FORMAT
   fprintf_unfiltered (file,
                       "gdbarch_dump: TARGET_FLOAT_FORMAT = %ld\n",
@@ -1948,6 +2078,13 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   fprintf_unfiltered (file,
                       "gdbarch_dump: TARGET_LONG_DOUBLE_FORMAT = %ld\n",
                       (long) TARGET_LONG_DOUBLE_FORMAT);
+#endif
+#ifdef CONVERT_FROM_FUNC_PTR_ADDR
+  if (GDB_MULTI_ARCH)
+    fprintf_unfiltered (file,
+                        "gdbarch_dump: CONVERT_FROM_FUNC_PTR_ADDR = 0x%08lx\n",
+                        (long) current_gdbarch->convert_from_func_ptr_addr
+                        /*CONVERT_FROM_FUNC_PTR_ADDR ()*/);
 #endif
   if (current_gdbarch->dump_tdep != NULL)
     current_gdbarch->dump_tdep (current_gdbarch, file);
@@ -2389,6 +2526,91 @@ set_gdbarch_nnpc_regnum (struct gdbarch *gdbarch,
   gdbarch->nnpc_regnum = nnpc_regnum;
 }
 
+int
+gdbarch_stab_reg_to_regnum (struct gdbarch *gdbarch, int stab_regnr)
+{
+  if (gdbarch->stab_reg_to_regnum == 0)
+    internal_error ("gdbarch: gdbarch_stab_reg_to_regnum invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_stab_reg_to_regnum called\n");
+  return gdbarch->stab_reg_to_regnum (stab_regnr);
+}
+
+void
+set_gdbarch_stab_reg_to_regnum (struct gdbarch *gdbarch,
+                                gdbarch_stab_reg_to_regnum_ftype stab_reg_to_regnum)
+{
+  gdbarch->stab_reg_to_regnum = stab_reg_to_regnum;
+}
+
+int
+gdbarch_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int ecoff_regnr)
+{
+  if (gdbarch->ecoff_reg_to_regnum == 0)
+    internal_error ("gdbarch: gdbarch_ecoff_reg_to_regnum invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_ecoff_reg_to_regnum called\n");
+  return gdbarch->ecoff_reg_to_regnum (ecoff_regnr);
+}
+
+void
+set_gdbarch_ecoff_reg_to_regnum (struct gdbarch *gdbarch,
+                                 gdbarch_ecoff_reg_to_regnum_ftype ecoff_reg_to_regnum)
+{
+  gdbarch->ecoff_reg_to_regnum = ecoff_reg_to_regnum;
+}
+
+int
+gdbarch_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int dwarf_regnr)
+{
+  if (gdbarch->dwarf_reg_to_regnum == 0)
+    internal_error ("gdbarch: gdbarch_dwarf_reg_to_regnum invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_dwarf_reg_to_regnum called\n");
+  return gdbarch->dwarf_reg_to_regnum (dwarf_regnr);
+}
+
+void
+set_gdbarch_dwarf_reg_to_regnum (struct gdbarch *gdbarch,
+                                 gdbarch_dwarf_reg_to_regnum_ftype dwarf_reg_to_regnum)
+{
+  gdbarch->dwarf_reg_to_regnum = dwarf_reg_to_regnum;
+}
+
+int
+gdbarch_sdb_reg_to_regnum (struct gdbarch *gdbarch, int sdb_regnr)
+{
+  if (gdbarch->sdb_reg_to_regnum == 0)
+    internal_error ("gdbarch: gdbarch_sdb_reg_to_regnum invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_sdb_reg_to_regnum called\n");
+  return gdbarch->sdb_reg_to_regnum (sdb_regnr);
+}
+
+void
+set_gdbarch_sdb_reg_to_regnum (struct gdbarch *gdbarch,
+                               gdbarch_sdb_reg_to_regnum_ftype sdb_reg_to_regnum)
+{
+  gdbarch->sdb_reg_to_regnum = sdb_reg_to_regnum;
+}
+
+int
+gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int dwarf2_regnr)
+{
+  if (gdbarch->dwarf2_reg_to_regnum == 0)
+    internal_error ("gdbarch: gdbarch_dwarf2_reg_to_regnum invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_dwarf2_reg_to_regnum called\n");
+  return gdbarch->dwarf2_reg_to_regnum (dwarf2_regnr);
+}
+
+void
+set_gdbarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch,
+                                  gdbarch_dwarf2_reg_to_regnum_ftype dwarf2_reg_to_regnum)
+{
+  gdbarch->dwarf2_reg_to_regnum = dwarf2_reg_to_regnum;
+}
+
 char *
 gdbarch_register_name (struct gdbarch *gdbarch, int regnr)
 {
@@ -2576,6 +2798,29 @@ set_gdbarch_register_sim_regno (struct gdbarch *gdbarch,
   gdbarch->register_sim_regno = register_sim_regno;
 }
 
+int
+gdbarch_register_bytes_ok_p (struct gdbarch *gdbarch)
+{
+  return gdbarch->register_bytes_ok != 0;
+}
+
+int
+gdbarch_register_bytes_ok (struct gdbarch *gdbarch, long nr_bytes)
+{
+  if (gdbarch->register_bytes_ok == 0)
+    internal_error ("gdbarch: gdbarch_register_bytes_ok invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_register_bytes_ok called\n");
+  return gdbarch->register_bytes_ok (nr_bytes);
+}
+
+void
+set_gdbarch_register_bytes_ok (struct gdbarch *gdbarch,
+                               gdbarch_register_bytes_ok_ftype register_bytes_ok)
+{
+  gdbarch->register_bytes_ok = register_bytes_ok;
+}
+
 int
 gdbarch_use_generic_dummy_frames (struct gdbarch *gdbarch)
 {
@@ -3692,6 +3937,21 @@ set_gdbarch_save_dummy_frame_tos (struct gdbarch *gdbarch,
   gdbarch->save_dummy_frame_tos = save_dummy_frame_tos;
 }
 
+int
+gdbarch_parm_boundary (struct gdbarch *gdbarch)
+{
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_parm_boundary called\n");
+  return gdbarch->parm_boundary;
+}
+
+void
+set_gdbarch_parm_boundary (struct gdbarch *gdbarch,
+                           int parm_boundary)
+{
+  gdbarch->parm_boundary = parm_boundary;
+}
+
 const struct floatformat *
 gdbarch_float_format (struct gdbarch *gdbarch)
 {
@@ -3737,45 +3997,65 @@ set_gdbarch_long_double_format (struct gdbarch *gdbarch,
   gdbarch->long_double_format = long_double_format;
 }
 
+CORE_ADDR
+gdbarch_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
+{
+  if (gdbarch->convert_from_func_ptr_addr == 0)
+    internal_error ("gdbarch: gdbarch_convert_from_func_ptr_addr invalid");
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_convert_from_func_ptr_addr called\n");
+  return gdbarch->convert_from_func_ptr_addr (addr);
+}
+
+void
+set_gdbarch_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
+                                        gdbarch_convert_from_func_ptr_addr_ftype convert_from_func_ptr_addr)
+{
+  gdbarch->convert_from_func_ptr_addr = convert_from_func_ptr_addr;
+}
 
-/* Keep a registrary of per-architecture data-pointers required by GDB
+
+/* Keep a registry of per-architecture data-pointers required by GDB
    modules. */
 
 struct gdbarch_data
 {
-  int index;
+  unsigned index;
+  gdbarch_data_init_ftype *init;
+  gdbarch_data_free_ftype *free;
 };
 
 struct gdbarch_data_registration
 {
-  gdbarch_data_ftype *init;
   struct gdbarch_data *data;
   struct gdbarch_data_registration *next;
 };
 
-struct gdbarch_data_registrary
+struct gdbarch_data_registry
 {
-  int nr;
+  unsigned nr;
   struct gdbarch_data_registration *registrations;
 };
 
-struct gdbarch_data_registrary gdbarch_data_registrary =
+struct gdbarch_data_registry gdbarch_data_registry =
 {
   0, NULL,
 };
 
 struct gdbarch_data *
-register_gdbarch_data (gdbarch_data_ftype *init)
+register_gdbarch_data (gdbarch_data_init_ftype *init,
+                       gdbarch_data_free_ftype *free)
 {
   struct gdbarch_data_registration **curr;
-  for (curr = &gdbarch_data_registrary.registrations;
+  for (curr = &gdbarch_data_registry.registrations;
        (*curr) != NULL;
        curr = &(*curr)->next);
   (*curr) = XMALLOC (struct gdbarch_data_registration);
   (*curr)->next = NULL;
-  (*curr)->init = init;
   (*curr)->data = XMALLOC (struct gdbarch_data);
-  (*curr)->data->index = gdbarch_data_registrary.nr++;
+  (*curr)->data->index = gdbarch_data_registry.nr++;
+  (*curr)->data->init = init;
+  (*curr)->data->free = free;
   return (*curr)->data;
 }
 
@@ -3786,32 +4066,79 @@ static void
 init_gdbarch_data (struct gdbarch *gdbarch)
 {
   struct gdbarch_data_registration *rego;
-  gdbarch->nr_data = gdbarch_data_registrary.nr + 1;
-  gdbarch->data = xmalloc (sizeof (void*) * gdbarch->nr_data);
-  for (rego = gdbarch_data_registrary.registrations;
+  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)
+        {
+          void *pointer = data->init (gdbarch);
+          set_gdbarch_data (gdbarch, data, pointer);
+        }
+    }
+}
+
+/* Create/delete the gdbarch data vector. */
+
+static void
+alloc_gdbarch_data (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch->data == NULL);
+  gdbarch->nr_data = gdbarch_data_registry.nr;
+  gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (void*));
+}
+
+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)
     {
-      if (rego->data->index < gdbarch->nr_data)
-       gdbarch->data[rego->data->index] = rego->init ();
+      struct gdbarch_data *data = rego->data;
+      gdb_assert (data->index < gdbarch->nr_data);
+      if (data->free != NULL && gdbarch->data[data->index] != 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)
+{
+  gdb_assert (data->index < gdbarch->nr_data);
+  if (data->free != NULL && gdbarch->data[data->index] != NULL)
+    data->free (gdbarch, gdbarch->data[data->index]);
+  gdbarch->data[data->index] = pointer;
+}
+
 /* Return the current value of the specified per-architecture
    data-pointer. */
 
 void *
 gdbarch_data (struct gdbarch_data *data)
 {
-  if (data->index >= current_gdbarch->nr_data)
-    internal_error ("gdbarch_data: request for non-existant data.");
+  gdb_assert (data->index < current_gdbarch->nr_data);
   return current_gdbarch->data[data->index];
 }
 
 
 
-/* Keep a registrary of swaped data required by GDB modules. */
+/* Keep a registry of swapped data required by GDB modules. */
 
 struct gdbarch_swap
 {
@@ -3828,13 +4155,13 @@ struct gdbarch_swap_registration
   struct gdbarch_swap_registration *next;
 };
 
-struct gdbarch_swap_registrary
+struct gdbarch_swap_registry
 {
   int nr;
   struct gdbarch_swap_registration *registrations;
 };
 
-struct gdbarch_swap_registrary gdbarch_swap_registrary = 
+struct gdbarch_swap_registry gdbarch_swap_registry = 
 {
   0, NULL,
 };
@@ -3845,7 +4172,7 @@ register_gdbarch_swap (void *data,
                       gdbarch_swap_ftype *init)
 {
   struct gdbarch_swap_registration **rego;
-  for (rego = &gdbarch_swap_registrary.registrations;
+  for (rego = &gdbarch_swap_registry.registrations;
        (*rego) != NULL;
        rego = &(*rego)->next);
   (*rego) = XMALLOC (struct gdbarch_swap_registration);
@@ -3861,7 +4188,7 @@ init_gdbarch_swap (struct gdbarch *gdbarch)
 {
   struct gdbarch_swap_registration *rego;
   struct gdbarch_swap **curr = &gdbarch->swap;
-  for (rego = gdbarch_swap_registrary.registrations;
+  for (rego = gdbarch_swap_registry.registrations;
        rego != NULL;
        rego = rego->next)
     {
@@ -3900,7 +4227,7 @@ swapin_gdbarch_swap (struct gdbarch *gdbarch)
 }
 
 
-/* Keep a registrary of the architectures known by GDB. */
+/* Keep a registry of the architectures known by GDB. */
 
 struct gdbarch_registration
 {
@@ -3911,7 +4238,7 @@ struct gdbarch_registration
   struct gdbarch_registration *next;
 };
 
-static struct gdbarch_registration *gdbarch_registrary = NULL;
+static struct gdbarch_registration *gdbarch_registry = NULL;
 
 static void
 append_name (const char ***buf, int *nr, const char *name)
@@ -3932,7 +4259,7 @@ gdbarch_printable_names (void)
       int nr_arches = 0;
       const char **arches = NULL;
       struct gdbarch_registration *rego;
-      for (rego = gdbarch_registrary;
+      for (rego = gdbarch_registry;
           rego != NULL;
           rego = rego->next)
        {
@@ -3964,14 +4291,14 @@ gdbarch_register (enum bfd_architecture bfd_architecture,
 {
   struct gdbarch_registration **curr;
   const struct bfd_arch_info *bfd_arch_info;
-  /* Check that BFD reconizes this architecture */
+  /* Check that BFD recognizes this architecture */
   bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
   if (bfd_arch_info == NULL)
     {
       internal_error ("gdbarch: Attempt to register unknown architecture (%d)", bfd_architecture);
     }
   /* Check that we haven't seen this architecture before */
-  for (curr = &gdbarch_registrary;
+  for (curr = &gdbarch_registry;
        (*curr) != NULL;
        curr = &(*curr)->next)
     {
@@ -3991,8 +4318,8 @@ gdbarch_register (enum bfd_architecture bfd_architecture,
   (*curr)->dump_tdep = dump_tdep;
   (*curr)->arches = NULL;
   (*curr)->next = NULL;
-  /* When non- multi-arch, install what ever target dump routine we've
-     been provided - hopefully that routine has been writen correct
+  /* When non- multi-arch, install whatever target dump routine we've
+     been provided - hopefully that routine has been written correctly
      and works regardless of multi-arch. */
   if (!GDB_MULTI_ARCH && dump_tdep != NULL
       && startup_gdbarch.dump_tdep == NULL)
@@ -4068,7 +4395,7 @@ gdbarch_update_p (struct gdbarch_info info)
   /* A default for abfd? */
 
   /* Find the target that knows about this architecture. */
-  for (rego = gdbarch_registrary;
+  for (rego = gdbarch_registry;
        rego != NULL;
        rego = rego->next)
     if (rego->bfd_architecture == info.bfd_architecture)
This page took 0.075954 seconds and 4 git commands to generate.