aboutsummaryrefslogtreecommitdiff
path: root/gdb/m68k-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/m68k-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/m68k-tdep.c')
-rw-r--r--gdb/m68k-tdep.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 75fa189..4ae27e6 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
static struct type *
m68k_ps_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (!tdep->m68k_ps_type)
{
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
static struct type *
m68881_ext_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (!tdep->m68881_ext_type)
tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
static struct type *
m68k_register_type (struct gdbarch *gdbarch, int regnum)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (tdep->fpregs_present)
{
@@ -171,12 +171,14 @@ static const char * const m68k_register_names[] = {
static const char *
m68k_register_name (struct gdbarch *gdbarch, int regnum)
{
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
internal_error (__FILE__, __LINE__,
_("m68k_register_name: illegal register number %d"),
regnum);
else if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
- && gdbarch_tdep (gdbarch)->fpregs_present == 0)
+ && tdep->fpregs_present == 0)
return "";
else
return m68k_register_names[regnum];
@@ -189,7 +191,9 @@ static int
m68k_convert_register_p (struct gdbarch *gdbarch,
int regnum, struct type *type)
{
- if (!gdbarch_tdep (gdbarch)->fpregs_present)
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
+ if (!tdep->fpregs_present)
return 0;
return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
/* We only support floating-point values. */
@@ -296,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
if (type->code () == TYPE_CODE_PTR && len == 4)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
regcache->raw_read (tdep->pointer_result_regnum, valbuf);
}
else if (len <= 4)
@@ -321,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
{
gdb_byte buf[M68K_MAX_REGISTER_SIZE];
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (tdep->float_return && type->code () == TYPE_CODE_FLT)
{
@@ -344,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
if (type->code () == TYPE_CODE_PTR && len == 4)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
regcache->raw_write (tdep->pointer_result_regnum, valbuf);
/* gdb historically also set D0 in the SVR4 case. */
if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -367,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
const gdb_byte *valbuf)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (tdep->float_return && type->code () == TYPE_CODE_FLT)
{
@@ -387,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
static int
m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum type_code code = type->code ();
int len = TYPE_LENGTH (type);
@@ -465,6 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = type->code ();
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
/* Aggregates with a single member are always returned like their
sole element. */
@@ -480,7 +485,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
|| code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
&& !m68k_reg_struct_return_p (gdbarch, type))
/* GCC may return a `long double' in memory too. */
- || (!gdbarch_tdep (gdbarch)->float_return
+ || (!tdep->float_return
&& code == TYPE_CODE_FLT
&& TYPE_LENGTH (type) == 12))
{
@@ -500,7 +505,6 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
if (readbuf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
ULONGEST addr;
regcache_raw_read_unsigned (regcache, tdep->pointer_result_regnum,
@@ -537,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
function_call_return_method return_method,
CORE_ADDR struct_addr)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
gdb_byte buf[4];
int i;
@@ -592,13 +596,15 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
static int
m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
{
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+
if (num < 8)
/* d0..7 */
return (num - 0) + M68K_D0_REGNUM;
else if (num < 16)
/* a0..7 */
return (num - 8) + M68K_A0_REGNUM;
- else if (num < 24 && gdbarch_tdep (gdbarch)->fpregs_present)
+ else if (num < 24 && tdep->fpregs_present)
/* fp0..7 */
return (num - 16) + M68K_FP0_REGNUM;
else if (num == 25)
@@ -760,6 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
struct m68k_frame_cache *cache)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (cache->locals >= 0)
{
@@ -772,7 +779,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
{
op = read_memory_unsigned_integer (pc, 2, byte_order);
if (op == P_FMOVEMX_SP
- && gdbarch_tdep (gdbarch)->fpregs_present)
+ && tdep->fpregs_present)
{
/* fmovem.x REGS,-(%sp) */
op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
@@ -1051,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
gdb_byte *buf;
CORE_ADDR sp, jb_addr;
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
if (tdep->jb_pc < 0)
@@ -1097,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
void
m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
/* SVR4 uses a different calling convention. */
set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1115,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
static void
m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
m68k_svr4_init_abi (info, gdbarch);
tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1130,7 +1137,6 @@ m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
static struct gdbarch *
m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
- struct gdbarch_tdep *tdep = NULL;
struct gdbarch *gdbarch;
struct gdbarch_list *best_arch;
tdesc_arch_data_up tdesc_data;
@@ -1230,13 +1236,16 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
best_arch != NULL;
best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
{
- if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
+ m68k_gdbarch_tdep *tdep
+ = (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+
+ if (flavour != tdep->flavour)
continue;
- if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
+ if (has_fp != tdep->fpregs_present)
continue;
- if (float_return != gdbarch_tdep (best_arch->gdbarch)->float_return)
+ if (float_return != tdep->float_return)
continue;
break;
@@ -1245,7 +1254,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
if (best_arch != NULL)
return best_arch->gdbarch;
- tdep = XCNEW (struct gdbarch_tdep);
+ m68k_gdbarch_tdep *tdep = new m68k_gdbarch_tdep;
gdbarch = gdbarch_alloc (&info, tdep);
tdep->fpregs_present = has_fp;
tdep->float_return = float_return;
@@ -1330,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
static void
m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (tdep == NULL)
return;