diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-11-15 11:29:39 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-11-15 11:29:39 -0500 |
commit | 345bd07cce33565f1cd66acabdaf387ca3a7ccb3 (patch) | |
tree | bfa86d2102817e06235193c865d2580e802d0a1a /gdb/cris-tdep.c | |
parent | eae06bb301512a21277dd48a4bff025c4dceda9e (diff) | |
download | fsf-binutils-gdb-345bd07cce33565f1cd66acabdaf387ca3a7ccb3.zip fsf-binutils-gdb-345bd07cce33565f1cd66acabdaf387ca3a7ccb3.tar.gz fsf-binutils-gdb-345bd07cce33565f1cd66acabdaf387ca3a7ccb3.tar.bz2 |
gdb: fix gdbarch_tdep ODR violation
I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.
To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class. The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.
These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor. In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object). But that's not necessary right now.
It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.
Most changes are fairly straightforward, mostly needing to add some
casts all over the place. There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep. I did my
best to adapt it, but I can't test those changes.
Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b
Diffstat (limited to 'gdb/cris-tdep.c')
-rw-r--r-- | gdb/cris-tdep.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c index 6b5dfc3..691cad8 100644 --- a/gdb/cris-tdep.c +++ b/gdb/cris-tdep.c @@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame, void **this_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct cris_unwind_cache *info; CORE_ADDR addr; @@ -450,7 +450,7 @@ static int crisv32_single_step_through_delay (struct gdbarch *gdbarch, struct frame_info *this_frame) { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); ULONGEST erp; int ret = 0; @@ -695,7 +695,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame, void **this_prologue_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); struct cris_unwind_cache *info; if ((*this_prologue_cache)) @@ -1333,7 +1333,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame, static CORE_ADDR cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); CORE_ADDR func_addr, func_end; struct symtab_and_line sal; CORE_ADDR pc_after_prologue; @@ -1368,7 +1368,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) static const gdb_byte * cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); static unsigned char break8_insn[] = {0x38, 0xe9}; static unsigned char break15_insn[] = {0x3f, 0xe9}; @@ -1387,7 +1387,7 @@ static int cris_spec_reg_applicable (struct gdbarch *gdbarch, struct cris_spec_reg spec_reg) { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); unsigned int version = tdep->cris_version; switch (spec_reg.applicable_version) @@ -3766,7 +3766,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len) { struct gdbarch *gdbarch = regcache->arch (); - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); int i; const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs); @@ -3860,7 +3860,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."), static void cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch); if (tdep != NULL) { fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n", @@ -3914,7 +3914,6 @@ static struct gdbarch * cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { struct gdbarch *gdbarch; - struct gdbarch_tdep *tdep; unsigned int cris_version; if (usr_cmd_cris_version_valid) @@ -3940,17 +3939,17 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) arches != NULL; arches = gdbarch_list_lookup_by_info (arches->next, &info)) { - if ((gdbarch_tdep (arches->gdbarch)->cris_version - == usr_cmd_cris_version) - && (gdbarch_tdep (arches->gdbarch)->cris_mode - == usr_cmd_cris_mode) - && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi - == usr_cmd_cris_dwarf2_cfi)) + cris_gdbarch_tdep *tdep + = (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch); + + if (tdep->cris_version == usr_cmd_cris_version + && tdep->cris_mode == usr_cmd_cris_mode + && tdep->cris_dwarf2_cfi == usr_cmd_cris_dwarf2_cfi) return arches->gdbarch; } /* No matching architecture was found. Create a new one. */ - tdep = XCNEW (struct gdbarch_tdep); + cris_gdbarch_tdep *tdep = new cris_gdbarch_tdep; info.byte_order = BFD_ENDIAN_LITTLE; gdbarch = gdbarch_alloc (&info, tdep); |