aboutsummaryrefslogtreecommitdiff
path: root/gdb/sparc-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/sparc-tdep.c
parenteae06bb301512a21277dd48a4bff025c4dceda9e (diff)
downloadfsf-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/sparc-tdep.c')
-rw-r--r--gdb/sparc-tdep.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 7302929..31916b6 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -429,7 +429,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
static struct type *
sparc_psr_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (!tdep->sparc_psr_type)
{
@@ -451,7 +451,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
static struct type *
sparc_fsr_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (!tdep->sparc_fsr_type)
{
@@ -992,7 +992,7 @@ CORE_ADDR
sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
CORE_ADDR current_pc, struct sparc_frame_cache *cache)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
unsigned long insn;
int offset = 0;
int dest = -1;
@@ -1684,8 +1684,9 @@ sparc_analyze_control_transfer (struct regcache *regcache,
struct frame_info *frame = get_current_frame ();
/* Trap instruction (TRAP). */
- return gdbarch_tdep (regcache->arch ())->step_trap (frame,
- insn);
+ gdbarch *arch = regcache->arch ();
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+ return tdep->step_trap (frame, insn);
}
/* FIXME: Handle DONE and RETRY instructions. */
@@ -1735,7 +1736,7 @@ static std::vector<CORE_ADDR>
sparc_software_single_step (struct regcache *regcache)
{
struct gdbarch *arch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
CORE_ADDR npc, nnpc;
CORE_ADDR pc, orig_npc;
@@ -1764,7 +1765,8 @@ sparc_software_single_step (struct regcache *regcache)
static void
sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (regcache->arch ());
+ gdbarch *arch = regcache->arch ();
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1779,7 +1781,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
void *cb_data,
const struct regcache *regcache)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
cb_data);
@@ -1814,7 +1816,6 @@ validate_tdesc_registers (const struct target_desc *tdesc,
static struct gdbarch *
sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
- struct gdbarch_tdep *tdep;
const struct target_desc *tdesc = info.target_desc;
struct gdbarch *gdbarch;
int valid_p = 1;
@@ -1825,7 +1826,7 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
return arches->gdbarch;
/* Allocate space for the new architecture. */
- tdep = XCNEW (struct gdbarch_tdep);
+ sparc_gdbarch_tdep *tdep = new sparc_gdbarch_tdep;
gdbarch = gdbarch_alloc (&info, tdep);
tdep->pc_regnum = SPARC32_PC_REGNUM;