Blame SOURCES/gdb-rhbz1261564-aarch64-hw-watchpoint-3of5.patch

01917d
http://sourceware.org/ml/gdb-patches/2015-02/msg00731.html
01917d
Subject: [PATCH 5/8] Linux native: Use TRAP_BRKPT/TRAP_HWBPT
01917d
01917d
This patch adjusts the native Linux target backend to tell the core
01917d
whether a trap was caused by a breakpoint.
01917d
01917d
It teaches the target to get that information out of the si_code of
01917d
the SIGTRAP siginfo.
01917d
01917d
Tested on x86-64 Fedora 20, s390 RHEL 7, and PPC64 Fedora 18.  An
01917d
earlier version was tested on ARM Fedora 21.
01917d
01917d
gdb/ChangeLog:
01917d
2015-02-25  Pedro Alves  <palves@redhat.com>
01917d
01917d
	* linux-nat.c (save_sigtrap): Check for breakpoints before
01917d
	checking watchpoints.
01917d
	(status_callback) [USE_SIGTRAP_SIGINFO]: Don't check whether a
01917d
	breakpoint is inserted if relying on SIGTRAP's siginfo.si_code.
01917d
	(check_stopped_by_breakpoint) [USE_SIGTRAP_SIGINFO]: Decide whether
01917d
	a breakpoint triggered based on the SIGTRAP's siginfo.si_code.
01917d
	(linux_nat_stopped_by_sw_breakpoint)
01917d
	(linux_nat_supports_stopped_by_sw_breakpoint)
01917d
	(linux_nat_stopped_by_hw_breakpoint)
01917d
	(linux_nat_supports_stopped_by_hw_breakpoint): New functions.
01917d
	(linux_nat_wait_1): Don't re-increment the PC if relying on
01917d
	SIGTRAP's siginfo->si_code.
01917d
	(linux_nat_add_target): Install new target methods.
01917d
	* linux-thread-db.c (check_event): Don't account for breakpoint PC
01917d
	offset if the target already adjusted the PC.
01917d
	* nat/linux-ptrace.h (USE_SIGTRAP_SIGINFO): New.
01917d
	(GDB_ARCH_TRAP_BRKPT): New.
01917d
	(TRAP_HWBKPT): Define if not already defined.
01917d
---
01917d
 gdb/linux-nat.c        | 109 ++++++++++++++++++++++++++++++++++++++++++++++---
01917d
 gdb/linux-thread-db.c  |   6 ++-
01917d
 gdb/nat/linux-ptrace.h |  51 +++++++++++++++++++++++
01917d
 3 files changed, 159 insertions(+), 7 deletions(-)
01917d
01917d
Index: gdb-7.6.1/gdb/linux-nat.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/linux-nat.c	2016-03-13 19:26:22.736952457 +0100
01917d
+++ gdb-7.6.1/gdb/linux-nat.c	2016-03-13 19:45:29.343367943 +0100
01917d
@@ -1953,6 +1953,7 @@
01917d
      otherwise handle_zombie_lwp_error would get confused.  */
01917d
   lp->stopped = 0;
01917d
   lp->stopped_by_watchpoint = 0;
01917d
+  lp->stopped_by_hw_breakpoint = 0;
01917d
   registers_changed_ptid (lp->ptid);
01917d
 }
01917d
 
01917d
@@ -2874,6 +2875,15 @@
01917d
     }
01917d
 
01917d
   do_cleanups (old_chain);
01917d
+
01917d
+  {
01917d
+#define __SI_FAULT	0
01917d
+#define TRAP_HWBKPT     (__SI_FAULT|4)  /* hardware breakpoint/watchpoint */
01917d
+  siginfo_t siginfo;
01917d
+  if (linux_nat_get_siginfo (lp->ptid, &siginfo)
01917d
+      && siginfo.si_signo == SIGTRAP && siginfo.si_code == TRAP_HWBKPT)
01917d
+    lp->stopped_by_hw_breakpoint = 1;
01917d
+  }
01917d
 }
01917d
 
01917d
 /* See save_sigtrap.  */
01917d
@@ -3162,6 +3172,17 @@
01917d
   return 0;
01917d
 }
01917d
 
01917d
+static int
01917d
+linux_nat_stopped_by_hw_breakpoint (struct target_ops *ops)
01917d
+{
01917d
+  struct lwp_info *lp = find_lwp_pid (inferior_ptid);
01917d
+
01917d
+  if (lp == NULL)
01917d
+    return 0;
01917d
+
01917d
+  return lp->stopped_by_hw_breakpoint;
01917d
+}
01917d
+
01917d
 /* Select one LWP out of those that have events pending.  */
01917d
 
01917d
 static void
01917d
@@ -5233,6 +5254,7 @@
01917d
   t->to_thread_address_space = linux_nat_thread_address_space;
01917d
   t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
01917d
   t->to_stopped_data_address = linux_nat_stopped_data_address;
01917d
+  t->to_stopped_by_hw_breakpoint = linux_nat_stopped_by_hw_breakpoint;
01917d
 
01917d
   t->to_can_async_p = linux_nat_can_async_p;
01917d
   t->to_is_async_p = linux_nat_is_async_p;
01917d
Index: gdb-7.6.1/gdb/linux-nat.h
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/linux-nat.h	2016-03-13 19:26:19.411928036 +0100
01917d
+++ gdb-7.6.1/gdb/linux-nat.h	2016-03-13 19:44:29.437928457 +0100
01917d
@@ -80,6 +80,9 @@
01917d
      watchpoint trap.  */
01917d
   int stopped_by_watchpoint;
01917d
 
01917d
+  /* RHEL: TARGET_STOPPED_BY_HW_BREAKPOINT */
01917d
+  int stopped_by_hw_breakpoint;
01917d
+
01917d
   /* On architectures where it is possible to know the data address of
01917d
      a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
01917d
      STOPPED_DATA_ADDRESS contains such data address.  Otherwise,