From 2b16913cdca20ae1dafdbd816b025a6efdc6c06f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 3 Oct 2022 11:15:14 -0400 Subject: 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 --- gdb/v850-tdep.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gdb/v850-tdep.c') diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c index 66a1e6d..cc7da90 100644 --- a/gdb/v850-tdep.c +++ b/gdb/v850-tdep.c @@ -1348,7 +1348,6 @@ static const struct frame_base v850_frame_base = { static struct gdbarch * v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { - struct gdbarch *gdbarch; int e_flags, e_machine; /* Extract the elf_flags if available. */ @@ -1380,7 +1379,10 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) return arches->gdbarch; } - v850_gdbarch_tdep *tdep = new v850_gdbarch_tdep; + gdbarch *gdbarch + = gdbarch_alloc (&info, gdbarch_tdep_up (new v850_gdbarch_tdep)); + v850_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + tdep->e_flags = e_flags; tdep->e_machine = e_machine; @@ -1395,7 +1397,6 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) } tdep->eight_byte_align = (tdep->e_flags & EF_RH850_DATA_ALIGN8) ? 1 : 0; - gdbarch = gdbarch_alloc (&info, tdep); switch (info.bfd_arch_info->mach) { -- cgit v1.1