Add `set print repeats' tests for C/C++ arrays
[binutils-gdb.git] / gdb / m32c-tdep.c
index 550a63da7569a69c19e311b6bf750221db493b38..5e4844bda0ac065b124d95c35383a16ba672abe9 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -30,6 +30,7 @@
 #include "reggroups.h"
 #include "prologue-value.h"
 #include "objfiles.h"
+#include "gdbarch.h"
 
 \f
 /* The m32c tdep structure.  */
@@ -95,42 +96,44 @@ struct m32c_reg
 #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
@@ -139,7 +142,7 @@ struct gdbarch_tdep
 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];
@@ -212,28 +215,31 @@ make_types (struct gdbarch *arch)
 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;
@@ -248,7 +254,7 @@ static int
 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.  */
@@ -323,7 +329,8 @@ m32c_raw_write (struct m32c_reg *reg, struct regcache *cache,
 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);
@@ -522,7 +529,8 @@ m32c_cat_write (struct m32c_reg *reg, struct regcache *cache,
 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;
 
@@ -558,7 +566,8 @@ static enum register_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)
@@ -586,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
                           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);
@@ -604,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
                            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);
@@ -629,7 +638,7 @@ add_reg (struct gdbarch *arch,
         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);
@@ -668,7 +677,9 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
     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;
 }
 
 
@@ -789,7 +800,7 @@ mark_save_restore (struct m32c_reg *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;
@@ -1336,16 +1347,17 @@ m32c_decode_sd23 (struct m32c_pv_state *st, int code, int size, int ind)
 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);
 
@@ -1371,7 +1383,8 @@ m32c_pv_pushm_one (struct m32c_pv_state *state, pv_t reg,
 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 */
@@ -1391,7 +1404,9 @@ m32c_pv_pushm (struct m32c_pv_state *state, int src)
 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)
@@ -1404,7 +1419,9 @@ m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 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)
@@ -1427,7 +1444,8 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
                   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
@@ -1450,7 +1468,8 @@ m32c_is_struct_return (struct m32c_pv_state *st,
                       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)
@@ -1467,7 +1486,9 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 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
@@ -1494,7 +1515,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   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?  */
@@ -1534,7 +1555,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
                       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;
@@ -1864,7 +1885,8 @@ m32c_frame_base (struct frame_info *this_frame,
 {
   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
@@ -1914,7 +1936,8 @@ static struct value *
 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);
@@ -1997,7 +2020,7 @@ m32c_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);
+  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;
@@ -2043,7 +2066,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   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);
 
@@ -2160,7 +2183,7 @@ m32c_return_value (struct gdbarch *gdbarch,
                   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);
@@ -2291,7 +2314,7 @@ static CORE_ADDR
 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
@@ -2537,7 +2560,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   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__,
@@ -2572,7 +2595,6 @@ static struct gdbarch *
 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
@@ -2582,7 +2604,7 @@ m32c_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        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.  */