AArch64: Add pointer authentication feature
[deliverable/binutils-gdb.git] / gdb / aarch64-tdep.c
index 023e8eb45393e48d0407bf149f34333769664756..0518837a1f992fd1a901d3d3c73e45faf5913f68 100644 (file)
@@ -1,6 +1,6 @@
 /* Common target dependent code for GDB on AArch64 systems.
 
-   Copyright (C) 2009-2018 Free Software Foundation, Inc.
+   Copyright (C) 2009-2019 Free Software Foundation, Inc.
    Contributed by ARM Ltd.
 
    This file is part of GDB.
 #include "infcall.h"
 #include "ax.h"
 #include "ax-gdb.h"
-#include "selftest.h"
+#include "common/selftest.h"
 
 #include "aarch64-tdep.h"
+#include "aarch64-ravenscar-thread.h"
 
 #include "elf-bfd.h"
 #include "elf/aarch64.h"
 
-#include "vec.h"
+#include "common/vec.h"
 
 #include "record.h"
 #include "record-full.h"
@@ -68,7 +69,7 @@
 #define HA_MAX_NUM_FLDS                4
 
 /* All possible aarch64 target descriptors.  */
-struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1];
+struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/];
 
 /* The standard register names, and all the valid aliases for them.  */
 static const struct
@@ -997,39 +998,6 @@ struct frame_base aarch64_normal_base =
   aarch64_normal_frame_base
 };
 
-/* Assuming THIS_FRAME is a dummy, return the frame ID of that
-   dummy frame.  The frame ID's base needs to match the TOS value
-   saved by save_dummy_frame_tos () and returned from
-   aarch64_push_dummy_call, and the PC needs to match the dummy
-   frame's breakpoint.  */
-
-static struct frame_id
-aarch64_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
-{
-  return frame_id_build (get_frame_register_unsigned (this_frame,
-                                                     AARCH64_SP_REGNUM),
-                        get_frame_pc (this_frame));
-}
-
-/* Implement the "unwind_pc" gdbarch method.  */
-
-static CORE_ADDR
-aarch64_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
-{
-  CORE_ADDR pc
-    = frame_unwind_register_unsigned (this_frame, AARCH64_PC_REGNUM);
-
-  return pc;
-}
-
-/* Implement the "unwind_sp" gdbarch method.  */
-
-static CORE_ADDR
-aarch64_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
-{
-  return frame_unwind_register_unsigned (this_frame, AARCH64_SP_REGNUM);
-}
-
 /* Return the value of the REGNUM register in the previous frame of
    *THIS_FRAME.  */
 
@@ -1211,7 +1179,7 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
            if (count == -1)
              return count;
 
-           count *= TYPE_LENGTH (type);
+           count *= (TYPE_LENGTH (type) / TYPE_LENGTH (target_type));
              return count;
          }
       }
@@ -1223,6 +1191,10 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
 
        for (int i = 0; i < TYPE_NFIELDS (type); i++)
          {
+           /* Ignore any static fields.  */
+           if (field_is_static (&TYPE_FIELD (type, i)))
+             continue;
+
            struct type *member = check_typedef (TYPE_FIELD_TYPE (type, i));
 
            int sub_count = aapcs_is_vfp_call_or_return_candidate_1
@@ -1231,6 +1203,14 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
              return -1;
            count += sub_count;
          }
+
+       /* Ensure there is no padding between the fields (allowing for empty
+          zero length structs)  */
+       int ftype_length = (*fundamental_type == nullptr)
+                          ? 0 : TYPE_LENGTH (*fundamental_type);
+       if (count * ftype_length != TYPE_LENGTH (type))
+         return -1;
+
        return count;
       }
 
@@ -1493,6 +1473,10 @@ pass_in_v_vfp_candidate (struct gdbarch *gdbarch, struct regcache *regcache,
     case TYPE_CODE_UNION:
       for (int i = 0; i < TYPE_NFIELDS (arg_type); i++)
        {
+         /* Don't include static fields.  */
+         if (field_is_static (&TYPE_FIELD (arg_type, i)))
+           continue;
+
          struct value *field = value_primitive_field (arg, 0, i, arg_type);
          struct type *field_type = check_typedef (value_type (field));
 
@@ -1513,14 +1497,12 @@ static CORE_ADDR
 aarch64_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,
+                        struct value **args, CORE_ADDR sp,
+                        function_call_return_method return_method,
                         CORE_ADDR struct_addr)
 {
   int argnum;
   struct aarch64_call_info info;
-  struct type *func_type;
-  struct type *return_type;
-  int lang_struct_return;
 
   memset (&info, 0, sizeof (info));
 
@@ -1542,42 +1524,21 @@ aarch64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
      If the language code decides to pass in memory we want to move
      the pointer inserted as the initial argument from the argument
      list and into X8, the conventional AArch64 struct return pointer
-     register.
-
-     This is slightly awkward, ideally the flag "lang_struct_return"
-     would be passed to the targets implementation of push_dummy_call.
-     Rather that change the target interface we call the language code
-     directly ourselves.  */
-
-  func_type = check_typedef (value_type (function));
-
-  /* Dereference function pointer types.  */
-  if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
-    func_type = TYPE_TARGET_TYPE (func_type);
-
-  gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
-             || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
-
-  /* If language_pass_by_reference () returned true we will have been
-     given an additional initial argument, a hidden pointer to the
-     return slot in memory.  */
-  return_type = TYPE_TARGET_TYPE (func_type);
-  lang_struct_return = language_pass_by_reference (return_type);
+     register.  */
 
   /* Set the return address.  For the AArch64, the return breakpoint
      is always at BP_ADDR.  */
   regcache_cooked_write_unsigned (regcache, AARCH64_LR_REGNUM, bp_addr);
 
-  /* If we were given an initial argument for the return slot because
-     lang_struct_return was true, lose it.  */
-  if (lang_struct_return)
+  /* If we were given an initial argument for the return slot, lose it.  */
+  if (return_method == return_method_hidden_param)
     {
       args++;
       nargs--;
     }
 
   /* The struct_return pointer occupies X8.  */
-  if (struct_return || lang_struct_return)
+  if (return_method != return_method_normal)
     {
       if (aarch64_debug)
        {
@@ -1954,7 +1915,7 @@ aarch64_extract_return_value (struct type *type, struct regcache *regs,
           || TYPE_IS_REFERENCE (type)
           || TYPE_CODE (type) == TYPE_CODE_ENUM)
     {
-      /* If the the type is a plain integer, then the access is
+      /* If the type is a plain integer, then the access is
         straight-forward.  Otherwise we have to play around a bit
         more.  */
       int len = TYPE_LENGTH (type);
@@ -2924,18 +2885,18 @@ aarch64_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
    (It is not possible to set VQ to zero on an SVE system).  */
 
 const target_desc *
-aarch64_read_description (uint64_t vq)
+aarch64_read_description (uint64_t vq, bool pauth_p)
 {
   if (vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq,
           AARCH64_MAX_SVE_VQ);
 
-  struct target_desc *tdesc = tdesc_aarch64_list[vq];
+  struct target_desc *tdesc = tdesc_aarch64_list[vq][pauth_p];
 
   if (tdesc == NULL)
     {
-      tdesc = aarch64_create_target_description (vq);
-      tdesc_aarch64_list[vq] = tdesc;
+      tdesc = aarch64_create_target_description (vq, pauth_p);
+      tdesc_aarch64_list[vq][pauth_p] = tdesc;
     }
 
   return tdesc;
@@ -2961,6 +2922,19 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
   return sve_vq_from_vl (vl);
 }
 
+/* Add all the expected register sets into GDBARCH.  */
+
+static void
+aarch64_add_reggroups (struct gdbarch *gdbarch)
+{
+  reggroup_add (gdbarch, general_reggroup);
+  reggroup_add (gdbarch, float_reggroup);
+  reggroup_add (gdbarch, system_reggroup);
+  reggroup_add (gdbarch, vector_reggroup);
+  reggroup_add (gdbarch, all_reggroup);
+  reggroup_add (gdbarch, save_reggroup);
+  reggroup_add (gdbarch, restore_reggroup);
+}
 
 /* Initialize the current architecture based on INFO.  If possible,
    re-use an architecture from ARCHES, which is a list of
@@ -2987,7 +2961,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Ensure we always have a target description.  */
   if (!tdesc_has_registers (tdesc))
-    tdesc = aarch64_read_description (0);
+    tdesc = aarch64_read_description (0, false);
   gdb_assert (tdesc);
 
   feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.core");
@@ -3084,11 +3058,6 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_push_dummy_call (gdbarch, aarch64_push_dummy_call);
   set_gdbarch_frame_align (gdbarch, aarch64_frame_align);
 
-  /* Frame handling.  */
-  set_gdbarch_dummy_id (gdbarch, aarch64_dummy_id);
-  set_gdbarch_unwind_pc (gdbarch, aarch64_unwind_pc);
-  set_gdbarch_unwind_sp (gdbarch, aarch64_unwind_sp);
-
   /* Advance PC across function entry code.  */
   set_gdbarch_skip_prologue (gdbarch, aarch64_skip_prologue);
 
@@ -3143,6 +3112,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Virtual tables.  */
   set_gdbarch_vbit_in_delta (gdbarch, 1);
 
+  /* Register architecture.  */
+  aarch64_add_reggroups (gdbarch);
+
   /* Hook in the ABI-specific overrides, if they have been registered.  */
   info.target_desc = tdesc;
   info.tdesc_data = tdesc_data;
@@ -3173,6 +3145,8 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
                  value_of_aarch64_user_reg,
                  &aarch64_register_aliases[i].regnum);
 
+  register_aarch64_ravenscar_ops (gdbarch);
+
   return gdbarch;
 }
 
@@ -3216,7 +3190,7 @@ When on, AArch64 specific debugging is enabled."),
   selftests::register_test ("aarch64-process-record",
                            selftests::aarch64_process_record_test);
   selftests::record_xml_tdesc ("aarch64.xml",
-                              aarch64_create_target_description (0));
+                              aarch64_create_target_description (0, false));
 #endif
 }
 
This page took 0.029888 seconds and 4 git commands to generate.