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

599b31
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
599b31
From: Rogerio Alves <rcardoso@linux.ibm.com>
599b31
Date: Wed, 7 Jul 2021 19:06:52 -0400
599b31
Subject: gdb-rhbz1854784-powerpc-remove-region-limit-dawr-7of7.patch
599b31
599b31
;; Backport "PowerPC remove 512 bytes region limit if 2nd DAWR is available."
599b31
;; (Rogerio Alves, RH BZ 1854784)
599b31
599b31
Power 10 introduces the 2nd DAWR (second watchpoint) and also removed
599b31
a restriction that limit the watch region to 512 bytes.
599b31
599b31
2020-11-08  Rogerio A. Cardoso  <rcardoso@linux.ibm.com>
599b31
599b31
/gdb
599b31
599b31
	* ppc-linux-nat.c: (PPC_DEBUG_FEATURE_DATA_BP_ARCH_31): New define.
599b31
	(region_ok_for_hw_watchpoint): Check if 2nd DAWR is avaliable before
599b31
	set region.
599b31
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
@@ -144,6 +144,11 @@ struct ppc_hw_breakpoint
599b31
 #define PPC_DEBUG_FEATURE_DATA_BP_DAWR	0x10
599b31
 #endif /* PPC_DEBUG_FEATURE_DATA_BP_DAWR */
599b31
 
599b31
+/* Feature defined on Linux kernel v5.1: Second watchpoint support.  */
599b31
+#ifndef PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
599b31
+#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
599b31
+#endif /* PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 */
599b31
+
599b31
 /* The version of the PowerPC HWDEBUG kernel interface that we will use, if
599b31
    available.  */
599b31
 #define PPC_DEBUG_CURRENT_VERSION 1
599b31
@@ -2121,9 +2126,10 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
599b31
      watchpoints.  */
599b31
   if (m_dreg_interface.hwdebug_p ())
599b31
     {
599b31
-      int region_size;
599b31
       const struct ppc_debug_info &hwdebug_info = (m_dreg_interface
599b31
 						   .hwdebug_info ());
599b31
+      int region_size = hwdebug_info.data_bp_alignment;
599b31
+      int region_align = region_size;
599b31
 
599b31
       /* Embedded DAC-based processors, like the PowerPC 440 have ranged
599b31
 	 watchpoints and can watch any access within an arbitrary memory
599b31
@@ -2135,15 +2141,19 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
599b31
 	return 2;
599b31
       /* Check if the processor provides DAWR interface.  */
599b31
       if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
599b31
-	/* DAWR interface allows to watch up to 512 byte wide ranges which
599b31
-	   can't cross a 512 byte boundary.  */
599b31
-	region_size = 512;
599b31
-      else
599b31
-	region_size = hwdebug_info.data_bp_alignment;
599b31
+	{
599b31
+	  /* DAWR interface allows to watch up to 512 byte wide ranges.  */
599b31
+	  region_size = 512;
599b31
+	  /* DAWR interface allows to watch up to 512 byte wide ranges which
599b31
+	     can't cross a 512 byte bondary on machines that doesn't have a
599b31
+	     second DAWR (P9 or less).  */
599b31
+	  if (!(hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_ARCH_31))
599b31
+	    region_align = 512;
599b31
+	}
599b31
       /* Server processors provide one hardware watchpoint and addr+len should
599b31
          fall in the watchable region provided by the ptrace interface.  */
599b31
-      if (region_size
599b31
-	  && (addr + len > (addr & ~(region_size - 1)) + region_size))
599b31
+      if (region_align
599b31
+	  && (addr + len > (addr & ~(region_align - 1)) + region_size))
599b31
 	return 0;
599b31
     }
599b31
   /* addr+len must fall in the 8 byte watchable region for DABR-based