gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / sparc64-tdep.c
index 86b5fcf47bf9d2819bad3cc34be15037ed1a97ff..5d6ef071099fe5ef97c35c22ca2d8e16919d521f 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for UltraSPARC.
 
-   Copyright (C) 2003-2018 Free Software Foundation, Inc.
+   Copyright (C) 2003-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -19,7 +19,7 @@
 
 #include "defs.h"
 #include "arch-utils.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
@@ -86,7 +86,7 @@
 static struct cmd_list_element *sparc64adilist = NULL;
 
 /* ADI stat settings.  */
-typedef struct
+struct adi_stat_t
 {
   /* The ADI block size.  */
   unsigned long blksize;
@@ -108,11 +108,11 @@ typedef struct
   /* ADI is available.  */
   bool is_avail = false;
 
-} adi_stat_t;
+};
 
 /* Per-process ADI stat info.  */
 
-typedef struct sparc64_adi_info
+struct sparc64_adi_info
 {
   sparc64_adi_info (pid_t pid_)
     : pid (pid_)
@@ -124,7 +124,7 @@ typedef struct sparc64_adi_info
   /* The ADI stat.  */
   adi_stat_t stat = {};
 
-} sparc64_adi_info;
+};
 
 static std::forward_list<sparc64_adi_info> adi_proc_list;
 
@@ -186,14 +186,6 @@ sparc64_forget_process (pid_t pid)
 
 }
 
-static void
-info_adi_command (const char *args, int from_tty)
-{
-  printf_unfiltered ("\"adi\" must be followed by \"examine\" "
-                     "or \"assign\".\n");
-  help_list (sparc64adilist, "adi ", all_commands, gdb_stdout);
-}
-
 /* Read attributes of a maps entry in /proc/[pid]/adi/maps.  */
 
 static void
@@ -214,7 +206,7 @@ read_maps_entry (const char *line,
 static bool
 adi_available (void)
 {
-  pid_t pid = ptid_get_pid (inferior_ptid);
+  pid_t pid = inferior_ptid.pid ();
   sparc64_adi_info *proc = get_adi_info_proc (pid);
   CORE_ADDR value;
 
@@ -222,10 +214,10 @@ adi_available (void)
     return proc->stat.is_avail;
 
   proc->stat.checked_avail = true;
-  if (target_auxv_search (target_stack, AT_ADI_BLKSZ, &value) <= 0)
+  if (target_auxv_search (current_top_target (), AT_ADI_BLKSZ, &value) <= 0)
     return false;
   proc->stat.blksize = value;
-  target_auxv_search (target_stack, AT_ADI_NBITS, &value);
+  target_auxv_search (current_top_target (), AT_ADI_NBITS, &value);
   proc->stat.nbits = value;
   proc->stat.max_version = (1 << proc->stat.nbits) - 2;
   proc->stat.is_avail = true;
@@ -238,7 +230,7 @@ adi_available (void)
 static CORE_ADDR
 adi_normalize_address (CORE_ADDR addr)
 {
-  adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+  adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
 
   if (ast.nbits)
     {
@@ -258,7 +250,7 @@ adi_normalize_address (CORE_ADDR addr)
 static CORE_ADDR
 adi_align_address (CORE_ADDR naddr)
 {
-  adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+  adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
 
   return (naddr - (naddr % ast.blksize)) / ast.blksize;
 }
@@ -268,7 +260,7 @@ adi_align_address (CORE_ADDR naddr)
 static int
 adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
 {
-  adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+  adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
 
   return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl;
 }
@@ -285,7 +277,7 @@ adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
 static int
 adi_tag_fd (void)
 {
-  pid_t pid = ptid_get_pid (inferior_ptid);
+  pid_t pid = inferior_ptid.pid ();
   sparc64_adi_info *proc = get_adi_info_proc (pid);
 
   if (proc->stat.tag_fd != 0)
@@ -295,7 +287,7 @@ adi_tag_fd (void)
   snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
   int target_errno;
   proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL, 
-                                          0, &target_errno);
+                                          false, 0, &target_errno);
   return proc->stat.tag_fd;
 }
 
@@ -309,15 +301,17 @@ adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt)
   char filename[MAX_PROC_NAME_SIZE];
   size_t i = 0;
 
-  pid_t pid = ptid_get_pid (inferior_ptid);
+  pid_t pid = inferior_ptid.pid ();
   snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid);
   gdb::unique_xmalloc_ptr<char> data
     = target_fileio_read_stralloc (NULL, filename);
   if (data)
     {
       adi_stat_t adi_stat = get_adi_info (pid);
-      char *line;
-      for (line = strtok (data.get (), "\n"); line; line = strtok (NULL, "\n"))
+      char *saveptr;
+      for (char *line = strtok_r (data.get (), "\n", &saveptr);
+          line;
+          line = strtok_r (NULL, "\n", &saveptr))
         {
           ULONGEST addr, endaddr;
 
@@ -349,7 +343,7 @@ adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_byte *tags)
 
   if (!adi_is_addr_mapped (vaddr, size))
     {
-      adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+      adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
       error(_("Address at %s is not in ADI maps"),
             paddress (target_gdbarch (), vaddr * ast.blksize));
     }
@@ -370,7 +364,7 @@ adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
 
   if (!adi_is_addr_mapped (vaddr, size))
     {
-      adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+      adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
       error(_("Address at %s is not in ADI maps"),
             paddress (target_gdbarch (), vaddr * ast.blksize));
     }
@@ -388,7 +382,7 @@ adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
   int v_idx = 0;
   const int maxelts = 8;  /* # of elements per line */
 
-  adi_stat_t adi_stat = get_adi_info (ptid_get_pid (inferior_ptid));
+  adi_stat_t adi_stat = get_adi_info (inferior_ptid.pid ());
 
   while (cnt > 0)
     {
@@ -406,7 +400,6 @@ adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
           ++v_idx;
         }
       printf_filtered ("\n");
-      gdb_flush (gdb_stdout);
       vaddr += maxelts;
     }
 }
@@ -449,7 +442,7 @@ do_assign (CORE_ADDR start, size_t bcnt, int version)
 
    Command syntax:
 
-     adi (examine|x)/count <addr> */
+     adi (examine|x)[/COUNT] [ADDR] */
 
 static void
 adi_examine_command (const char *args, int from_tty)
@@ -461,8 +454,6 @@ adi_examine_command (const char *args, int from_tty)
   if (!adi_available ())
     error (_("No ADI information"));
 
-  pid_t pid = ptid_get_pid (inferior_ptid);
-  sparc64_adi_info *proc = get_adi_info_proc (pid);
   int cnt = 1;
   const char *p = args;
   if (p && *p == '/')
@@ -475,7 +466,7 @@ adi_examine_command (const char *args, int from_tty)
   if (p != 0 && *p != 0)
     next_address = parse_and_eval_address (p);
   if (!cnt || !next_address)
-    error (_("Usage: adi examine|x[/count] <addr>"));
+    error (_("Usage: adi examine|x[/COUNT] [ADDR]"));
 
   do_examine (next_address, cnt);
 }
@@ -484,11 +475,14 @@ adi_examine_command (const char *args, int from_tty)
 
    Command syntax:
 
-     adi (assign|a)/count <addr> = <version>  */
+     adi (assign|a)[/COUNT] ADDR = VERSION  */
 
 static void
 adi_assign_command (const char *args, int from_tty)
 {
+  static const char *adi_usage
+    = N_("Usage: adi assign|a[/COUNT] ADDR = VERSION");
+
   /* make sure program is active and adi is available */
   if (!target_has_execution)
     error (_("ADI command requires a live process/thread"));
@@ -498,13 +492,13 @@ adi_assign_command (const char *args, int from_tty)
 
   const char *exp = args;
   if (exp == 0)
-    error_no_arg (_("Usage: adi assign|a[/count] <addr> = <version>"));
+    error_no_arg (_(adi_usage));
 
   char *q = (char *) strchr (exp, '=');
   if (q)
     *q++ = 0;
   else
-    error (_("Usage: adi assign|a[/count] <addr> = <version>"));
+    error ("%s", _(adi_usage));
 
   size_t cnt = 1;
   const char *p = args;
@@ -518,12 +512,12 @@ adi_assign_command (const char *args, int from_tty)
   if (p != 0 && *p != 0)
     next_address = parse_and_eval_address (p);
   else
-    error (_("Usage: adi assign|a[/count] <addr> = <version>"));
+    error ("%s", _(adi_usage));
 
   int version = 0;
   if (q != NULL)           /* parse version tag */
     {
-      adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
+      adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
       version = parse_and_eval_long (q);
       if (version < 0 || version > ast.max_version)
         error (_("Invalid ADI version tag %d"), version);
@@ -532,13 +526,13 @@ adi_assign_command (const char *args, int from_tty)
   do_assign (next_address, cnt, version);
 }
 
+void _initialize_sparc64_adi_tdep ();
 void
-_initialize_sparc64_adi_tdep (void)
+_initialize_sparc64_adi_tdep ()
 {
-
-  add_prefix_cmd ("adi", class_support, info_adi_command,
-                  _("ADI version related commands."),
-                  &sparc64adilist, "adi ", 0, &cmdlist);
+  add_basic_prefix_cmd ("adi", class_support,
+                       _("ADI version related commands."),
+                       &sparc64adilist, "adi ", 0, &cmdlist);
   add_cmd ("examine", class_support, adi_examine_command,
            _("Examine ADI versions."), &sparc64adilist);
   add_alias_cmd ("x", "examine", no_class, 1, &sparc64adilist);
@@ -556,7 +550,7 @@ _initialize_sparc64_adi_tdep (void)
 static int
 sparc64_integral_or_pointer_p (const struct type *type)
 {
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_INT:
     case TYPE_CODE_BOOL:
@@ -588,7 +582,7 @@ sparc64_integral_or_pointer_p (const struct type *type)
 static int
 sparc64_floating_p (const struct type *type)
 {
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_FLT:
       {
@@ -608,7 +602,7 @@ sparc64_floating_p (const struct type *type)
 static int
 sparc64_complex_floating_p (const struct type *type)
 {
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_COMPLEX:
       {
@@ -632,7 +626,7 @@ sparc64_complex_floating_p (const struct type *type)
 static int
 sparc64_structure_or_union_p (const struct type *type)
 {
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
@@ -1171,7 +1165,7 @@ static const struct frame_base sparc64_frame_base =
 static int
 sparc64_16_byte_align_p (struct type *type)
 {
-  if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (type->code () == TYPE_CODE_ARRAY)
     {
       struct type *t = check_typedef (TYPE_TARGET_TYPE (type));
 
@@ -1185,7 +1179,7 @@ sparc64_16_byte_align_p (struct type *type)
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
        {
          struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
 
@@ -1199,7 +1193,7 @@ sparc64_16_byte_align_p (struct type *type)
 
 /* Store floating fields of element ELEMENT of an "parameter array"
    that has type TYPE and is stored at BITPOS in VALBUF in the
-   apropriate registers of REGCACHE.  This function can be called
+   appropriate registers of REGCACHE.  This function can be called
    recursively and therefore handles floating types in addition to
    structures.  */
 
@@ -1212,7 +1206,7 @@ sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
 
   gdb_assert (element < 16);
 
-  if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (type->code () == TYPE_CODE_ARRAY)
     {
       gdb_byte buf[8];
       int regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
@@ -1262,7 +1256,7 @@ sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
        {
          struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
          int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
@@ -1280,7 +1274,7 @@ sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
          probably in older releases to.  To appease GCC, if a
          structure has only a single `float' member, we store its
          value in %f1 too (we already have stored in %f0).  */
-      if (TYPE_NFIELDS (type) == 1)
+      if (type->num_fields () == 1)
        {
          struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0));
 
@@ -1301,7 +1295,7 @@ sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
 {
   struct gdbarch *gdbarch = regcache->arch ();
 
-  if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (type->code () == TYPE_CODE_ARRAY)
     {
       int len = TYPE_LENGTH (type);
       int regnum =  SPARC_F0_REGNUM + bitpos / 32;
@@ -1350,7 +1344,7 @@ sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
        {
          struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
          int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
@@ -1366,7 +1360,8 @@ sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
 static CORE_ADDR
 sparc64_store_arguments (struct regcache *regcache, int nargs,
                         struct value **args, CORE_ADDR sp,
-                        int struct_return, CORE_ADDR struct_addr)
+                        function_call_return_method return_method,
+                        CORE_ADDR struct_addr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   /* Number of extended words in the "parameter array".  */
@@ -1380,7 +1375,7 @@ sparc64_store_arguments (struct regcache *regcache, int nargs,
   /* First we calculate the number of extended words in the "parameter
      array".  While doing so we also convert some of the arguments.  */
 
-  if (struct_return)
+  if (return_method == return_method_struct)
     num_elements++;
 
   for (i = 0; i < nargs; i++)
@@ -1462,7 +1457,7 @@ sparc64_store_arguments (struct regcache *regcache, int nargs,
   /* The psABI says that "Every stack frame must be 16-byte aligned."  */
   sp &= ~0xf;
 
-  /* Now we store the arguments in to the "paramater array".  Some
+  /* Now we store the arguments in to the "parameter array".  Some
      Integer or Pointer arguments and Structure or Union arguments
      will be passed in %o registers.  Some Floating arguments and
      floating members of structures are passed in floating-point
@@ -1476,7 +1471,7 @@ sparc64_store_arguments (struct regcache *regcache, int nargs,
      contents of any unused memory or registers in the "parameter
      array" are undefined.  */
 
-  if (struct_return)
+  if (return_method == return_method_struct)
     {
       regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
       element++;
@@ -1620,14 +1615,15 @@ static CORE_ADDR
 sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                         struct regcache *regcache, CORE_ADDR bp_addr,
                         int nargs, struct value **args, CORE_ADDR sp,
-                        int struct_return, CORE_ADDR struct_addr)
+                        function_call_return_method return_method,
+                        CORE_ADDR struct_addr)
 {
   /* Set return address.  */
   regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
 
   /* Set up function arguments.  */
-  sp = sparc64_store_arguments (regcache, nargs, args, sp,
-                               struct_return, struct_addr);
+  sp = sparc64_store_arguments (regcache, nargs, args, sp, return_method,
+                               struct_addr);
 
   /* Allocate the register save area.  */
   sp -= 16 * 8;
@@ -1660,7 +1656,7 @@ sparc64_extract_return_value (struct type *type, struct regcache *regcache,
 
       for (i = 0; i < ((len + 7) / 8); i++)
        regcache->cooked_read (SPARC_O0_REGNUM + i, buf + i * 8);
-      if (TYPE_CODE (type) != TYPE_CODE_UNION)
+      if (type->code () != TYPE_CODE_UNION)
        sparc64_extract_floating_fields (regcache, type, buf, 0);
       memcpy (valbuf, buf, len);
     }
@@ -1671,7 +1667,7 @@ sparc64_extract_return_value (struct type *type, struct regcache *regcache,
        regcache->cooked_read (SPARC_F0_REGNUM + i, buf + i * 4);
       memcpy (valbuf, buf, len);
     }
-  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  else if (type->code () == TYPE_CODE_ARRAY)
     {
       /* Small arrays are returned the same way as small structures.  */
       gdb_assert (len <= 32);
@@ -1715,7 +1711,7 @@ sparc64_store_return_value (struct type *type, struct regcache *regcache,
       memcpy (buf, valbuf, len);
       for (i = 0; i < ((len + 7) / 8); i++)
        regcache->cooked_write (SPARC_O0_REGNUM + i, buf + i * 8);
-      if (TYPE_CODE (type) != TYPE_CODE_UNION)
+      if (type->code () != TYPE_CODE_UNION)
        sparc64_store_floating_fields (regcache, type, buf, 0, 0);
     }
   else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
@@ -1725,7 +1721,7 @@ sparc64_store_return_value (struct type *type, struct regcache *regcache,
       for (i = 0; i < len / 4; i++)
        regcache->cooked_write (SPARC_F0_REGNUM + i, buf + i * 4);
     }
-  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  else if (type->code () == TYPE_CODE_ARRAY)
     {
       /* Small arrays are returned the same way as small structures.  */
       gdb_assert (len <= 32);
This page took 0.050694 seconds and 4 git commands to generate.