-/* 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 = GDBARCH_OBSTACK_CALLOC (gdbarch, gdbarch->nr_data, void *);
-}
-
-/* Initialize the current value of the specified per-architecture
- data-pointer. */
-
-void
-deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
- struct gdbarch_data *data,
- void *pointer)
-{
- gdb_assert (data->index < gdbarch->nr_data);
- gdb_assert (gdbarch->data[data->index] == NULL);
- gdb_assert (data->pre_init == NULL);
- gdbarch->data[data->index] = pointer;
-}
-
-/* Return the current value of the specified per-architecture
- data-pointer. */
-
-void *
-gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *data)
-{
- gdb_assert (data->index < gdbarch->nr_data);
- if (gdbarch->data[data->index] == NULL)
- {
- /* The data-pointer isn't initialized, call init() to get a
- value. */
- if (data->pre_init != NULL)
- /* Mid architecture creation: pass just the obstack, and not
- the entire architecture, as that way it isn't possible for
- pre-init code to refer to undefined architecture
- fields. */
- gdbarch->data[data->index] = data->pre_init (gdbarch->obstack);
- else if (gdbarch->initialized_p
- && data->post_init != NULL)
- /* Post architecture creation: pass the entire architecture
- (as all fields are valid), but be careful to also detect
- recursive references. */
- {
- gdb_assert (data->init_p);
- data->init_p = 0;
- gdbarch->data[data->index] = data->post_init (gdbarch);
- data->init_p = 1;
- }
- else
- /* The architecture initialization hasn't completed - punt -
- hope that the caller knows what they are doing. Once
- deprecated_set_gdbarch_data has been initialized, this can be
- changed to an internal error. */
- return NULL;
- gdb_assert (gdbarch->data[data->index] != NULL);
- }
- return gdbarch->data[data->index];
-}
-
-
-/* Keep a registry of the architectures known by GDB. */
-
-struct gdbarch_registration
-{
- enum bfd_architecture bfd_architecture;
- gdbarch_init_ftype *init;
- gdbarch_dump_tdep_ftype *dump_tdep;
- struct gdbarch_list *arches;
- struct gdbarch_registration *next;
-};
-
-static struct gdbarch_registration *gdbarch_registry = NULL;
-
-static void
-append_name (const char ***buf, int *nr, const char *name)
-{
- *buf = XRESIZEVEC (const char *, *buf, *nr + 1);
- (*buf)[*nr] = name;
- *nr += 1;
-}
-
-const char **
-gdbarch_printable_names (void)
-{
- /* Accumulate a list of names based on the registed list of
- architectures. */
- int nr_arches = 0;
- const char **arches = NULL;
- struct gdbarch_registration *rego;
-
- for (rego = gdbarch_registry;
- rego != NULL;
- rego = rego->next)
- {
- const struct bfd_arch_info *ap;
- ap = bfd_lookup_arch (rego->bfd_architecture, 0);
- if (ap == NULL)
- internal_error (__FILE__, __LINE__,
- _("gdbarch_architecture_names: multi-arch unknown"));
- do
- {
- append_name (&arches, &nr_arches, ap->printable_name);
- ap = ap->next;
- }
- while (ap != NULL);
- }
- append_name (&arches, &nr_arches, NULL);
- return arches;
-}
-
-
-void
-gdbarch_register (enum bfd_architecture bfd_architecture,
- gdbarch_init_ftype *init,
- gdbarch_dump_tdep_ftype *dump_tdep)
-{
- struct gdbarch_registration **curr;
- const struct bfd_arch_info *bfd_arch_info;
-
- /* Check that BFD recognizes this architecture */
- bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
- if (bfd_arch_info == NULL)
- {
- internal_error (__FILE__, __LINE__,
- _("gdbarch: Attempt to register "
- "unknown architecture (%d)"),
- bfd_architecture);
- }
- /* Check that we haven't seen this architecture before. */
- for (curr = &gdbarch_registry;
- (*curr) != NULL;
- curr = &(*curr)->next)
- {
- if (bfd_architecture == (*curr)->bfd_architecture)
- internal_error (__FILE__, __LINE__,
- _("gdbarch: Duplicate registration "
- "of architecture (%s)"),
- bfd_arch_info->printable_name);
- }
- /* log it */
- if (gdbarch_debug)
- fprintf_unfiltered (gdb_stdlog, "register_gdbarch_init (%s, %s)\n",
- bfd_arch_info->printable_name,
- host_address_to_string (init));
- /* Append it */
- (*curr) = XNEW (struct gdbarch_registration);
- (*curr)->bfd_architecture = bfd_architecture;
- (*curr)->init = init;
- (*curr)->dump_tdep = dump_tdep;
- (*curr)->arches = NULL;
- (*curr)->next = NULL;
-}
-
-void
-register_gdbarch_init (enum bfd_architecture bfd_architecture,
- gdbarch_init_ftype *init)
-{
- gdbarch_register (bfd_architecture, init, NULL);
-}
-
-
-/* Look for an architecture using gdbarch_info. */
-
-struct gdbarch_list *
-gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
- const struct gdbarch_info *info)
-{
- for (; arches != NULL; arches = arches->next)
- {
- if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
- continue;
- if (info->byte_order != arches->gdbarch->byte_order)
- continue;
- if (info->osabi != arches->gdbarch->osabi)
- continue;
- if (info->target_desc != arches->gdbarch->target_desc)
- continue;
- return arches;
- }
- return NULL;
-}
-
-
-/* Find an architecture that matches the specified INFO. Create a new
- architecture if needed. Return that new architecture. */
-
-struct gdbarch *
-gdbarch_find_by_info (struct gdbarch_info info)
-{
- struct gdbarch *new_gdbarch;
- struct gdbarch_registration *rego;
-
- /* Fill in missing parts of the INFO struct using a number of
- sources: "set ..."; INFOabfd supplied; and the global
- defaults. */
- gdbarch_info_fill (&info);
-
- /* Must have found some sort of architecture. */
- gdb_assert (info.bfd_arch_info != NULL);
-
- if (gdbarch_debug)
- {
- fprintf_unfiltered (gdb_stdlog,
- "gdbarch_find_by_info: info.bfd_arch_info %s\n",
- (info.bfd_arch_info != NULL
- ? info.bfd_arch_info->printable_name
- : "(null)"));
- fprintf_unfiltered (gdb_stdlog,
- "gdbarch_find_by_info: info.byte_order %d (%s)\n",
- info.byte_order,
- (info.byte_order == BFD_ENDIAN_BIG ? "big"
- : info.byte_order == BFD_ENDIAN_LITTLE ? "little"
- : "default"));
- fprintf_unfiltered (gdb_stdlog,
- "gdbarch_find_by_info: info.osabi %d (%s)\n",
- info.osabi, gdbarch_osabi_name (info.osabi));
- fprintf_unfiltered (gdb_stdlog,
- "gdbarch_find_by_info: info.abfd %s\n",
- host_address_to_string (info.abfd));
- fprintf_unfiltered (gdb_stdlog,
- "gdbarch_find_by_info: info.tdep_info %s\n",
- host_address_to_string (info.tdep_info));
- }
-
- /* Find the tdep code that knows about this architecture. */
- for (rego = gdbarch_registry;
- rego != NULL;
- rego = rego->next)
- if (rego->bfd_architecture == info.bfd_arch_info->arch)
- break;
- if (rego == NULL)
- {
- if (gdbarch_debug)
- fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
- "No matching architecture\n");
- return 0;
- }
-
- /* Ask the tdep code for an architecture that matches "info". */
- new_gdbarch = rego->init (info, rego->arches);
-
- /* Did the tdep code like it? No. Reject the change and revert to
- the old architecture. */
- if (new_gdbarch == NULL)
- {
- if (gdbarch_debug)
- fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
- "Target rejected architecture\n");
- return NULL;
- }
-
- /* Is this a pre-existing architecture (as determined by already
- being initialized)? Move it to the front of the architecture
- list (keeping the list sorted Most Recently Used). */
- if (new_gdbarch->initialized_p)
- {
- struct gdbarch_list **list;
- struct gdbarch_list *self;
- if (gdbarch_debug)
- fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
- "Previous architecture %s (%s) selected\n",
- host_address_to_string (new_gdbarch),
- new_gdbarch->bfd_arch_info->printable_name);
- /* Find the existing arch in the list. */
- for (list = ®o->arches;
- (*list) != NULL && (*list)->gdbarch != new_gdbarch;
- list = &(*list)->next);
- /* It had better be in the list of architectures. */
- gdb_assert ((*list) != NULL && (*list)->gdbarch == new_gdbarch);
- /* Unlink SELF. */
- self = (*list);
- (*list) = self->next;
- /* Insert SELF at the front. */
- self->next = rego->arches;
- rego->arches = self;
- /* Return it. */
- return new_gdbarch;
- }
-
- /* It's a new architecture. */
- if (gdbarch_debug)
- fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
- "New architecture %s (%s) selected\n",
- host_address_to_string (new_gdbarch),
- new_gdbarch->bfd_arch_info->printable_name);
-
- /* Insert the new architecture into the front of the architecture
- list (keep the list sorted Most Recently Used). */
- {
- struct gdbarch_list *self = XNEW (struct gdbarch_list);
- self->next = rego->arches;
- self->gdbarch = new_gdbarch;
- rego->arches = self;
- }
-
- /* Check that the newly installed architecture is valid. Plug in
- any post init values. */
- new_gdbarch->dump_tdep = rego->dump_tdep;
- verify_gdbarch (new_gdbarch);
- new_gdbarch->initialized_p = 1;
-
- if (gdbarch_debug)
- gdbarch_dump (new_gdbarch, gdb_stdlog);
-
- return new_gdbarch;
-}
-
-/* Make the specified architecture current. */
-
-void
-set_target_gdbarch (struct gdbarch *new_gdbarch)
-{
- gdb_assert (new_gdbarch != NULL);
- gdb_assert (new_gdbarch->initialized_p);
- current_inferior ()->gdbarch = new_gdbarch;
- observer_notify_architecture_changed (new_gdbarch);
- registers_changed ();
-}
-
-/* Return the current inferior's arch. */
-
-struct gdbarch *
-target_gdbarch (void)