Blame SOURCES/gdb-rhbz1854784-powerpc-remove-region-limit-dawr-2of7.patch

599b31
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
599b31
From: Alan Hayward <alan.hayward@arm.com>
599b31
Date: Wed, 7 Jul 2021 18:13:44 -0400
599b31
Subject: gdb-rhbz1854784-powerpc-remove-region-limit-dawr-2of7.patch
599b31
599b31
;; Backport "Add linux_get_hwcap"
599b31
;; (Alan Hayward, RH BZ 1854784)
599b31
599b31
Tidy up calls to read HWCAP (and HWCAP2) by adding common functions,
599b31
removing the PPC and AArch64 specific versions.
599b31
599b31
The only function difference is in aarch64_linux_core_read_description - if
599b31
the hwcap read fails it now return a valid description instead of nullptr.
599b31
599b31
gdb/ChangeLog:
599b31
599b31
2019-03-25  Alan Hayward  <alan.hayward@arm.com>
599b31
599b31
	* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
599b31
	Call linux_get_hwcap.
599b31
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description):
599b31
	Likewise.
599b31
	(aarch64_linux_get_hwcap): Remove function.
599b31
	* aarch64-linux-tdep.h (aarch64_linux_get_hwcap): Remove
599b31
	declaration.
599b31
	* arm-linux-nat.c (arm_linux_nat_target::read_description):Call
599b31
	linux_get_hwcap.
599b31
	* arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
599b31
	* linux-tdep.c (linux_get_hwcap): Add function.
599b31
	(linux_get_hwcap2): Likewise.
599b31
	* linux-tdep.h (linux_get_hwcap): Add declaration.
599b31
	(linux_get_hwcap2): Likewise.
599b31
	* ppc-linux-nat.c (ppc_linux_get_hwcap): Remove function.
599b31
	(ppc_linux_get_hwcap2): Likewise.
599b31
	(ppc_linux_nat_target::region_ok_for_hw_watchpoint): Call
599b31
	linux_get_hwcap.
599b31
	(ppc_linux_nat_target::insert_watchpoint): Likewise.
599b31
	(ppc_linux_nat_target::watchpoint_addr_within_range): Likewise.
599b31
	(ppc_linux_nat_target::read_description): Likewise.
599b31
	* ppc-linux-tdep.c (ppc_linux_core_read_description): Likewise.
599b31
	* s390-linux-nat.c: Likewise.
599b31
	* s390-linux-tdep.c (s390_core_read_description): Likewise.
599b31
599b31
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
599b31
--- a/gdb/aarch64-linux-nat.c
599b31
+++ b/gdb/aarch64-linux-nat.c
599b31
@@ -42,6 +42,7 @@
599b31
 #include <asm/ptrace.h>
599b31
 
599b31
 #include "gregset.h"
599b31
+#include "linux-tdep.h"
599b31
 
599b31
 /* Defines ps_err_e, struct ps_prochandle.  */
599b31
 #include "gdb_proc_service.h"
599b31
@@ -605,8 +606,7 @@ aarch64_linux_nat_target::read_description ()
599b31
   ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
599b31
   if (ret == 0)
599b31
     return tdesc_arm_with_neon;
599b31
-  else
599b31
-    return aarch64_read_description (aarch64_sve_get_vq (tid));
599b31
+  else return aarch64_read_description (aarch64_sve_get_vq (tid));
599b31
 }
599b31
 
599b31
 /* Convert a native/host siginfo object, into/from the siginfo in the
599b31
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
599b31
--- a/gdb/aarch64-linux-tdep.c
599b31
+++ b/gdb/aarch64-linux-tdep.c
599b31
@@ -442,10 +442,7 @@ static const struct target_desc *
599b31
 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
599b31
 				     struct target_ops *target, bfd *abfd)
599b31
 {
599b31
-  CORE_ADDR aarch64_hwcap = 0;
599b31
-
599b31
-  if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
599b31
-    return NULL;
599b31
+  CORE_ADDR hwcap = linux_get_hwcap (target);
599b31
 
599b31
   return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd));
599b31
 }
599b31
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
599b31
--- a/gdb/arm-linux-nat.c
599b31
+++ b/gdb/arm-linux-nat.c
599b31
@@ -533,7 +533,7 @@ ps_get_thread_area (struct ps_prochandle *ph,
599b31
 const struct target_desc *
599b31
 arm_linux_nat_target::read_description ()
599b31
 {
599b31
-  CORE_ADDR arm_hwcap = 0;
599b31
+  CORE_ADDR arm_hwcap = linux_get_hwcap (this);
599b31
 
599b31
   if (have_ptrace_getregset == TRIBOOL_UNKNOWN)
599b31
     {
599b31
@@ -551,11 +551,6 @@ arm_linux_nat_target::read_description ()
599b31
 	have_ptrace_getregset = TRIBOOL_TRUE;
599b31
     }
599b31
 
599b31
-  if (target_auxv_search (this, AT_HWCAP, &arm_hwcap) != 1)
599b31
-    {
599b31
-      return this->beneath ()->read_description ();
599b31
-    }
599b31
-
599b31
   if (arm_hwcap & HWCAP_IWMMXT)
599b31
     return tdesc_arm_with_iwmmxt;
599b31
 
599b31
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
599b31
--- a/gdb/arm-linux-tdep.c
599b31
+++ b/gdb/arm-linux-tdep.c
599b31
@@ -730,10 +730,7 @@ arm_linux_core_read_description (struct gdbarch *gdbarch,
599b31
                                  struct target_ops *target,
599b31
                                  bfd *abfd)
599b31
 {
599b31
-  CORE_ADDR arm_hwcap = 0;
599b31
-
599b31
-  if (target_auxv_search (target, AT_HWCAP, &arm_hwcap) != 1)
599b31
-    return NULL;
599b31
+  CORE_ADDR arm_hwcap = linux_get_hwcap (target);
599b31
 
599b31
   if (arm_hwcap & HWCAP_VFP)
599b31
     {
599b31
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
599b31
--- a/gdb/linux-tdep.c
599b31
+++ b/gdb/linux-tdep.c
599b31
@@ -2567,6 +2567,28 @@ linux_displaced_step_location (struct gdbarch *gdbarch)
599b31
   return addr;
599b31
 }
599b31
 
599b31
+/* See linux-tdep.h.  */
599b31
+
599b31
+CORE_ADDR
599b31
+linux_get_hwcap (struct target_ops *target)
599b31
+{
599b31
+  CORE_ADDR field;
599b31
+  if (target_auxv_search (target, AT_HWCAP, &field) != 1)
599b31
+    return 0;
599b31
+  return field;
599b31
+}
599b31
+
599b31
+/* See linux-tdep.h.  */
599b31
+
599b31
+CORE_ADDR
599b31
+linux_get_hwcap2 (struct target_ops *target)
599b31
+{
599b31
+  CORE_ADDR field;
599b31
+  if (target_auxv_search (target, AT_HWCAP2, &field) != 1)
599b31
+    return 0;
599b31
+  return field;
599b31
+}
599b31
+
599b31
 /* Display whether the gcore command is using the
599b31
    /proc/PID/coredump_filter file.  */
599b31
 
599b31
diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h
599b31
--- a/gdb/linux-tdep.h
599b31
+++ b/gdb/linux-tdep.h
599b31
@@ -61,4 +61,12 @@ extern void linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
599b31
 
599b31
 extern int linux_is_uclinux (void);
599b31
 
599b31
+/* Fetch the AT_HWCAP entry from the auxv vector for the given TARGET.  On
599b31
+   error, 0 is returned.  */
599b31
+extern CORE_ADDR linux_get_hwcap (struct target_ops *target);
599b31
+
599b31
+/* Fetch the AT_HWCAP2 entry from the auxv vector for the given TARGET.  On
599b31
+   error, 0 is returned.  */
599b31
+extern CORE_ADDR linux_get_hwcap2 (struct target_ops *target);
599b31
+
599b31
 #endif /* linux-tdep.h */
599b31
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
599b31
--- a/gdb/ppc-linux-nat.c
599b31
+++ b/gdb/ppc-linux-nat.c
599b31
@@ -50,6 +50,7 @@
599b31
 #include "arch/ppc-linux-common.h"
599b31
 #include "arch/ppc-linux-tdesc.h"
599b31
 #include "nat/ppc-linux.h"
599b31
+#include "linux-tdep.h"
599b31
 
599b31
 /* Similarly for the hardware watchpoint support.  These requests are used
599b31
    when the PowerPC HWDEBUG ptrace interface is not available.  */
599b31
@@ -1560,31 +1561,6 @@ store_ppc_registers (const struct regcache *regcache, int tid)
599b31
      function to fail most of the time, so we ignore them.  */
599b31
 }
599b31
 
599b31
-/* Fetch the AT_HWCAP entry from the aux vector.  */
599b31
-static CORE_ADDR
599b31
-ppc_linux_get_hwcap (void)
599b31
-{
599b31
-  CORE_ADDR field;
599b31
-
599b31
-  if (target_auxv_search (current_top_target (), AT_HWCAP, &field) != 1)
599b31
-    return 0;
599b31
-
599b31
-  return field;
599b31
-}
599b31
-
599b31
-/* Fetch the AT_HWCAP2 entry from the aux vector.  */
599b31
-
599b31
-static CORE_ADDR
599b31
-ppc_linux_get_hwcap2 (void)
599b31
-{
599b31
-  CORE_ADDR field;
599b31
-
599b31
-  if (target_auxv_search (current_top_target (), AT_HWCAP2, &field) != 1)
599b31
-    return 0;
599b31
-
599b31
-  return field;
599b31
-}
599b31
-
599b31
 /* The cached DABR value, to install in new threads.
599b31
    This variable is used when the PowerPC HWDEBUG ptrace
599b31
    interface is not available.  */
599b31
@@ -1741,7 +1717,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, LONGEST len)
599b31
          takes two hardware watchpoints though.  */
599b31
       if (len > 1
599b31
 	  && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
599b31
-	  && ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
599b31
+	  && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
599b31
 	return 2;
599b31
       /* Check if the processor provides DAWR interface.  */
599b31
       if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
599b31
@@ -1761,7 +1737,7 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, LONGEST len)
599b31
      ptrace interface, DAC-based processors (i.e., embedded processors) will
599b31
      use addresses aligned to 4-bytes due to the way the read/write flags are
599b31
      passed in the old ptrace interface.  */
599b31
-  else if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
599b31
+  else if (((linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
599b31
 	   && (addr + len) > (addr & ~3) + 4)
599b31
 	   || (addr + len) > (addr & ~7) + 8)
599b31
     return 0;
599b31
@@ -2303,7 +2279,7 @@ ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
599b31
       long dabr_value;
599b31
       long read_mode, write_mode;
599b31
 
599b31
-      if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
599b31
+      if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
599b31
 	{
599b31
 	  /* PowerPC 440 requires only the read/write flags to be passed
599b31
 	     to the kernel.  */
599b31
@@ -2506,9 +2482,9 @@ ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
599b31
   int mask;
599b31
 
599b31
   if (have_ptrace_hwdebug_interface ()
599b31
-      && ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
599b31
+      && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
599b31
     return start <= addr && start + length >= addr;
599b31
-  else if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
599b31
+  else if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
599b31
     mask = 3;
599b31
   else
599b31
     mask = 7;
599b31
@@ -2646,8 +2622,8 @@ ppc_linux_nat_target::read_description ()
599b31
 
599b31
   features.wordsize = ppc_linux_target_wordsize (tid);
599b31
 
599b31
-  CORE_ADDR hwcap = ppc_linux_get_hwcap ();
599b31
-  CORE_ADDR hwcap2 = ppc_linux_get_hwcap2 ();
599b31
+  CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
599b31
+  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_top_target ());
599b31
 
599b31
   if (have_ptrace_getsetvsxregs
599b31
       && (hwcap & PPC_FEATURE_HAS_VSX))
599b31
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
599b31
--- a/gdb/ppc-linux-tdep.c
599b31
+++ b/gdb/ppc-linux-tdep.c
599b31
@@ -1602,10 +1602,7 @@ ppc_linux_core_read_description (struct gdbarch *gdbarch,
599b31
   if (vsx)
599b31
     features.vsx = true;
599b31
 
599b31
-  CORE_ADDR hwcap;
599b31
-
599b31
-  if (target_auxv_search (target, AT_HWCAP, &hwcap) != 1)
599b31
-    hwcap = 0;
599b31
+  CORE_ADDR hwcap = linux_get_hwcap (target);
599b31
 
599b31
   features.isa205 = ppc_linux_has_isa205 (hwcap);
599b31
 
599b31
diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
599b31
--- a/gdb/s390-linux-nat.c
599b31
+++ b/gdb/s390-linux-nat.c
599b31
@@ -42,6 +42,7 @@
599b31
 #include <elf.h>
599b31
 #include <algorithm>
599b31
 #include "inf-ptrace.h"
599b31
+#include "linux-tdep.h"
599b31
 
599b31
 /* Per-thread arch-specific data.  */
599b31
 
599b31
@@ -1018,9 +1019,8 @@ s390_linux_nat_target::read_description ()
599b31
      that mode, report s390 architecture with 64-bit GPRs.  */
599b31
 #ifdef __s390x__
599b31
   {
599b31
-    CORE_ADDR hwcap = 0;
599b31
+    CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
599b31
 
599b31
-    target_auxv_search (current_top_target (), AT_HWCAP, &hwcap);
599b31
     have_regset_tdb = (hwcap & HWCAP_S390_TE)
599b31
       && check_regset (tid, NT_S390_TDB, s390_sizeof_tdbregset);
599b31
 
599b31
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
599b31
--- a/gdb/s390-linux-tdep.c
599b31
+++ b/gdb/s390-linux-tdep.c
599b31
@@ -332,10 +332,9 @@ s390_core_read_description (struct gdbarch *gdbarch,
599b31
 			    struct target_ops *target, bfd *abfd)
599b31
 {
599b31
   asection *section = bfd_get_section_by_name (abfd, ".reg");
599b31
-  CORE_ADDR hwcap = 0;
599b31
+  CORE_ADDR hwcap = linux_get_hwcap (target);
599b31
   bool high_gprs, v1, v2, te, vx, gs;
599b31
 
599b31
-  target_auxv_search (target, AT_HWCAP, &hwcap);
599b31
   if (!section)
599b31
     return NULL;
599b31