aboutsummaryrefslogtreecommitdiff
path: root/gdb/frv-tdep.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-10-03 11:15:14 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2023-01-05 14:38:51 -0500
commit2b16913cdca20ae1dafdbd816b025a6efdc6c06f (patch)
treee1b7e91c6e5f57f605ea37cf868f4987eedf078e /gdb/frv-tdep.c
parentcabd67874a6ef7aaed41490d9eaddc4a4869a452 (diff)
downloadgdb-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/frv-tdep.c')
-rw-r--r--gdb/frv-tdep.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 5e9f203..1a709b9 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -89,6 +89,8 @@ struct frv_gdbarch_tdep : gdbarch_tdep_base
const char **register_names = nullptr;
};
+using frv_gdbarch_tdep_up = std::unique_ptr<frv_gdbarch_tdep>;
+
/* Return the FR-V ABI associated with GDBARCH. */
enum frv_abi
frv_abi (struct gdbarch *gdbarch)
@@ -130,12 +132,12 @@ frv_fdpic_loadmap_addresses (struct gdbarch *gdbarch, CORE_ADDR *interp_addr,
/* Allocate a new variant structure, and set up default values for all
the fields. */
-static frv_gdbarch_tdep *
-new_variant (void)
+static frv_gdbarch_tdep_up
+new_variant ()
{
int r;
- frv_gdbarch_tdep *var = new frv_gdbarch_tdep;
+ frv_gdbarch_tdep_up var (new frv_gdbarch_tdep);
var->frv_abi = FRV_ABI_EABI;
var->num_gprs = 64;
@@ -1427,7 +1429,6 @@ static const struct frame_base frv_frame_base = {
static struct gdbarch *
frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
- struct gdbarch *gdbarch;
int elf_flags = 0;
/* Check to see if we've already built an appropriate architecture
@@ -1437,7 +1438,9 @@ frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
return arches->gdbarch;
/* Select the right tdep structure for this variant. */
- frv_gdbarch_tdep *var = new_variant ();
+ gdbarch *gdbarch = gdbarch_alloc (&info, new_variant ());
+ frv_gdbarch_tdep *var = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
+
switch (info.bfd_arch_info->mach)
{
case bfd_mach_frv:
@@ -1471,8 +1474,6 @@ frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
if (elf_flags & EF_FRV_CPU_FR450)
set_variant_scratch_registers (var);
- gdbarch = gdbarch_alloc (&info, var);
-
set_gdbarch_short_bit (gdbarch, 16);
set_gdbarch_int_bit (gdbarch, 32);
set_gdbarch_long_bit (gdbarch, 32);