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/z80-tdep.c | |
parent | eae06bb301512a21277dd48a4bff025c4dceda9e (diff) | |
download | gdb-345bd07cce33565f1cd66acabdaf387ca3a7ccb3.zip gdb-345bd07cce33565f1cd66acabdaf387ca3a7ccb3.tar.gz 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/z80-tdep.c')
-rw-r--r-- | gdb/z80-tdep.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c index 7b9a7e2..9d453cd 100644 --- a/gdb/z80-tdep.c +++ b/gdb/z80-tdep.c @@ -54,19 +54,21 @@ __gdb_break_handler: next frame - frame of caller, which has called current function */ -struct gdbarch_tdep +struct z80_gdbarch_tdep : gdbarch_tdep { /* Number of bytes used for address: 2 bytes for all Z80 family 3 bytes for eZ80 CPUs operating in ADL mode */ - int addr_length; + int addr_length = 0; /* Type for void. */ - struct type *void_type; + struct type *void_type = nullptr; + /* Type for a function returning void. */ - struct type *func_void_type; + struct type *func_void_type = nullptr; + /* Type for a pointer to a function. Used for the type of PC. */ - struct type *pc_type; + struct type *pc_type = nullptr; }; /* At any time stack frame contains following parts: @@ -305,7 +307,8 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end, struct z80_unwind_cache *info) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - int addr_len = gdbarch_tdep (gdbarch)->addr_length; + z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch); + int addr_len = tdep->addr_length; gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */ int pos = 0; int len; @@ -560,7 +563,8 @@ z80_frame_unwind_cache (struct frame_info *this_frame, gdb_byte buf[sizeof(void*)]; struct z80_unwind_cache *info; struct gdbarch *gdbarch = get_frame_arch (this_frame); - int addr_len = gdbarch_tdep (gdbarch)->addr_length; + z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch); + int addr_len = tdep->addr_length; if (*this_prologue_cache) return (struct z80_unwind_cache *) *this_prologue_cache; @@ -692,7 +696,7 @@ z80_frame_prev_register (struct frame_info *this_frame, ULONGEST pc; gdb_byte buf[3]; struct gdbarch *gdbarch = get_frame_arch (this_frame); - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); read_memory (info->saved_regs[Z80_PC_REGNUM].addr (), @@ -745,11 +749,12 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) } else /* kind is non-RST address, use CALL instead, but it is dungerous */ { + z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch); gdb_byte *p = break_insn; *p++ = 0xcd; *p++ = (kind >> 0) & 0xff; *p++ = (kind >> 8) & 0xff; - if (gdbarch_tdep (gdbarch)->addr_length > 2) + if (tdep->addr_length > 2) *p++ = (kind >> 16) & 0xff; *size = p - break_insn; } @@ -1077,7 +1082,6 @@ static struct gdbarch * z80_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { struct gdbarch *gdbarch; - struct gdbarch_tdep *tdep; struct gdbarch_list *best_arch; tdesc_arch_data_up tdesc_data; unsigned long mach = info.bfd_arch_info->mach; @@ -1119,7 +1123,7 @@ z80_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) } /* None found, create a new architecture from the information provided. */ - tdep = XCNEW (struct gdbarch_tdep); + z80_gdbarch_tdep *tdep = new z80_gdbarch_tdep; gdbarch = gdbarch_alloc (&info, tdep); if (mach == bfd_mach_ez80_adl) |