gdb: make gdbarch_alloc take ownership of the tdep

It's currently not clear how the ownership of gdbarch_tdep objects
works.  In fact, nothing ever takes ownership of it.  This is mostly
fine because we never free gdbarch objects, and thus we never free
gdbarch_tdep objects.  There is an exception to that however: when
initialization fails, we do free the gdbarch object that is not going to
be used, and we free the tdep too.  Currently, i386 and s390 do it.

To make things clearer, change gdbarch_alloc so that it takes ownership
of the tdep.  The tdep is thus automatically freed if the gdbarch is
freed.

Change all gdbarch initialization functions to pass a new gdbarch_tdep
object to gdbarch_alloc and then retrieve a non-owning reference from
the gdbarch object.

Before this patch, the xtensa architecture had a single global instance
of xtensa_gdbarch_tdep.  Since we need to pass a dynamically allocated
gdbarch_tdep_base instance to gdbarch_alloc, remove this global
instance, and dynamically allocate one as needed, like we do for all
other architectures.  Make the `rmap` array externally visible and
rename it to the less collision-prone `xtensa_rmap` name.

Change-Id: Id3d70493ef80ce4bdff701c57636f4c79ed8aea2
Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Simon Marchi 2022-10-03 11:15:14 -04:00
parent cabd67874a
commit 2b16913cdc
46 changed files with 148 additions and 149 deletions

View file

@ -2587,7 +2587,6 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
static struct gdbarch *
m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
struct gdbarch *gdbarch;
unsigned long mach = info.bfd_arch_info->mach;
/* Find a candidate among the list of architectures we've created
@ -2597,8 +2596,8 @@ m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
arches = gdbarch_list_lookup_by_info (arches->next, &info))
return arches->gdbarch;
m32c_gdbarch_tdep *tdep = new m32c_gdbarch_tdep;
gdbarch = gdbarch_alloc (&info, tdep);
gdbarch *gdbarch
= gdbarch_alloc (&info, gdbarch_tdep_up (new m32c_gdbarch_tdep));
/* Essential types. */
make_types (gdbarch);