aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Franco de Carvalho <pedromfc@linux.ibm.com>2020-08-14 15:41:14 -0300
committerPedro Franco de Carvalho <pedromfc@linux.ibm.com>2020-08-14 15:41:14 -0300
commit6ea815e78134babf819920845e537d2e2f2abbc1 (patch)
treefd22594375252e1655893e380148c5a3a68dd3ce
parent6e562fa3ba95b5415b269410137c0ca3e620a08d (diff)
downloadgdb-6ea815e78134babf819920845e537d2e2f2abbc1.zip
gdb-6ea815e78134babf819920845e537d2e2f2abbc1.tar.gz
gdb-6ea815e78134babf819920845e537d2e2f2abbc1.tar.bz2
[PowerPC] Always clear watchpoint with PTRACE_SET_DEBUGREG
This patches changes low_prepare_to_resume in the ppc linux native target to always clear the watchpoint when the old PTRACE_SET_DEBUGREG interface is used, even if another watchpoint GDB requested to the target is written right after using the same call. The reason for this is that there were some older kernel versions for which overwriting a watchpoint with PTRACE_SET_DEBUGREG would not re-activate the watchpoint if it was previouly disabled following a hit. This happened when the kernel was configured with CONFIG_HW_BREAKPOINT on and uses perf events to install watchpoints. Previously, the ppc linux native target would immediately remove or insert watchpoints following a request from the upper layers. This was changed in commit 227c0bf4b3dd0cf65dceb58e729e9da81b38b5a7 to fix other issues, which caused watchpoint requests to be applied to the inferior only in low_prepare_to_resume, right before the inferior is resumed. Usually, but maybe not always, after a hit, GDB will remove the watchpoint, resume the inferior for a single-step, possibly report the watchpoint hit to the user, and then re-insert the watchpoint before the inferior is next resumed. In this case there would be no problems, but since I can't guarantee that there aren't other paths in GDB that allow the user to set a new watchpoint after the first one hit, and after its deletion by GDB, but before the inferior is resumed, there is a chance that PTRACE_SET_DEBUGREG could be called directly without the watchpoint first having been cleared, which could cause a false negative with the older kernel versions. This issue would affect kernel versions starting from this commit: 5aae8a53708025d4e718f0d2e7c2f766779ddc71 Up to the fix in this commit: a53fd61ac2f411745471c1c877d5e072fbbf0e5c gdb/ChangeLog: PR breakpoints/26385 * ppc-linux-nat.c (ppc_linux_nat_target::low_prepare_to_resume): Always clear watchpoint with PTRACE_SET_DEBUGREG.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/ppc-linux-nat.c21
2 files changed, 18 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5fbc887..5106b28 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2020-08-14 Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
+ PR breakpoints/26385
+ * ppc-linux-nat.c (ppc_linux_nat_target::low_prepare_to_resume):
+ Always clear watchpoint with PTRACE_SET_DEBUGREG.
+
+2020-08-14 Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
+
* ppc-linux-nat.c (ppc_linux_dreg_interface::detect)
(ppc_linux_nat_target::low_prepare_to_resume): Use ptrace () < 0
and >= to check return value instead of == -1 and != -1.
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index 89efdae..5f823d7 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -2909,20 +2909,23 @@ ppc_linux_nat_target::low_prepare_to_resume (struct lwp_info *lp)
{
gdb_assert (m_dreg_interface.debugreg_p ());
- /* Passing 0 to PTRACE_SET_DEBUGREG will clear the
- watchpoint. */
- long wp = 0;
+ /* Passing 0 to PTRACE_SET_DEBUGREG will clear the watchpoint. We
+ always clear the watchpoint instead of just overwriting it, in
+ case there is a request for a new watchpoint, because on some
+ older kernel versions and configurations simply overwriting the
+ watchpoint after it was hit would not re-enable it. */
+ if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, 0) < 0)
+ perror_with_name (_("Error clearing hardware watchpoint"));
/* GDB requested a watchpoint to be installed. */
if (process_it != m_process_info.end ()
&& process_it->second.requested_wp_val.has_value ())
- wp = *(process_it->second.requested_wp_val);
-
- long ret = ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (),
- 0, wp);
+ {
+ long wp = *(process_it->second.requested_wp_val);
- if (ret < 0)
- perror_with_name (_("Error setting hardware watchpoint"));
+ if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, wp) < 0)
+ perror_with_name (_("Error setting hardware watchpoint"));
+ }
}
lp_arch_info->debug_regs_stale = false;