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

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