diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2022-10-03 11:15:14 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2023-01-05 14:38:51 -0500 |
commit | 2b16913cdca20ae1dafdbd816b025a6efdc6c06f (patch) | |
tree | e1b7e91c6e5f57f605ea37cf868f4987eedf078e /gdb/s390-tdep.c | |
parent | cabd67874a6ef7aaed41490d9eaddc4a4869a452 (diff) | |
download | gdb-2b16913cdca20ae1dafdbd816b025a6efdc6c06f.zip gdb-2b16913cdca20ae1dafdbd816b025a6efdc6c06f.tar.gz gdb-2b16913cdca20ae1dafdbd816b025a6efdc6c06f.tar.bz2 |
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>
Diffstat (limited to 'gdb/s390-tdep.c')
-rw-r--r-- | gdb/s390-tdep.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index 7716525..1793399 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -6983,13 +6983,12 @@ s390_tdesc_valid (s390_gdbarch_tdep *tdep, return true; } -/* Allocate and initialize new gdbarch_tdep. Caller is responsible to free - memory after use. */ +/* Allocate and initialize new gdbarch_tdep. */ -static s390_gdbarch_tdep * +static s390_gdbarch_tdep_up s390_gdbarch_tdep_alloc () { - s390_gdbarch_tdep *tdep = new s390_gdbarch_tdep; + s390_gdbarch_tdep_up tdep (new s390_gdbarch_tdep); tdep->tdesc = NULL; @@ -7026,8 +7025,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) static const char *const stap_register_indirection_suffixes[] = { ")", NULL }; - s390_gdbarch_tdep *tdep = s390_gdbarch_tdep_alloc (); - struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep); + gdbarch *gdbarch = gdbarch_alloc (&info, s390_gdbarch_tdep_alloc ()); + s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch); tdesc_arch_data_up tdesc_data = tdesc_data_alloc (); info.tdesc_data = tdesc_data.get (); @@ -7156,7 +7155,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* Check any target description for validity. */ if (!s390_tdesc_valid (tdep, tdesc_data.get ())) { - delete tdep; gdbarch_free (gdbarch); return NULL; } @@ -7189,7 +7187,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (tmp->vector_abi != tdep->vector_abi) continue; - delete tdep; gdbarch_free (gdbarch); return arches->gdbarch; } |