diff options
author | Tom Tromey <tromey@adacore.com> | 2020-09-17 14:11:38 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-09-17 14:28:06 -0600 |
commit | c1e1314d00fda5625f1a87b915fd83a61c253993 (patch) | |
tree | 62affcd614124eec0c51db5223b0ea7f797a17d1 /gdb/riscv-tdep.c | |
parent | 0363df3db7d3f5edd3a349ab7720eca83f460545 (diff) | |
download | gdb-c1e1314d00fda5625f1a87b915fd83a61c253993.zip gdb-c1e1314d00fda5625f1a87b915fd83a61c253993.tar.gz gdb-c1e1314d00fda5625f1a87b915fd83a61c253993.tar.bz2 |
Change management of tdesc_arch_data
While working on something else, I noticed that tdesc_data_cleanup
took a void* parameter. Looking more into this, I found that
tdesc_use_registers expected a transfer of ownership.
I think it's better to express this sort of thing via the type system,
when possible. This patch changes tdesc_data_alloc to return a unique
pointer, changes tdesc_use_registers to accept an rvalue reference,
and then adapts all the users.
Note that a deleter structure is introduced to avoid having to move
tdesc_arch_data to the header file.
2020-09-17 Tom Tromey <tromey@adacore.com>
* tic6x-tdep.c (tic6x_gdbarch_init): Update.
* target-descriptions.h (struct tdesc_arch_data_deleter): New.
(tdesc_arch_data_up): New typedef.
(tdesc_use_registers, tdesc_data_alloc): Update.
(tdesc_data_cleanup): Don't declare.
* target-descriptions.c (tdesc_data_alloc): Return a
tdesc_arch_data_up.
(tdesc_arch_data_deleter::operator()): Rename from
tdesc_data_cleanup. Change argument type.
(tdesc_use_registers): Change early_data to an rvalue reference.
(tdesc_use_registers): Don't use delete.
* sparc-tdep.c (sparc32_gdbarch_init): Update.
* s390-tdep.c (s390_gdbarch_init): Update.
* rx-tdep.c (rx_gdbarch_init): Update.
* rs6000-tdep.c (rs6000_gdbarch_init): Update.
* riscv-tdep.c (riscv_gdbarch_init): Update.
* or1k-tdep.c (or1k_gdbarch_init): Update.
* nios2-tdep.c (nios2_gdbarch_init): Update.
* nds32-tdep.c (nds32_gdbarch_init): Update.
* mips-tdep.c (mips_gdbarch_init): Update.
* microblaze-tdep.c (microblaze_gdbarch_init): Update.
* m68k-tdep.c (m68k_gdbarch_init): Update.
* i386-tdep.c (i386_gdbarch_init): Update.
* arm-tdep.c (arm_gdbarch_init): Update.
* arc-tdep.c (arc_tdesc_init): Update.
(arc_gdbarch_init): Update.
* aarch64-tdep.c (aarch64_gdbarch_init): Update.
Diffstat (limited to 'gdb/riscv-tdep.c')
-rw-r--r-- | gdb/riscv-tdep.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index ac4ac1b..2c4eeab 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -3320,10 +3320,10 @@ riscv_gdbarch_init (struct gdbarch_info info, if (feature_cpu == NULL) return NULL; - struct tdesc_arch_data *tdesc_data = tdesc_data_alloc (); + tdesc_arch_data_up tdesc_data = tdesc_data_alloc (); std::vector<riscv_pending_register_alias> pending_aliases; - bool valid_p = riscv_check_tdesc_feature (tdesc_data, + bool valid_p = riscv_check_tdesc_feature (tdesc_data.get (), feature_cpu, feature_csr, &riscv_xreg_feature, &pending_aliases); @@ -3345,7 +3345,7 @@ riscv_gdbarch_init (struct gdbarch_info info, if (feature_fpu != NULL) { - valid_p &= riscv_check_tdesc_feature (tdesc_data, feature_fpu, + valid_p &= riscv_check_tdesc_feature (tdesc_data.get (), feature_fpu, feature_csr, &riscv_freg_feature, &pending_aliases); @@ -3383,12 +3383,12 @@ riscv_gdbarch_init (struct gdbarch_info info, } if (feature_virtual) - riscv_check_tdesc_feature (tdesc_data, feature_virtual, feature_csr, + riscv_check_tdesc_feature (tdesc_data.get (), feature_virtual, feature_csr, &riscv_virtual_feature, &pending_aliases); if (feature_csr) - riscv_check_tdesc_feature (tdesc_data, feature_csr, nullptr, + riscv_check_tdesc_feature (tdesc_data.get (), feature_csr, nullptr, &riscv_csr_feature, &pending_aliases); @@ -3396,7 +3396,6 @@ riscv_gdbarch_init (struct gdbarch_info info, { if (riscv_debug_gdbarch) fprintf_unfiltered (gdb_stdlog, "Target description is not valid\n"); - tdesc_data_cleanup (tdesc_data); return NULL; } @@ -3442,10 +3441,7 @@ riscv_gdbarch_init (struct gdbarch_info info, } if (arches != NULL) - { - tdesc_data_cleanup (tdesc_data); - return arches->gdbarch; - } + return arches->gdbarch; /* None found, so create a new architecture from the information provided. */ tdep = new (struct gdbarch_tdep); @@ -3511,7 +3507,8 @@ riscv_gdbarch_init (struct gdbarch_info info, set_gdbarch_print_registers_info (gdbarch, riscv_print_registers_info); /* Finalise the target description registers. */ - tdesc_use_registers (gdbarch, tdesc, tdesc_data, riscv_tdesc_unknown_reg); + tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data), + riscv_tdesc_unknown_reg); /* Override the register type callback setup by the target description mechanism. This allows us to provide special type for floating point |