aboutsummaryrefslogtreecommitdiff
path: root/gdb/m68hc11-tdep.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-11-15 11:29:39 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2021-11-15 11:29:39 -0500
commit345bd07cce33565f1cd66acabdaf387ca3a7ccb3 (patch)
treebfa86d2102817e06235193c865d2580e802d0a1a /gdb/m68hc11-tdep.c
parenteae06bb301512a21277dd48a4bff025c4dceda9e (diff)
downloadgdb-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/m68hc11-tdep.c')
-rw-r--r--gdb/m68hc11-tdep.c60
1 files changed, 41 insertions, 19 deletions
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index bbf7e5d..6d41fe8 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -123,27 +123,38 @@ enum insn_return_kind {
#define M68HC12_HARD_PC_REGNUM (SOFT_D32_REGNUM+1)
struct insn_sequence;
-struct gdbarch_tdep
+struct m68gc11_gdbarch_tdep : gdbarch_tdep
{
/* Stack pointer correction value. For 68hc11, the stack pointer points
to the next push location. An offset of 1 must be applied to obtain
the address where the last value is saved. For 68hc12, the stack
pointer points to the last value pushed. No offset is necessary. */
- int stack_correction;
+ int stack_correction = 0;
/* Description of instructions in the prologue. */
- struct insn_sequence *prologue;
+ struct insn_sequence *prologue = nullptr;
/* True if the page memory bank register is available
and must be used. */
- int use_page_register;
+ int use_page_register = 0;
/* ELF flags for ABI. */
- int elf_flags;
+ int elf_flags = 0;
};
-#define STACK_CORRECTION(gdbarch) (gdbarch_tdep (gdbarch)->stack_correction)
-#define USE_PAGE_REGISTER(gdbarch) (gdbarch_tdep (gdbarch)->use_page_register)
+static int
+stack_correction (gdbarch *arch)
+{
+ m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+ return tdep->stack_correction;
+}
+
+static int
+use_page_register (gdbarch *arch)
+{
+ m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+ return tdep->stack_correction;
+}
struct m68hc11_unwind_cache
{
@@ -371,13 +382,15 @@ m68hc11_pseudo_register_write (struct gdbarch *gdbarch,
static const char *
m68hc11_register_name (struct gdbarch *gdbarch, int reg_nr)
{
- if (reg_nr == M68HC12_HARD_PC_REGNUM && USE_PAGE_REGISTER (gdbarch))
+ if (reg_nr == M68HC12_HARD_PC_REGNUM && use_page_register (gdbarch))
return "pc";
- if (reg_nr == HARD_PC_REGNUM && USE_PAGE_REGISTER (gdbarch))
+
+ if (reg_nr == HARD_PC_REGNUM && use_page_register (gdbarch))
return "ppc";
if (reg_nr < 0)
return NULL;
+
if (reg_nr >= M68HC11_ALL_REGS)
return NULL;
@@ -387,6 +400,7 @@ m68hc11_register_name (struct gdbarch *gdbarch, int reg_nr)
does not exist. */
if (reg_nr > M68HC11_LAST_HARD_REG && soft_regs[reg_nr].name == 0)
return NULL;
+
return m68hc11_register_names[reg_nr];
}
@@ -627,7 +641,8 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
return pc;
}
- seq_table = gdbarch_tdep (gdbarch)->prologue;
+ m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+ seq_table = tdep->prologue;
/* The 68hc11 stack is as follows:
@@ -807,7 +822,7 @@ m68hc11_frame_unwind_cache (struct frame_info *this_frame,
info->saved_regs[HARD_PC_REGNUM].set_addr (info->sp_offset);
this_base = get_frame_register_unsigned (this_frame, HARD_SP_REGNUM);
prev_sp = this_base + info->sp_offset + 2;
- this_base += STACK_CORRECTION (gdbarch);
+ this_base += stack_correction (gdbarch);
}
else
{
@@ -815,7 +830,7 @@ m68hc11_frame_unwind_cache (struct frame_info *this_frame,
to before the first saved register giving the SP. */
prev_sp = this_base + info->size + 2;
- this_base += STACK_CORRECTION (gdbarch);
+ this_base += stack_correction (gdbarch);
if (soft_regs[SOFT_FP_REGNUM].name)
info->saved_regs[SOFT_FP_REGNUM].set_addr (info->size - 2);
}
@@ -898,7 +913,7 @@ m68hc11_frame_prev_register (struct frame_info *this_frame,
/* Take into account the 68HC12 specific call (PC + page). */
if (regnum == HARD_PC_REGNUM
&& info->return_kind == RETURN_RTC
- && USE_PAGE_REGISTER (get_frame_arch (this_frame)))
+ && use_page_register (get_frame_arch (this_frame)))
{
CORE_ADDR pc = value_as_long (value);
if (pc >= 0x08000 && pc < 0x0c000)
@@ -1003,7 +1018,10 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
}
else
{
- if (regno == HARD_PC_REGNUM && gdbarch_tdep (gdbarch)->use_page_register)
+ m68gc11_gdbarch_tdep *tdep
+ = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
+ if (regno == HARD_PC_REGNUM && tdep->use_page_register)
{
ULONGEST page;
@@ -1106,7 +1124,9 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
fprintf_filtered (file, " Y=");
m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
- if (gdbarch_tdep (gdbarch)->use_page_register)
+ m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
+ if (tdep->use_page_register)
{
fprintf_filtered (file, "\nPage=");
m68hc11_print_register (gdbarch, file, frame, HARD_PAGE_REGNUM);
@@ -1194,7 +1214,7 @@ m68hc11_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
write_memory (sp, buf, 2);
/* Finally, update the stack pointer... */
- sp -= STACK_CORRECTION (gdbarch);
+ sp -= stack_correction (gdbarch);
regcache_cooked_write_unsigned (regcache, HARD_SP_REGNUM, sp);
/* ...and fake a frame pointer. */
@@ -1386,7 +1406,6 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
struct gdbarch_list *arches)
{
struct gdbarch *gdbarch;
- struct gdbarch_tdep *tdep;
int elf_flags;
soft_reg_initialized = 0;
@@ -1403,14 +1422,17 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
arches != NULL;
arches = gdbarch_list_lookup_by_info (arches->next, &info))
{
- if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
+ m68gc11_gdbarch_tdep *tdep
+ = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+
+ if (tdep->elf_flags != elf_flags)
continue;
return arches->gdbarch;
}
/* Need a new architecture. Fill in a target specific vector. */
- tdep = XCNEW (struct gdbarch_tdep);
+ m68gc11_gdbarch_tdep *tdep = new m68gc11_gdbarch_tdep;
gdbarch = gdbarch_alloc (&info, tdep);
tdep->elf_flags = elf_flags;