/* Renesas M32C target-dependent code for GDB, the GNU debugger.
- Copyright (C) 2004-2021 Free Software Foundation, Inc.
+ Copyright (C) 2004-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "reggroups.h"
#include "prologue-value.h"
#include "objfiles.h"
+#include "gdbarch.h"
\f
/* The m32c tdep structure. */
#define M32C_MAX_DWARF_REGNUM (40)
-struct gdbarch_tdep
+struct m32c_gdbarch_tdep : gdbarch_tdep
{
/* All the registers for this variant, indexed by GDB register
number, and the number of registers present. */
- struct m32c_reg regs[M32C_MAX_NUM_REGS];
+ struct m32c_reg regs[M32C_MAX_NUM_REGS] {};
/* The number of valid registers. */
- int num_regs;
+ int num_regs = 0;
/* Interesting registers. These are pointers into REGS. */
- struct m32c_reg *pc, *flg;
- struct m32c_reg *r0, *r1, *r2, *r3, *a0, *a1;
- struct m32c_reg *r2r0, *r3r2r1r0, *r3r1r2r0;
- struct m32c_reg *sb, *fb, *sp;
+ struct m32c_reg *pc = nullptr, *flg = nullptr;
+ struct m32c_reg *r0 = nullptr, *r1 = nullptr, *r2 = nullptr, *r3 = nullptr,
+ *a0 = nullptr, *a1 = nullptr;
+ struct m32c_reg *r2r0 = nullptr, *r3r2r1r0 = nullptr, *r3r1r2r0 = nullptr;
+ struct m32c_reg *sb = nullptr, *fb = nullptr, *sp = nullptr;
/* A table indexed by DWARF register numbers, pointing into
REGS. */
- struct m32c_reg *dwarf_regs[M32C_MAX_DWARF_REGNUM + 1];
+ struct m32c_reg *dwarf_regs[M32C_MAX_DWARF_REGNUM + 1] {};
/* Types for this architecture. We can't use the builtin_type_foo
types, because they're not initialized when building a gdbarch
structure. */
- struct type *voyd, *ptr_voyd, *func_voyd;
- struct type *uint8, *uint16;
- struct type *int8, *int16, *int32, *int64;
+ struct type *voyd = nullptr, *ptr_voyd = nullptr, *func_voyd = nullptr;
+ struct type *uint8 = nullptr, *uint16 = nullptr;
+ struct type *int8 = nullptr, *int16 = nullptr, *int32 = nullptr,
+ *int64 = nullptr;
/* The types for data address and code address registers. */
- struct type *data_addr_reg_type, *code_addr_reg_type;
+ struct type *data_addr_reg_type = nullptr, *code_addr_reg_type = nullptr;
/* The number of bytes a return address pushed by a 'jsr' instruction
occupies on the stack. */
- int ret_addr_bytes;
+ int ret_addr_bytes = 0;
/* The number of bytes an address register occupies on the stack
when saved by an 'enter' or 'pushm' instruction. */
- int push_addr_bytes;
+ int push_addr_bytes = 0;
};
\f
static void
make_types (struct gdbarch *arch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
int data_addr_reg_bits, code_addr_reg_bits;
char type_name[50];
static const char *
m32c_register_name (struct gdbarch *gdbarch, int num)
{
- return gdbarch_tdep (gdbarch)->regs[num].name;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+ return tdep->regs[num].name;
}
static struct type *
m32c_register_type (struct gdbarch *arch, int reg_nr)
{
- return gdbarch_tdep (arch)->regs[reg_nr].type;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+ return tdep->regs[reg_nr].type;
}
static int
m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
{
- return gdbarch_tdep (gdbarch)->regs[reg_nr].sim_num;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+ return tdep->regs[reg_nr].sim_num;
}
static int
m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
&& tdep->dwarf_regs[reg_nr])
return tdep->dwarf_regs[reg_nr]->num;
m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
struct reggroup *group)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
struct m32c_reg *reg = &tdep->regs[regnum];
/* The anonymous raw registers aren't in any groups. */
static int
m32c_read_flg (readable_regcache *cache)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (cache->arch ());
+ gdbarch *arch = cache->arch ();
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
ULONGEST flg;
cache->raw_read (tdep->flg->num, &flg);
static enum register_status
m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (reg->arch);
+ gdbarch *arch = reg->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
int len = TYPE_LENGTH (tdep->r0->type);
enum register_status status;
m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
const gdb_byte *buf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (reg->arch);
+ gdbarch *arch = reg->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
int len = TYPE_LENGTH (tdep->r0->type);
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
int cookednum,
gdb_byte *buf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
struct m32c_reg *reg;
gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
int cookednum,
const gdb_byte *buf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
struct m32c_reg *reg;
gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
struct m32c_reg *ry,
int n)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
struct m32c_reg *r = &tdep->regs[tdep->num_regs];
gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
reg->dwarf_num = num;
/* Update the DWARF->reg mapping. */
- gdbarch_tdep (reg->arch)->dwarf_regs[num] = reg;
+ gdbarch *arch = reg->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+ tdep->dwarf_regs[num] = reg;
}
static void
make_regs (struct gdbarch *arch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
int mach = gdbarch_bfd_arch_info (arch)->mach;
int num_raw_regs;
int num_cooked_regs;
static int
m32c_pv_enter (struct m32c_pv_state *state, int size)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (state->arch);
-
/* If simulating this store would require us to forget
everything we know about the stack frame in the name of
accuracy, it would be better to just quit now. */
if (state->stack->store_would_trash (state->sp))
return 1;
+ gdbarch *arch = state->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
return 1;
+
state->fb = state->sp;
state->sp = pv_add_constant (state->sp, -size);
static int
m32c_pv_pushm (struct m32c_pv_state *state, int src)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (state->arch);
+ gdbarch *arch = state->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
/* The bits in SRC indicating which registers to save are:
r0 r1 r2 r3 a0 a1 sb fb */
static int
m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (state->arch);
+ gdbarch *arch = state->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+
return (value.kind == pvk_register
&& (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
? (value.reg == tdep->r1->num)
static int
m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (state->arch);
+ gdbarch *arch = state->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+
return (value.kind == pvk_register
&& (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
? (value.reg == tdep->r1->num || value.reg == tdep->r2->num)
struct srcdest loc,
pv_t value)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (st->arch);
+ gdbarch *arch = st->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
return (m32c_is_arg_reg (st, value)
&& loc.kind == srcdest_mem
struct srcdest loc,
pv_t value)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (st->arch);
+ gdbarch *arch = st->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
return (m32c_is_1st_arg_reg (st, value)
&& !st->stack->find_reg (st->arch, value.reg, 0)
static int
m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (st->arch);
+ gdbarch *arch = st->arch;
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+
/* The bits in SRC indicating which registers to save are:
r0 r1 r2 r3 a0 a1 sb fb */
return
{
struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
struct gdbarch *arch = prologue->arch;
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
/* Is this the unchanged value of some register being saved on the
stack? */
CORE_ADDR start, CORE_ADDR limit,
struct m32c_prologue *prologue)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
CORE_ADDR after_last_frame_related_insn;
struct m32c_pv_state st;
{
struct m32c_prologue *p
= m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
- struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
+ gdbarch *arch = get_frame_arch (this_frame);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
/* In functions that use alloca, the distance between the stack
pointer and the frame base varies dynamically, so we can't use
m32c_prev_register (struct frame_info *this_frame,
void **this_prologue_cache, int regnum)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
+ gdbarch *arch = get_frame_arch (this_frame);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
struct m32c_prologue *p
= m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
function_call_return_method return_method,
CORE_ADDR struct_addr)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
CORE_ADDR cfa;
for (i = nargs - 1; i >= 0; i--)
{
struct value *arg = args[i];
- const gdb_byte *arg_bits = value_contents (arg);
+ const gdb_byte *arg_bits = value_contents (arg).data ();
struct type *arg_type = value_type (arg);
ULONGEST arg_size = TYPE_LENGTH (arg_type);
gdb_byte *readbuf,
const gdb_byte *writebuf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
enum return_value_convention conv;
ULONGEST valtype_len = TYPE_LENGTH (valtype);
m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* It would be nicer to simply look up the addresses of known
struct m32c_prologue p;
struct regcache *regcache = get_current_regcache ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
internal_error (__FILE__, __LINE__,
m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
struct gdbarch *gdbarch;
- struct gdbarch_tdep *tdep;
unsigned long mach = info.bfd_arch_info->mach;
/* Find a candidate among the list of architectures we've created
arches = gdbarch_list_lookup_by_info (arches->next, &info))
return arches->gdbarch;
- tdep = XCNEW (struct gdbarch_tdep);
+ m32c_gdbarch_tdep *tdep = new m32c_gdbarch_tdep;
gdbarch = gdbarch_alloc (&info, tdep);
/* Essential types. */