Add linux_get_hwcap
authorAlan Hayward <alan.hayward@arm.com>
Mon, 25 Mar 2019 16:48:03 +0000 (16:48 +0000)
committerAlan Hayward <alan.hayward@arm.com>
Mon, 25 Mar 2019 16:50:38 +0000 (16:50 +0000)
Tidy up calls to read HWCAP (and HWCAP2) by adding common functions,
removing the PPC and AArch64 specific versions.

The only function difference is in aarch64_linux_core_read_description - if
the hwcap read fails it now return a valid description instead of nullptr.

gdb/ChangeLog:

2019-03-25  Alan Hayward  <alan.hayward@arm.com>

* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
Call linux_get_hwcap.
* aarch64-linux-tdep.c (aarch64_linux_core_read_description):
Likewise.
(aarch64_linux_get_hwcap): Remove function.
* aarch64-linux-tdep.h (aarch64_linux_get_hwcap): Remove
declaration.
* arm-linux-nat.c (arm_linux_nat_target::read_description):Call
linux_get_hwcap.
* arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
* linux-tdep.c (linux_get_hwcap): Add function.
(linux_get_hwcap2): Likewise.
* linux-tdep.h (linux_get_hwcap): Add declaration.
(linux_get_hwcap2): Likewise.
* ppc-linux-nat.c (ppc_linux_get_hwcap): Remove function.
(ppc_linux_get_hwcap2): Likewise.
(ppc_linux_nat_target::region_ok_for_hw_watchpoint): Call
linux_get_hwcap.
(ppc_linux_nat_target::insert_watchpoint): Likewise.
(ppc_linux_nat_target::watchpoint_addr_within_range): Likewise.
(ppc_linux_nat_target::read_description): Likewise.
* ppc-linux-tdep.c (ppc_linux_core_read_description): Likewise.
* s390-linux-nat.c: Likewise.
* s390-linux-tdep.c (s390_core_read_description): Likewise.

12 files changed:
gdb/ChangeLog
gdb/aarch64-linux-nat.c
gdb/aarch64-linux-tdep.c
gdb/aarch64-linux-tdep.h
gdb/arm-linux-nat.c
gdb/arm-linux-tdep.c
gdb/linux-tdep.c
gdb/linux-tdep.h
gdb/ppc-linux-nat.c
gdb/ppc-linux-tdep.c
gdb/s390-linux-nat.c
gdb/s390-linux-tdep.c

index 2f63bc3ef0658419f6c5c4b89ac6ac7e6aedf58d..38a1fdba1f2a92d8c3dd8081b7aa045b74929083 100644 (file)
@@ -1,3 +1,30 @@
+2019-03-25  Alan Hayward  <alan.hayward@arm.com>
+
+       * aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
+       Call linux_get_hwcap.
+       * aarch64-linux-tdep.c (aarch64_linux_core_read_description):
+       Likewise.
+       (aarch64_linux_get_hwcap): Remove function.
+       * aarch64-linux-tdep.h (aarch64_linux_get_hwcap): Remove
+       declaration.
+       * arm-linux-nat.c (arm_linux_nat_target::read_description):Call
+       linux_get_hwcap.
+       * arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
+       * linux-tdep.c (linux_get_hwcap): Add function.
+       (linux_get_hwcap2): Likewise.
+       * linux-tdep.h (linux_get_hwcap): Add declaration.
+       (linux_get_hwcap2): Likewise.
+       * ppc-linux-nat.c (ppc_linux_get_hwcap): Remove function.
+       (ppc_linux_get_hwcap2): Likewise.
+       (ppc_linux_nat_target::region_ok_for_hw_watchpoint): Call
+       linux_get_hwcap.
+       (ppc_linux_nat_target::insert_watchpoint): Likewise.
+       (ppc_linux_nat_target::watchpoint_addr_within_range): Likewise.
+       (ppc_linux_nat_target::read_description): Likewise.
+       * ppc-linux-tdep.c (ppc_linux_core_read_description): Likewise.
+       * s390-linux-nat.c: Likewise.
+       * s390-linux-tdep.c (s390_core_read_description): Likewise.
+
 2019-03-24  Tom Tromey  <tom@tromey.com>
 
        * ada-lang.c (standard_lookup): Simplify initialization.
index 86c7e87dd5e087436a557bfcf760b68b5379d4cf..6d43eb7070f17768f324fe950bc7a0f278d190d8 100644 (file)
@@ -42,6 +42,7 @@
 #include <asm/ptrace.h>
 
 #include "gregset.h"
+#include "linux-tdep.h"
 
 /* Defines ps_err_e, struct ps_prochandle.  */
 #include "gdb_proc_service.h"
@@ -641,11 +642,10 @@ aarch64_linux_nat_target::read_description ()
   if (ret == 0)
     return tdesc_arm_with_neon;
 
-  CORE_ADDR hwcap = 0;
-  bool pauth_p = aarch64_linux_get_hwcap (this, &hwcap)
-                && (hwcap & AARCH64_HWCAP_PACA);
+  CORE_ADDR hwcap = linux_get_hwcap (this);
 
-  return aarch64_read_description (aarch64_sve_get_vq (tid), pauth_p);
+  return aarch64_read_description (aarch64_sve_get_vq (tid),
+                                  hwcap & AARCH64_HWCAP_PACA);
 }
 
 /* Convert a native/host siginfo object, into/from the siginfo in the
index bcd1961744dbb9dfe22653817f38ca85618a9c52..7f2193f2fa5781ef4ee1f78828f749efa5671f8b 100644 (file)
@@ -655,13 +655,10 @@ static const struct target_desc *
 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
                                     struct target_ops *target, bfd *abfd)
 {
-  CORE_ADDR aarch64_hwcap = 0;
-
-  if (!aarch64_linux_get_hwcap (target, &aarch64_hwcap))
-    return nullptr;
+  CORE_ADDR hwcap = linux_get_hwcap (target);
 
   return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
-                                  aarch64_hwcap & AARCH64_HWCAP_PACA);
+                                  hwcap & AARCH64_HWCAP_PACA);
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
@@ -1439,15 +1436,6 @@ aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
   return NULL;
 }
 
-/* See aarch64-linux-tdep.h.  */
-
-bool
-aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap)
-{
-  *hwcap = 0;
-  return target_auxv_search (target, AT_HWCAP, hwcap) == 1;
-}
-
 static void
 aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
index ec494bfc5387ac47a5b979998e3541fbaad08c12..f075f0acd94bb54b0aa518c0e1f8bf1e164a556e 100644 (file)
@@ -42,7 +42,4 @@ extern const struct regset aarch64_linux_fpregset;
 /* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
 #define AARCH64_HWCAP_PACA (1 << 30)
 
-/* Fetch the AT_HWCAP entry from the auxv vector for the given TARGET.  */
-bool aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap);
-
 #endif /* AARCH64_LINUX_TDEP_H */
index 11e353e61cd6c073f2ee0efa1efc67668c793e3f..b54bd5afe9a88449965968911b083d1b123881a4 100644 (file)
@@ -533,7 +533,7 @@ ps_get_thread_area (struct ps_prochandle *ph,
 const struct target_desc *
 arm_linux_nat_target::read_description ()
 {
-  CORE_ADDR arm_hwcap = 0;
+  CORE_ADDR arm_hwcap = linux_get_hwcap (this);
 
   if (have_ptrace_getregset == TRIBOOL_UNKNOWN)
     {
@@ -551,11 +551,6 @@ arm_linux_nat_target::read_description ()
        have_ptrace_getregset = TRIBOOL_TRUE;
     }
 
-  if (target_auxv_search (this, AT_HWCAP, &arm_hwcap) != 1)
-    {
-      return this->beneath ()->read_description ();
-    }
-
   if (arm_hwcap & HWCAP_IWMMXT)
     return tdesc_arm_with_iwmmxt;
 
index 11db9bae32d38d5ef97e78b0c80db5a631e84449..a5ad06434c230ed2e0af42ec5aa3694d28361b7d 100644 (file)
@@ -730,10 +730,7 @@ arm_linux_core_read_description (struct gdbarch *gdbarch,
                                  struct target_ops *target,
                                  bfd *abfd)
 {
-  CORE_ADDR arm_hwcap = 0;
-
-  if (target_auxv_search (target, AT_HWCAP, &arm_hwcap) != 1)
-    return NULL;
+  CORE_ADDR arm_hwcap = linux_get_hwcap (target);
 
   if (arm_hwcap & HWCAP_VFP)
     {
index 77bc7142865ea196a4d96c7ac3c2036e38deca6e..f6c4f7b2081d727874d60d4f382121e600324cbe 100644 (file)
@@ -2462,6 +2462,28 @@ linux_displaced_step_location (struct gdbarch *gdbarch)
   return addr;
 }
 
+/* See linux-tdep.h.  */
+
+CORE_ADDR
+linux_get_hwcap (struct target_ops *target)
+{
+  CORE_ADDR field;
+  if (target_auxv_search (target, AT_HWCAP, &field) != 1)
+    return 0;
+  return field;
+}
+
+/* See linux-tdep.h.  */
+
+CORE_ADDR
+linux_get_hwcap2 (struct target_ops *target)
+{
+  CORE_ADDR field;
+  if (target_auxv_search (target, AT_HWCAP2, &field) != 1)
+    return 0;
+  return field;
+}
+
 /* Display whether the gcore command is using the
    /proc/PID/coredump_filter file.  */
 
index 824ba3afaf4093fb7e032ae6dd8c88f1429e0782..913045a954e6d97a40811f3b12ae56af291b9d2c 100644 (file)
@@ -61,4 +61,12 @@ extern void linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
 
 extern int linux_is_uclinux (void);
 
+/* Fetch the AT_HWCAP entry from the auxv vector for the given TARGET.  On
+   error, 0 is returned.  */
+extern CORE_ADDR linux_get_hwcap (struct target_ops *target);
+
+/* Fetch the AT_HWCAP2 entry from the auxv vector for the given TARGET.  On
+   error, 0 is returned.  */
+extern CORE_ADDR linux_get_hwcap2 (struct target_ops *target);
+
 #endif /* linux-tdep.h */
index 11394ef36deaef3247933525f94993b641484485..3a6bbf416356bbe59c4fcc2c3b2148ba8ed0724a 100644 (file)
@@ -1554,31 +1554,6 @@ store_ppc_registers (const struct regcache *regcache, int tid)
      function to fail most of the time, so we ignore them.  */
 }
 
-/* Fetch the AT_HWCAP entry from the aux vector.  */
-static CORE_ADDR
-ppc_linux_get_hwcap (void)
-{
-  CORE_ADDR field;
-
-  if (target_auxv_search (current_top_target (), AT_HWCAP, &field) != 1)
-    return 0;
-
-  return field;
-}
-
-/* Fetch the AT_HWCAP2 entry from the aux vector.  */
-
-static CORE_ADDR
-ppc_linux_get_hwcap2 (void)
-{
-  CORE_ADDR field;
-
-  if (target_auxv_search (current_top_target (), AT_HWCAP2, &field) != 1)
-    return 0;
-
-  return field;
-}
-
 /* The cached DABR value, to install in new threads.
    This variable is used when the PowerPC HWDEBUG ptrace
    interface is not available.  */
@@ -1735,7 +1710,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
          takes two hardware watchpoints though.  */
       if (len > 1
          && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
-         && ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
+         && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
        return 2;
       /* Check if the processor provides DAWR interface.  */
       if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
@@ -1755,7 +1730,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
      ptrace interface, DAC-based processors (i.e., embedded processors) will
      use addresses aligned to 4-bytes due to the way the read/write flags are
      passed in the old ptrace interface.  */
-  else if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
+  else if (((linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
           && (addr + len) > (addr & ~3) + 4)
           || (addr + len) > (addr & ~7) + 8)
     return 0;
@@ -2294,7 +2269,7 @@ ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
       long dabr_value;
       long read_mode, write_mode;
 
-      if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
+      if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
        {
          /* PowerPC 440 requires only the read/write flags to be passed
             to the kernel.  */
@@ -2497,9 +2472,9 @@ ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
   int mask;
 
   if (have_ptrace_hwdebug_interface ()
-      && ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
+      && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
     return start <= addr && start + length >= addr;
-  else if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
+  else if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
     mask = 3;
   else
     mask = 7;
@@ -2637,8 +2612,8 @@ ppc_linux_nat_target::read_description ()
 
   features.wordsize = ppc_linux_target_wordsize (tid);
 
-  CORE_ADDR hwcap = ppc_linux_get_hwcap ();
-  CORE_ADDR hwcap2 = ppc_linux_get_hwcap2 ();
+  CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
+  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_top_target ());
 
   if (have_ptrace_getsetvsxregs
       && (hwcap & PPC_FEATURE_HAS_VSX))
index df44ad826e72eb8add9bf5545c4ffa5e035e9b94..19435602b5a1fc8e9336d0cc1b2f86a6b176d92f 100644 (file)
@@ -1601,10 +1601,7 @@ ppc_linux_core_read_description (struct gdbarch *gdbarch,
   if (vsx)
     features.vsx = true;
 
-  CORE_ADDR hwcap;
-
-  if (target_auxv_search (target, AT_HWCAP, &hwcap) != 1)
-    hwcap = 0;
+  CORE_ADDR hwcap = linux_get_hwcap (target);
 
   features.isa205 = ppc_linux_has_isa205 (hwcap);
 
index 5f6c5be8e023a8f0d092816856df5efecdb8526d..3a3afae7a6ea7569ec8cf4dbabc681ab39f7ae92 100644 (file)
@@ -1016,9 +1016,8 @@ s390_linux_nat_target::read_description ()
      that mode, report s390 architecture with 64-bit GPRs.  */
 #ifdef __s390x__
   {
-    CORE_ADDR hwcap = 0;
+    CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
 
-    target_auxv_search (current_top_target (), AT_HWCAP, &hwcap);
     have_regset_tdb = (hwcap & HWCAP_S390_TE)
       && check_regset (tid, NT_S390_TDB, s390_sizeof_tdbregset);
 
index 64fe7abd80e519a2229b0cd3e6b646e2928c85ef..02ae28b4ea7675b23b3c4cd24d3caf7b99bcf8a9 100644 (file)
@@ -332,10 +332,9 @@ s390_core_read_description (struct gdbarch *gdbarch,
                            struct target_ops *target, bfd *abfd)
 {
   asection *section = bfd_get_section_by_name (abfd, ".reg");
-  CORE_ADDR hwcap = 0;
+  CORE_ADDR hwcap = linux_get_hwcap (target);
   bool high_gprs, v1, v2, te, vx, gs;
 
-  target_auxv_search (target, AT_HWCAP, &hwcap);
   if (!section)
     return NULL;
 
This page took 0.039156 seconds and 4 git commands to generate.