Remove cleanup from complaints.c
[deliverable/binutils-gdb.git] / gdb / m88k-tdep.c
index 7f6fe33b5b21993342a4cc41fa8c744fe6490e79..9f1688abf0abfc63262450fcace995564355f30f 100644 (file)
@@ -1,12 +1,12 @@
 /* Target-dependent code for the Motorola 88000 series.
 
-   Copyright 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -15,9 +15,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "arch-utils.h"
 #include "symtab.h"
 #include "trad-frame.h"
 #include "value.h"
-
-#include "gdb_assert.h"
-#include "gdb_string.h"
+#include <algorithm>
 
 #include "m88k-tdep.h"
 
 /* Fetch the instruction at PC.  */
 
 static unsigned long
-m88k_fetch_instruction (CORE_ADDR pc)
+m88k_fetch_instruction (CORE_ADDR pc, enum bfd_endian byte_order)
 {
-  return read_memory_unsigned_integer (pc, 4);
+  return read_memory_unsigned_integer (pc, 4, byte_order);
 }
 
 /* Register information.  */
@@ -51,9 +47,9 @@ m88k_fetch_instruction (CORE_ADDR pc)
 /* Return the name of register REGNUM.  */
 
 static const char *
-m88k_register_name (int regnum)
+m88k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  static char *register_names[] =
+  static const char *register_names[] =
   {
     "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
     "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
@@ -69,7 +65,7 @@ m88k_register_name (int regnum)
 }
 
 /* Return the GDB type object for the "standard" data type of data in
-   register REGNUM. */
+   register REGNUM.  */
 
 static struct type *
 m88k_register_type (struct gdbarch *gdbarch, int regnum)
@@ -77,18 +73,18 @@ m88k_register_type (struct gdbarch *gdbarch, int regnum)
   /* SXIP, SNIP, SFIP and R1 contain code addresses.  */
   if ((regnum >= M88K_SXIP_REGNUM && regnum <= M88K_SFIP_REGNUM)
       || regnum == M88K_R1_REGNUM)
-    return builtin_type_void_func_ptr;
+    return builtin_type (gdbarch)->builtin_func_ptr;
 
   /* R30 and R31 typically contains data addresses.  */
   if (regnum == M88K_R30_REGNUM || regnum == M88K_R31_REGNUM)
-    return builtin_type_void_data_ptr;
+    return builtin_type (gdbarch)->builtin_data_ptr;
 
-  return builtin_type_int32;
+  return builtin_type (gdbarch)->builtin_int32;
 }
 \f
 
 static CORE_ADDR
-m88k_addr_bits_remove (CORE_ADDR addr)
+m88k_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   /* All instructures are 4-byte aligned.  The lower 2 bits of SXIP,
      SNIP and SFIP are used for special purposes: bit 0 is the
@@ -101,16 +97,11 @@ m88k_addr_bits_remove (CORE_ADDR addr)
    encode a breakpoint instruction, store the length of the string in
    *LEN and optionally adjust *PC to point to the correct memory
    location for inserting the breakpoint.  */
-   
-static const unsigned char *
-m88k_breakpoint_from_pc (CORE_ADDR *pc, int *len)
-{
-  /* tb 0,r0,511 */
-  static unsigned char break_insn[] = { 0xf0, 0x00, 0xd1, 0xff };
 
-  *len = sizeof (break_insn);
-  return break_insn;
-}
+/* tb 0,r0,511 */
+constexpr gdb_byte m88k_break_insn[] = { 0xf0, 0x00, 0xd1, 0xff };
+
+typedef BP_MANIPULATION (m88k_break_insn) m88k_breakpoint;
 
 static CORE_ADDR
 m88k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
@@ -118,11 +109,11 @@ m88k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
   CORE_ADDR pc;
 
   pc = frame_unwind_register_unsigned (next_frame, M88K_SXIP_REGNUM);
-  return m88k_addr_bits_remove (pc);
+  return m88k_addr_bits_remove (gdbarch, pc);
 }
 
 static void
-m88k_write_pc (CORE_ADDR pc, ptid_t ptid)
+m88k_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   /* According to the MC88100 RISC Microprocessor User's Manual,
      section 6.4.3.1.2:
@@ -140,9 +131,9 @@ m88k_write_pc (CORE_ADDR pc, ptid_t ptid)
      with it.  We could even (presumably) give it a totally bogus
      value.  */
 
-  write_register_pid (M88K_SXIP_REGNUM, pc, ptid);
-  write_register_pid (M88K_SNIP_REGNUM, pc | 2, ptid);
-  write_register_pid (M88K_SFIP_REGNUM, (pc + 4) | 2, ptid);
+  regcache_cooked_write_unsigned (regcache, M88K_SXIP_REGNUM, pc);
+  regcache_cooked_write_unsigned (regcache, M88K_SNIP_REGNUM, pc | 2);
+  regcache_cooked_write_unsigned (regcache, M88K_SFIP_REGNUM, (pc + 4) | 2);
 }
 \f
 
@@ -170,6 +161,7 @@ m88k_integral_or_pointer_p (const struct type *type)
       return 1;
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       {
        /* Allow only 32-bit pointers.  */
        return (TYPE_LENGTH (type) == 4);
@@ -260,6 +252,7 @@ static CORE_ADDR
 m88k_store_arguments (struct regcache *regcache, int nargs,
                      struct value **args, CORE_ADDR sp)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   int num_register_words = 0;
   int num_stack_words = 0;
   int i;
@@ -271,7 +264,8 @@ m88k_store_arguments (struct regcache *regcache, int nargs,
 
       if (m88k_integral_or_pointer_p (type) && len < 4)
        {
-         args[i] = value_cast (builtin_type_int32, args[i]);
+         args[i] = value_cast (builtin_type (gdbarch)->builtin_int32,
+                               args[i]);
          type = value_type (args[i]);
          len = TYPE_LENGTH (type);
        }
@@ -306,7 +300,7 @@ m88k_store_arguments (struct regcache *regcache, int nargs,
 
   for (i = 0; i < nargs; i++)
     {
-      char *valbuf = VALUE_CONTENTS (args[i]);
+      const bfd_byte *valbuf = value_contents (args[i]);
       struct type *type = value_type (args[i]);
       int len = TYPE_LENGTH (type);
       int stack_word = num_stack_words;
@@ -367,12 +361,12 @@ m88k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 }
 
 static struct frame_id
-m88k_unwind_dummy_id (struct gdbarch *arch, struct frame_info *next_frame)
+m88k_dummy_id (struct gdbarch *arch, struct frame_info *this_frame)
 {
   CORE_ADDR sp;
 
-  sp = frame_unwind_register_unsigned (next_frame, M88K_R31_REGNUM);
-  return frame_id_build (sp, frame_pc_unwind (next_frame));
+  sp = get_frame_register_unsigned (this_frame, M88K_R31_REGNUM);
+  return frame_id_build (sp, get_frame_pc (this_frame));
 }
 \f
 
@@ -383,12 +377,12 @@ m88k_unwind_dummy_id (struct gdbarch *arch, struct frame_info *next_frame)
    from WRITEBUF into REGCACHE.  */
 
 static enum return_value_convention
-m88k_return_value (struct gdbarch *gdbarch, struct type *type,
-                  struct regcache *regcache, void *readbuf,
-                  const void *writebuf)
+m88k_return_value (struct gdbarch *gdbarch, struct value *function,
+                  struct type *type, struct regcache *regcache,
+                  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   int len = TYPE_LENGTH (type);
-  char buf[8];
+  gdb_byte buf[8];
 
   if (!m88k_integral_or_pointer_p (type) && !m88k_floating_p (type))
     return RETURN_VALUE_STRUCT_CONVENTION;
@@ -526,19 +520,19 @@ struct m88k_prologue_insn m88k_prologue_insn_table[] =
    prologue.  */
 
 static CORE_ADDR
-m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
+m88k_analyze_prologue (struct gdbarch *gdbarch,
+                      CORE_ADDR pc, CORE_ADDR limit,
                       struct m88k_frame_cache *cache)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR end = limit;
 
   /* Provide a dummy cache if necessary.  */
   if (cache == NULL)
     {
-      size_t sizeof_saved_regs =
-       (M88K_R31_REGNUM + 1) * sizeof (struct trad_frame_saved_reg);
-
-      cache = alloca (sizeof (struct m88k_frame_cache));
-      cache->saved_regs = alloca (sizeof_saved_regs);
+      cache = XALLOCA (struct m88k_frame_cache);
+      cache->saved_regs =
+        XALLOCAVEC (struct trad_frame_saved_reg, M88K_R31_REGNUM + 1);
 
       /* We only initialize the members we care about.  */
       cache->saved_regs[M88K_R1_REGNUM].addr = -1;
@@ -548,7 +542,7 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
   while (pc < limit)
     {
       struct m88k_prologue_insn *pi = m88k_prologue_insn_table;
-      unsigned long insn = m88k_fetch_instruction (pc);
+      unsigned long insn = m88k_fetch_instruction (pc, byte_order);
 
       while ((insn & pi->mask) != pi->insn)
        pi++;
@@ -561,7 +555,7 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
              prologue.  */
          if (cache->fp_offset != -1
              && cache->saved_regs[M88K_R1_REGNUM].addr != -1)
-           return min (pc, end);
+           return std::min (pc, end);
          break;
 
        case M88K_PIA_NOTE_ST:
@@ -569,7 +563,7 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
          /* If no frame has been allocated, the stores aren't part of
              the prologue.  */
          if (cache->sp_offset == 0)
-           return min (pc, end);
+           return std::min (pc, end);
 
          /* Record location of saved registers.  */
          {
@@ -586,7 +580,7 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
          /* A second stack pointer adjustment isn't part of the
              prologue.  */
          if (cache->sp_offset != 0)
-           return min (pc, end);
+           return std::min (pc, end);
 
          /* Store stack pointer adjustment.  */
          cache->sp_offset = -SUBU_OFFSET (insn);
@@ -596,7 +590,7 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
          /* A second frame pointer assignment isn't part of the
              prologue.  */
          if (cache->fp_offset != -1)
-           return min (pc, end);
+           return std::min (pc, end);
 
          /* Record frame pointer assignment.  */
          cache->fp_offset = ADDU_OFFSET (insn);
@@ -607,12 +601,12 @@ m88k_analyze_prologue (CORE_ADDR pc, CORE_ADDR limit,
              the instruction in the delay slot might be.  Limit the
              prologue analysis to the delay slot and record the branch
              instruction as the end of the prologue.  */
-         limit = min (limit, pc + 2 * M88K_INSN_SIZE);
+         limit = std::min (limit, pc + 2 * M88K_INSN_SIZE);
          end = pc;
          break;
 
        case M88K_PIA_NOTE_PROLOGUE_END:
-         return min (pc, end);
+         return std::min (pc, end);
        }
 
       pc += M88K_INSN_SIZE;
@@ -628,7 +622,7 @@ const int m88k_max_prologue_size = 128 * M88K_INSN_SIZE;
    starting at PC.  */
 
 static CORE_ADDR
-m88k_skip_prologue (CORE_ADDR pc)
+m88k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   struct symtab_and_line sal;
   CORE_ADDR func_start, func_end;
@@ -643,35 +637,35 @@ m88k_skip_prologue (CORE_ADDR pc)
        return sal.end;
     }
 
-  return m88k_analyze_prologue (pc, pc + m88k_max_prologue_size, NULL);
+  return m88k_analyze_prologue (gdbarch, pc, pc + m88k_max_prologue_size,
+                               NULL);
 }
 
-struct m88k_frame_cache *
-m88k_frame_cache (struct frame_info *next_frame, void **this_cache)
+static struct m88k_frame_cache *
+m88k_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
   struct m88k_frame_cache *cache;
   CORE_ADDR frame_sp;
 
   if (*this_cache)
-    return *this_cache;
+    return (struct m88k_frame_cache *) *this_cache;
 
   cache = FRAME_OBSTACK_ZALLOC (struct m88k_frame_cache);
-  cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
+  cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
   cache->fp_offset = -1;
 
-  cache->pc = frame_func_unwind (next_frame);
+  cache->pc = get_frame_func (this_frame);
   if (cache->pc != 0)
-    {
-      CORE_ADDR addr_in_block = frame_unwind_address_in_block (next_frame);
-      m88k_analyze_prologue (cache->pc, addr_in_block, cache);
-    }
+    m88k_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame),
+                          cache);
 
   /* Calculate the stack pointer used in the prologue.  */
   if (cache->fp_offset != -1)
     {
       CORE_ADDR fp;
 
-      fp = frame_unwind_register_unsigned (next_frame, M88K_R30_REGNUM);
+      fp = get_frame_register_unsigned (this_frame, M88K_R30_REGNUM);
       frame_sp = fp - cache->fp_offset;
     }
   else
@@ -680,7 +674,7 @@ m88k_frame_cache (struct frame_info *next_frame, void **this_cache)
          solid guess at what the frame pointer should be.  */
       if (cache->saved_regs[M88K_R1_REGNUM].addr != -1)
        cache->fp_offset = cache->saved_regs[M88K_R1_REGNUM].addr - 4;
-      frame_sp = frame_unwind_register_unsigned (next_frame, M88K_R31_REGNUM);
+      frame_sp = get_frame_register_unsigned (this_frame, M88K_R31_REGNUM);
     }
 
   /* Now that we know the stack pointer, adjust the location of the
@@ -705,10 +699,10 @@ m88k_frame_cache (struct frame_info *next_frame, void **this_cache)
 }
 
 static void
-m88k_frame_this_id (struct frame_info *next_frame, void **this_cache,
+m88k_frame_this_id (struct frame_info *this_frame, void **this_cache,
                    struct frame_id *this_id)
 {
-  struct m88k_frame_cache *cache = m88k_frame_cache (next_frame, this_cache);
+  struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache);
 
   /* This marks the outermost frame.  */
   if (cache->base == 0)
@@ -717,60 +711,47 @@ m88k_frame_this_id (struct frame_info *next_frame, void **this_cache,
   (*this_id) = frame_id_build (cache->base, cache->pc);
 }
 
-static void
-m88k_frame_prev_register (struct frame_info *next_frame, void **this_cache,
-                         int regnum, int *optimizedp,
-                         enum lval_type *lvalp, CORE_ADDR *addrp,
-                         int *realnump, void *valuep)
+static struct value *
+m88k_frame_prev_register (struct frame_info *this_frame,
+                         void **this_cache, int regnum)
 {
-  struct m88k_frame_cache *cache = m88k_frame_cache (next_frame, this_cache);
+  struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache);
 
   if (regnum == M88K_SNIP_REGNUM || regnum == M88K_SFIP_REGNUM)
     {
-      if (valuep)
-       {
-         CORE_ADDR pc;
+      struct value *value;
+      CORE_ADDR pc;
 
-         trad_frame_get_prev_register (next_frame, cache->saved_regs,
-                                       M88K_SXIP_REGNUM, optimizedp,
-                                       lvalp, addrp, realnump, valuep);
+      value = trad_frame_get_prev_register (this_frame, cache->saved_regs,
+                                           M88K_SXIP_REGNUM);
+      pc = value_as_long (value);
+      release_value (value);
+      value_free (value);
 
-         pc = extract_unsigned_integer (valuep, 4);
-         if (regnum == M88K_SFIP_REGNUM)
-           pc += 4;
-         store_unsigned_integer (valuep, 4, pc + 4);
-       }
+      if (regnum == M88K_SFIP_REGNUM)
+       pc += 4;
 
-      /* It's a computed value.  */
-      *optimizedp = 0;
-      *lvalp = not_lval;
-      *addrp = 0;
-      *realnump = -1;
-      return;
+      return frame_unwind_got_constant (this_frame, regnum, pc + 4);
     }
 
-  trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
-                               optimizedp, lvalp, addrp, realnump, valuep);
+  return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
 }
 
 static const struct frame_unwind m88k_frame_unwind =
 {
   NORMAL_FRAME,
+  default_frame_unwind_stop_reason,
   m88k_frame_this_id,
-  m88k_frame_prev_register
+  m88k_frame_prev_register,
+  NULL,
+  default_frame_sniffer
 };
-
-static const struct frame_unwind *
-m88k_frame_sniffer (struct frame_info *next_frame)
-{
-  return &m88k_frame_unwind;
-}
 \f
 
 static CORE_ADDR
-m88k_frame_base_address (struct frame_info *next_frame, void **this_cache)
+m88k_frame_base_address (struct frame_info *this_frame, void **this_cache)
 {
-  struct m88k_frame_cache *cache = m88k_frame_cache (next_frame, this_cache);
+  struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache);
 
   if (cache->fp_offset != -1)
     return cache->base + cache->sp_offset + cache->fp_offset;
@@ -798,7 +779,7 @@ m88k_supply_gregset (const struct regset *regset,
                     struct regcache *regcache,
                     int regnum, const void *gregs, size_t len)
 {
-  const char *regs = gregs;
+  const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
   for (i = 0; i < M88K_NUM_REGS; i++)
@@ -810,23 +791,21 @@ m88k_supply_gregset (const struct regset *regset,
 
 /* Motorola 88000 register set.  */
 
-static struct regset m88k_gregset =
+static const struct regset m88k_gregset =
 {
   NULL,
   m88k_supply_gregset
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over supported core file register note sections. */
 
-static const struct regset *
-m88k_regset_from_core_section (struct gdbarch *gdbarch,
-                              const char *sect_name, size_t sect_size)
+static void
+m88k_iterate_over_regset_sections (struct gdbarch *gdbarch,
+                                  iterate_over_regset_sections_cb *cb,
+                                  void *cb_data,
+                                  const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0 && sect_size >= M88K_NUM_REGS * 4)
-    return &m88k_gregset;
-
-  return NULL;
+  cb (".reg", M88K_NUM_REGS * 4, &m88k_gregset, NULL, cb_data);
 }
 \f
 
@@ -845,7 +824,7 @@ m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* There is no real `long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
-  set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
+  set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
 
   set_gdbarch_num_regs (gdbarch, M88K_NUM_REGS);
   set_gdbarch_register_name (gdbarch, m88k_register_name);
@@ -856,10 +835,8 @@ m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pc_regnum (gdbarch, M88K_SXIP_REGNUM);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, m88k_regset_from_core_section);
-
-  set_gdbarch_print_insn (gdbarch, print_insn_m88k);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, m88k_iterate_over_regset_sections);
 
   set_gdbarch_skip_prologue (gdbarch, m88k_skip_prologue);
 
@@ -868,25 +845,22 @@ m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Call dummy code.  */
   set_gdbarch_push_dummy_call (gdbarch, m88k_push_dummy_call);
-  set_gdbarch_unwind_dummy_id (gdbarch, m88k_unwind_dummy_id);
+  set_gdbarch_dummy_id (gdbarch, m88k_dummy_id);
 
-  /* Return value info */
+  /* Return value info */
   set_gdbarch_return_value (gdbarch, m88k_return_value);
 
   set_gdbarch_addr_bits_remove (gdbarch, m88k_addr_bits_remove);
-  set_gdbarch_breakpoint_from_pc (gdbarch, m88k_breakpoint_from_pc);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch, m88k_breakpoint::kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch, m88k_breakpoint::bp_from_kind);
   set_gdbarch_unwind_pc (gdbarch, m88k_unwind_pc);
   set_gdbarch_write_pc (gdbarch, m88k_write_pc);
 
   frame_base_set_default (gdbarch, &m88k_frame_base);
-  frame_unwind_append_sniffer (gdbarch, m88k_frame_sniffer);
+  frame_unwind_append_unwinder (gdbarch, &m88k_frame_unwind);
 
   return gdbarch;
 }
-\f
-
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_m88k_tdep (void);
 
 void
 _initialize_m88k_tdep (void)
This page took 0.03293 seconds and 4 git commands to generate.