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

a909d0
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
a909d0
From: Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
a909d0
Date: Wed, 7 Jul 2021 19:05:04 -0400
a909d0
Subject: gdb-rhbz1854784-powerpc-remove-region-limit-dawr-6of7.patch
a909d0
a909d0
;; Backport "[PowerPC] Always clear watchpoint with PTRACE_SET_DEBUGREG"
a909d0
;; (Pedro Franco de Carvalho, RH BZ 1854784)
a909d0
a909d0
This patches changes low_prepare_to_resume in the ppc linux native target
a909d0
to always clear the watchpoint when the old PTRACE_SET_DEBUGREG interface
a909d0
is used, even if another watchpoint GDB requested to the target is
a909d0
written right after using the same call.
a909d0
a909d0
The reason for this is that there were some older kernel versions for
a909d0
which overwriting a watchpoint with PTRACE_SET_DEBUGREG would not
a909d0
re-activate the watchpoint if it was previouly disabled following a hit.
a909d0
This happened when the kernel was configured with CONFIG_HW_BREAKPOINT on
a909d0
and uses perf events to install watchpoints.
a909d0
a909d0
Previously, the ppc linux native target would immediately remove or
a909d0
insert watchpoints following a request from the upper layers.  This was
a909d0
changed in commit 227c0bf4b3dd0cf65dceb58e729e9da81b38b5a7 to fix other
a909d0
issues, which caused watchpoint requests to be applied to the inferior
a909d0
only in low_prepare_to_resume, right before the inferior is resumed.
a909d0
a909d0
Usually, but maybe not always, after a hit, GDB will remove the
a909d0
watchpoint, resume the inferior for a single-step, possibly report the
a909d0
watchpoint hit to the user, and then re-insert the watchpoint before the
a909d0
inferior is next resumed.  In this case there would be no problems, but
a909d0
since I can't guarantee that there aren't other paths in GDB that allow
a909d0
the user to set a new watchpoint after the first one hit, and after its
a909d0
deletion by GDB, but before the inferior is resumed, there is a chance
a909d0
that PTRACE_SET_DEBUGREG could be called directly without the watchpoint
a909d0
first having been cleared, which could cause a false negative with the
a909d0
older kernel versions.
a909d0
a909d0
This issue would affect kernel versions starting from this commit:
a909d0
a909d0
5aae8a53708025d4e718f0d2e7c2f766779ddc71
a909d0
a909d0
Up to the fix in this commit:
a909d0
a909d0
a53fd61ac2f411745471c1c877d5e072fbbf0e5c
a909d0
a909d0
gdb/ChangeLog:
a909d0
a909d0
	PR breakpoints/26385
a909d0
	* ppc-linux-nat.c (ppc_linux_nat_target::low_prepare_to_resume):
a909d0
	Always clear watchpoint with PTRACE_SET_DEBUGREG.
a909d0
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
@@ -2922,20 +2922,23 @@ ppc_linux_nat_target::low_prepare_to_resume (struct lwp_info *lp)
a909d0
     {
a909d0
       gdb_assert (m_dreg_interface.debugreg_p ());
a909d0
 
a909d0
-      /* Passing 0 to PTRACE_SET_DEBUGREG will clear the
a909d0
-	 watchpoint.  */
a909d0
-      long wp = 0;
a909d0
+      /* Passing 0 to PTRACE_SET_DEBUGREG will clear the watchpoint.  We
a909d0
+	 always clear the watchpoint instead of just overwriting it, in
a909d0
+	 case there is a request for a new watchpoint, because on some
a909d0
+	 older kernel versions and configurations simply overwriting the
a909d0
+	 watchpoint after it was hit would not re-enable it.  */
a909d0
+      if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, 0) < 0)
a909d0
+	perror_with_name (_("Error clearing hardware watchpoint"));
a909d0
 
a909d0
       /* GDB requested a watchpoint to be installed.  */
a909d0
       if (process_it != m_process_info.end ()
a909d0
 	  && process_it->second.requested_wp_val.has_value ())
a909d0
-	wp = *(process_it->second.requested_wp_val);
a909d0
-
a909d0
-      long ret = ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (),
a909d0
-			 0, wp);
a909d0
+	{
a909d0
+	  long wp = *(process_it->second.requested_wp_val);
a909d0
 
a909d0
-      if (ret < 0)
a909d0
-	perror_with_name (_("Error setting hardware watchpoint"));
a909d0
+	  if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, wp) < 0)
a909d0
+	    perror_with_name (_("Error setting hardware watchpoint"));
a909d0
+	}
a909d0
     }
a909d0
 
a909d0
   lp_arch_info->debug_regs_stale = false;