PR29262, memory leak in pr_function_type
[binutils-gdb.git] / gdb / h8300-tdep.c
index d8801197c3ca1ae554a7c16a90e6aa7a86291a3c..c4d9824ffda6e337eb08a3225637e954cf628dc0 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-machine dependent code for Renesas H8/300, for GDB.
 
-   Copyright (C) 1988-2019 Free Software Foundation, Inc.
+   Copyright (C) 1988-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -29,7 +29,7 @@
 #include "gdbcore.h"
 #include "objfiles.h"
 #include "dis-asm.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
 
@@ -178,10 +178,10 @@ h8300_is_argument_spill (struct gdbarch *gdbarch, CORE_ADDR pc)
       if (IS_MOVB_Rn24_SP (read_memory_unsigned_integer (pc + 2,
                                                         2, byte_order)))
        {
-         LONGEST disp = read_memory_integer (pc + 4, 4, byte_order);
+         ULONGEST disp = read_memory_unsigned_integer (pc + 4, 4, byte_order);
 
          /* ... and d:24 is negative.  */
-         if (disp < 0 && disp > 0xffffff)
+         if ((disp & 0x00800000) != 0)
            return 8;
        }
     }
@@ -197,10 +197,10 @@ h8300_is_argument_spill (struct gdbarch *gdbarch, CORE_ADDR pc)
       if (IS_MOVW_Rn24_SP (read_memory_unsigned_integer (pc + 2,
                                                         2, byte_order)))
        {
-         LONGEST disp = read_memory_integer (pc + 4, 4, byte_order);
+         ULONGEST disp = read_memory_unsigned_integer (pc + 4, 4, byte_order);
 
          /* ... and d:24 is negative.  */
-         if (disp < 0 && disp > 0xffffff)
+         if ((disp & 0x00800000) != 0)
            return 8;
        }
     }
@@ -219,10 +219,11 @@ h8300_is_argument_spill (struct gdbarch *gdbarch, CORE_ADDR pc)
        {
          if (IS_MOVL_Rn24_SP (read_memory_integer (pc + 4, 2, byte_order)))
            {
-             LONGEST disp = read_memory_integer (pc + 6, 4, byte_order);
+             ULONGEST disp = read_memory_unsigned_integer (pc + 6, 4,
+                                                           byte_order);
 
              /* ... and d:24 is negative.  */
-             if (disp < 0 && disp > 0xffffff)
+             if ((disp & 0x00800000) != 0)
                return 10;
            }
        }
@@ -293,7 +294,7 @@ h8300_analyze_prologue (struct gdbarch *gdbarch,
       cache->saved_regs[E_FP_REGNUM] = 0;
       pc += 4;
       if (pc >= current_pc)
-        return current_pc;
+       return current_pc;
       op = read_memory_unsigned_integer (pc, 2, byte_order);
       if (IS_MOV_SP_FP (op))
        {
@@ -331,7 +332,7 @@ h8300_analyze_prologue (struct gdbarch *gdbarch,
          pc += 2;
        }
       else if (IS_MOV_IMM_Rn (op))
-        {
+       {
          int offset = read_memory_integer (pc + 2, 2, byte_order);
          regno = op & 0x000f;
          op = read_memory_unsigned_integer (pc + 4, 2, byte_order);
@@ -375,7 +376,7 @@ h8300_analyze_prologue (struct gdbarch *gdbarch,
          if (IS_PUSH (op1))
            {
              /* Since the prefix is 0x01x0, this is not a simple pushm but a
-                stm.l reglist,@-sp */
+                stm.l reglist,@-sp */
              i = ((op & 0x0030) >> 4) + 1;
              regno = op1 & 0x000f;
              for (; i > 0; regno++, --i)
@@ -396,7 +397,7 @@ h8300_analyze_prologue (struct gdbarch *gdbarch,
      This could also be an initializing store from non-prologue code,
      but I don't think there's any harm in skipping that.  */
   while ((spill_size = h8300_is_argument_spill (gdbarch, pc)) > 0
-         && pc + spill_size <= current_pc)
+        && pc + spill_size <= current_pc)
     pc += spill_size;
 
   return pc;
@@ -437,12 +438,12 @@ h8300_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (!cache->uses_fp)
     {
       /* We didn't find a valid frame, which means that CACHE->base
-         currently holds the frame pointer for our calling frame.  If
-         we're at the start of a function, or somewhere half-way its
-         prologue, the function's frame probably hasn't been fully
-         setup yet.  Try to reconstruct the base address for the stack
-         frame by looking at the stack pointer.  For truly "frameless"
-         functions this might work too.  */
+        currently holds the frame pointer for our calling frame.  If
+        we're at the start of a function, or somewhere half-way its
+        prologue, the function's frame probably hasn't been fully
+        setup yet.  Try to reconstruct the base address for the stack
+        frame by looking at the stack pointer.  For truly "frameless"
+        functions this might work too.  */
 
       cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM)
                    + cache->sp_offset;
@@ -494,12 +495,13 @@ h8300_frame_prev_register (struct frame_info *this_frame, void **this_cache,
   if (regnum < gdbarch_num_regs (gdbarch)
       && cache->saved_regs[regnum] != -1)
     return frame_unwind_got_memory (this_frame, regnum,
-                                    cache->saved_regs[regnum]);
+                                   cache->saved_regs[regnum]);
 
   return frame_unwind_got_register (this_frame, regnum, regnum);
 }
 
 static const struct frame_unwind h8300_frame_unwind = {
+  "h8300 prologue",
   NORMAL_FRAME,
   default_frame_unwind_stop_reason,
   h8300_frame_this_id,
@@ -535,8 +537,8 @@ h8300_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
       /* Found a function.  */
       sal = find_pc_line (func_addr, 0);
       if (sal.end && sal.end < func_end)
-        /* Found a line number, use it as end of prologue.  */
-        return sal.end;
+       /* Found a line number, use it as end of prologue.  */
+       return sal.end;
 
       /* No useable line symbol.  Use prologue parsing method.  */
       h8300_init_frame_cache (gdbarch, &cache);
@@ -646,7 +648,7 @@ h8300_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
     {
       struct type *type = value_type (args[argument]);
       int len = TYPE_LENGTH (type);
-      char *contents = (char *) value_contents (args[argument]);
+      char *contents = (char *) value_contents (args[argument]).data ();
 
       /* Pad the argument appropriately.  */
       int padded_len = align_up (len, wordsize);
@@ -669,15 +671,15 @@ h8300_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
              stack_offset += padded_len;
 
              /* That's right --- even though we passed the argument
-                on the stack, we consume the registers anyway!  Love
-                me, love my dog.  */
+                on the stack, we consume the registers anyway!  Love
+                me, love my dog.  */
              reg += padded_len / wordsize;
            }
          else
            {
              /* Heavens to Betsy --- it's really going in registers!
-                Note that on the h8/300s, there are gaps between the
-                registers in the register file.  */
+                Note that on the h8/300s, there are gaps between the
+                registers in the register file.  */
              int offset;
 
              for (offset = 0; offset < padded_len; offset += wordsize)
@@ -740,7 +742,7 @@ h8300_extract_return_value (struct type *type, struct regcache *regcache,
       store_unsigned_integer (valbuf + 2, 2, byte_order, c);
       break;
     case 8:                    /* long long is now 8 bytes.  */
-      if (TYPE_CODE (type) == TYPE_CODE_INT)
+      if (type->code () == TYPE_CODE_INT)
        {
          regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr);
          c = read_memory_unsigned_integer ((CORE_ADDR) addr, len, byte_order);
@@ -771,7 +773,7 @@ h8300h_extract_return_value (struct type *type, struct regcache *regcache,
       store_unsigned_integer (valbuf, TYPE_LENGTH (type), byte_order, c);
       break;
     case 8:                    /* long long is now 8 bytes.  */
-      if (TYPE_CODE (type) == TYPE_CODE_INT)
+      if (type->code () == TYPE_CODE_INT)
        {
          regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c);
          store_unsigned_integer (valbuf, 4, byte_order, c);
@@ -792,8 +794,8 @@ h8300_use_struct_convention (struct type *value_type)
   /* Types of 1, 2 or 4 bytes are returned in R0/R1, everything else on the
      stack.  */
 
-  if (TYPE_CODE (value_type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (value_type) == TYPE_CODE_UNION)
+  if (value_type->code () == TYPE_CODE_STRUCT
+      || value_type->code () == TYPE_CODE_UNION)
     return 1;
   return !(TYPE_LENGTH (value_type) == 1
           || TYPE_LENGTH (value_type) == 2
@@ -805,14 +807,14 @@ h8300h_use_struct_convention (struct type *value_type)
 {
   /* Types of 1, 2 or 4 bytes are returned in R0, INT types of 8 bytes are
      returned in R0/R1, everything else on the stack.  */
-  if (TYPE_CODE (value_type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (value_type) == TYPE_CODE_UNION)
+  if (value_type->code () == TYPE_CODE_STRUCT
+      || value_type->code () == TYPE_CODE_UNION)
     return 1;
   return !(TYPE_LENGTH (value_type) == 1
           || TYPE_LENGTH (value_type) == 2
           || TYPE_LENGTH (value_type) == 4
           || (TYPE_LENGTH (value_type) == 8
-              && TYPE_CODE (value_type) == TYPE_CODE_INT));
+              && value_type->code () == TYPE_CODE_INT));
 }
 
 /* Function: store_return_value
@@ -1005,17 +1007,17 @@ h8300_print_register (struct gdbarch *gdbarch, struct ui_file *file,
 
   rval = get_frame_register_signed (frame, regno);
 
-  fprintf_filtered (file, "%-14s ", name);
+  gdb_printf (file, "%-14s ", name);
   if ((regno == E_PSEUDO_CCR_REGNUM (gdbarch)) || \
       (regno == E_PSEUDO_EXR_REGNUM (gdbarch) && is_h8300smode (gdbarch)))
     {
-      fprintf_filtered (file, "0x%02x        ", (unsigned char) rval);
+      gdb_printf (file, "0x%02x        ", (unsigned char) rval);
       print_longest (file, 'u', 1, rval);
     }
   else
     {
-      fprintf_filtered (file, "0x%s  ", phex ((ULONGEST) rval,
-                       BINWORD (gdbarch)));
+      gdb_printf (file, "0x%s  ", phex ((ULONGEST) rval,
+                                       BINWORD (gdbarch)));
       print_longest (file, 'd', 1, rval);
     }
   if (regno == E_PSEUDO_CCR_REGNUM (gdbarch))
@@ -1023,51 +1025,51 @@ h8300_print_register (struct gdbarch *gdbarch, struct ui_file *file,
       /* CCR register */
       int C, Z, N, V;
       unsigned char l = rval & 0xff;
-      fprintf_filtered (file, "\t");
-      fprintf_filtered (file, "I-%d ", (l & 0x80) != 0);
-      fprintf_filtered (file, "UI-%d ", (l & 0x40) != 0);
-      fprintf_filtered (file, "H-%d ", (l & 0x20) != 0);
-      fprintf_filtered (file, "U-%d ", (l & 0x10) != 0);
+      gdb_printf (file, "\t");
+      gdb_printf (file, "I-%d ", (l & 0x80) != 0);
+      gdb_printf (file, "UI-%d ", (l & 0x40) != 0);
+      gdb_printf (file, "H-%d ", (l & 0x20) != 0);
+      gdb_printf (file, "U-%d ", (l & 0x10) != 0);
       N = (l & 0x8) != 0;
       Z = (l & 0x4) != 0;
       V = (l & 0x2) != 0;
       C = (l & 0x1) != 0;
-      fprintf_filtered (file, "N-%d ", N);
-      fprintf_filtered (file, "Z-%d ", Z);
-      fprintf_filtered (file, "V-%d ", V);
-      fprintf_filtered (file, "C-%d ", C);
+      gdb_printf (file, "N-%d ", N);
+      gdb_printf (file, "Z-%d ", Z);
+      gdb_printf (file, "V-%d ", V);
+      gdb_printf (file, "C-%d ", C);
       if ((C | Z) == 0)
-       fprintf_filtered (file, "u> ");
+       gdb_printf (file, "u> ");
       if ((C | Z) == 1)
-       fprintf_filtered (file, "u<= ");
+       gdb_printf (file, "u<= ");
       if (C == 0)
-       fprintf_filtered (file, "u>= ");
+       gdb_printf (file, "u>= ");
       if (C == 1)
-       fprintf_filtered (file, "u< ");
+       gdb_printf (file, "u< ");
       if (Z == 0)
-       fprintf_filtered (file, "!= ");
+       gdb_printf (file, "!= ");
       if (Z == 1)
-       fprintf_filtered (file, "== ");
+       gdb_printf (file, "== ");
       if ((N ^ V) == 0)
-       fprintf_filtered (file, ">= ");
+       gdb_printf (file, ">= ");
       if ((N ^ V) == 1)
-       fprintf_filtered (file, "< ");
+       gdb_printf (file, "< ");
       if ((Z | (N ^ V)) == 0)
-       fprintf_filtered (file, "> ");
+       gdb_printf (file, "> ");
       if ((Z | (N ^ V)) == 1)
-       fprintf_filtered (file, "<= ");
+       gdb_printf (file, "<= ");
     }
   else if (regno == E_PSEUDO_EXR_REGNUM (gdbarch) && is_h8300smode (gdbarch))
     {
       /* EXR register */
       unsigned char l = rval & 0xff;
-      fprintf_filtered (file, "\t");
-      fprintf_filtered (file, "T-%d - - - ", (l & 0x80) != 0);
-      fprintf_filtered (file, "I2-%d ", (l & 4) != 0);
-      fprintf_filtered (file, "I1-%d ", (l & 2) != 0);
-      fprintf_filtered (file, "I0-%d", (l & 1) != 0);
+      gdb_printf (file, "\t");
+      gdb_printf (file, "T-%d - - - ", (l & 0x80) != 0);
+      gdb_printf (file, "I2-%d ", (l & 4) != 0);
+      gdb_printf (file, "I1-%d ", (l & 2) != 0);
+      gdb_printf (file, "I0-%d", (l & 1) != 0);
     }
-  fprintf_filtered (file, "\n");
+  gdb_printf (file, "\n");
 }
 
 static void
@@ -1377,8 +1379,9 @@ h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
 }
 
+void _initialize_h8300_tdep ();
 void
-_initialize_h8300_tdep (void)
+_initialize_h8300_tdep ()
 {
   register_gdbarch_init (bfd_arch_h8300, h8300_gdbarch_init);
 }