Blame SOURCES/gdb-bz541866-rwatch-before-run.patch

2f9ed3
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2f9ed3
From: Fedora GDB patches <invalid@email.com>
2f9ed3
Date: Fri, 27 Oct 2017 21:07:50 +0200
2f9ed3
Subject: gdb-bz541866-rwatch-before-run.patch
2f9ed3
2f9ed3
;; Fix i386+x86_64 rwatch+awatch before run, regression against 6.8 (BZ 541866).
2f9ed3
;; Fix i386 rwatch+awatch before run (BZ 688788, on top of BZ 541866).
2f9ed3
;;=push+jan: It should be fixed properly instead.
2f9ed3
2f9ed3
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
2f9ed3
--- a/gdb/breakpoint.c
2f9ed3
+++ b/gdb/breakpoint.c
2f9ed3
@@ -8773,7 +8773,7 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
2f9ed3
 		     int enabled, int internal, unsigned flags,
2f9ed3
 		     int display_canonical)
2f9ed3
 {
2f9ed3
-  int i;
2f9ed3
+  int i ATTRIBUTE_UNUSED;
2f9ed3
 
2f9ed3
   if (type == bp_hardware_breakpoint)
2f9ed3
     {
2f9ed3
@@ -14271,7 +14271,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
2f9ed3
 
2f9ed3
   if (bpt->type == bp_hardware_breakpoint)
2f9ed3
     {
2f9ed3
-      int i;
2f9ed3
+      int i ATTRIBUTE_UNUSED;
2f9ed3
       i = hw_breakpoint_used_count ();
2f9ed3
       target_resources_ok = 
2f9ed3
 	target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 
2f9ed3
diff --git a/gdb/config/i386/nm-linux.h b/gdb/config/i386/nm-linux.h
2f9ed3
new file mode 100644
2f9ed3
--- /dev/null
2f9ed3
+++ b/gdb/config/i386/nm-linux.h
2f9ed3
@@ -0,0 +1,28 @@
2f9ed3
+/* Native support for GNU/Linux i386.
2f9ed3
+
2f9ed3
+   Copyright 2010 Free Software Foundation, Inc.
2f9ed3
+
2f9ed3
+   This file is part of GDB.
2f9ed3
+
2f9ed3
+   This program is free software; you can redistribute it and/or modify
2f9ed3
+   it under the terms of the GNU General Public License as published by
2f9ed3
+   the Free Software Foundation; either version 3 of the License, or
2f9ed3
+   (at your option) any later version.
2f9ed3
+
2f9ed3
+   This program is distributed in the hope that it will be useful,
2f9ed3
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2f9ed3
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2f9ed3
+   GNU General Public License for more details.
2f9ed3
+
2f9ed3
+   You should have received a copy of the GNU General Public License
2f9ed3
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2f9ed3
+
2f9ed3
+#ifndef NM_LINUX_H
2f9ed3
+#define NM_LINUX_H
2f9ed3
+
2f9ed3
+#include "config/nm-linux.h"
2f9ed3
+
2f9ed3
+/* Red Hat backward compatibility with gdb-6.8.  */
2f9ed3
+#define target_can_use_hardware_watchpoint(type, cnt, ot) 1
2f9ed3
+
2f9ed3
+#endif /* NM_LINUX64_H */
2f9ed3
diff --git a/gdb/config/i386/nm-linux64.h b/gdb/config/i386/nm-linux64.h
2f9ed3
new file mode 100644
2f9ed3
--- /dev/null
2f9ed3
+++ b/gdb/config/i386/nm-linux64.h
2f9ed3
@@ -0,0 +1,28 @@
2f9ed3
+/* Native support for GNU/Linux amd64.
2f9ed3
+
2f9ed3
+   Copyright 2010 Free Software Foundation, Inc.
2f9ed3
+
2f9ed3
+   This file is part of GDB.
2f9ed3
+
2f9ed3
+   This program is free software; you can redistribute it and/or modify
2f9ed3
+   it under the terms of the GNU General Public License as published by
2f9ed3
+   the Free Software Foundation; either version 3 of the License, or
2f9ed3
+   (at your option) any later version.
2f9ed3
+
2f9ed3
+   This program is distributed in the hope that it will be useful,
2f9ed3
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2f9ed3
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2f9ed3
+   GNU General Public License for more details.
2f9ed3
+
2f9ed3
+   You should have received a copy of the GNU General Public License
2f9ed3
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2f9ed3
+
2f9ed3
+#ifndef NM_LINUX64_H
2f9ed3
+#define NM_LINUX64_H
2f9ed3
+
2f9ed3
+#include "config/nm-linux.h"
2f9ed3
+
2f9ed3
+/* Red Hat backward compatibility with gdb-6.8.  */
2f9ed3
+#define target_can_use_hardware_watchpoint(type, cnt, ot) 1
2f9ed3
+
2f9ed3
+#endif /* NM_LINUX64_H */
2f9ed3
diff --git a/gdb/configure.nat b/gdb/configure.nat
2f9ed3
--- a/gdb/configure.nat
2f9ed3
+++ b/gdb/configure.nat
2f9ed3
@@ -245,6 +245,7 @@ case ${gdb_host} in
2f9ed3
 		;;
2f9ed3
 	    i386)
2f9ed3
 		# Host: Intel 386 running GNU/Linux.
2f9ed3
+		NAT_FILE="${srcdir}/config/${gdb_host_cpu}/nm-linux.h"
2f9ed3
 		NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \
2f9ed3
 		i386-linux-nat.o x86-linux-nat.o nat/linux-btrace.o \
2f9ed3
 		nat/x86-linux.o nat/x86-linux-dregs.o"
2f9ed3
@@ -301,6 +302,7 @@ case ${gdb_host} in
2f9ed3
 	case ${gdb_host_cpu} in
2f9ed3
 	    i386)
2f9ed3
 		# Host: GNU/Linux x86-64
2f9ed3
+		NAT_FILE="${srcdir}/config/${gdb_host_cpu}/nm-linux64.h"
2f9ed3
 		NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \
2f9ed3
 		amd64-nat.o amd64-linux-nat.o x86-linux-nat.o \
2f9ed3
 		nat/linux-btrace.o \
2f9ed3
diff --git a/gdb/target.h b/gdb/target.h
2f9ed3
--- a/gdb/target.h
2f9ed3
+++ b/gdb/target.h
2f9ed3
@@ -1971,9 +1971,11 @@ extern struct thread_info *target_thread_handle_to_thread_info
2f9ed3
    one.  OTHERTYPE is the number of watchpoints of other types than
2f9ed3
    this one used so far.  */
2f9ed3
 
2f9ed3
+#ifndef target_can_use_hardware_watchpoint
2f9ed3
 #define target_can_use_hardware_watchpoint(TYPE,CNT,OTHERTYPE) \
2f9ed3
  (current_top_target ()->can_use_hw_breakpoint) ( \
2f9ed3
 					     TYPE, CNT, OTHERTYPE)
2f9ed3
+#endif
2f9ed3
 
2f9ed3
 /* Returns the number of debug registers needed to watch the given
2f9ed3
    memory region, or zero if not supported.  */
2f9ed3
diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-before-run.exp b/gdb/testsuite/gdb.base/watchpoint-hw-before-run.exp
2f9ed3
new file mode 100644
2f9ed3
--- /dev/null
2f9ed3
+++ b/gdb/testsuite/gdb.base/watchpoint-hw-before-run.exp
2f9ed3
@@ -0,0 +1,40 @@
2f9ed3
+# Copyright 2009, 2010 Free Software Foundation, Inc.
2f9ed3
+
2f9ed3
+# This program is free software; you can redistribute it and/or modify
2f9ed3
+# it under the terms of the GNU General Public License as published by
2f9ed3
+# the Free Software Foundation; either version 3 of the License, or
2f9ed3
+# (at your option) any later version.
2f9ed3
+#
2f9ed3
+# This program is distributed in the hope that it will be useful,
2f9ed3
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2f9ed3
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2f9ed3
+# GNU General Public License for more details.
2f9ed3
+#
2f9ed3
+# You should have received a copy of the GNU General Public License
2f9ed3
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2f9ed3
+
2f9ed3
+# Arch not supporting hw watchpoints does not imply no_hardware_watchpoints set.
2f9ed3
+if {(![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"]
2f9ed3
+     && ![istarget "ia64-*-*"])
2f9ed3
+    || [target_info exists gdb,no_hardware_watchpoints]} then {
2f9ed3
+    verbose "Skipping watchpoint-hw-before-run test."
2f9ed3
+    return
2f9ed3
+}
2f9ed3
+
2f9ed3
+set test watchpoint-hw-before-run
2f9ed3
+set srcfile watchpoint-hw-hit-once.c
2f9ed3
+if { [prepare_for_testing ${test}.exp ${test} ${srcfile}] } {
2f9ed3
+    return -1
2f9ed3
+}
2f9ed3
+
2f9ed3
+gdb_test "rwatch watchee" "ardware read watchpoint 1: watchee"
2f9ed3
+
2f9ed3
+# `runto_main' or `runto main' would delete the watchpoint created above.
2f9ed3
+
2f9ed3
+if { [gdb_start_cmd] < 0 } {
2f9ed3
+    untested start
2f9ed3
+    return -1
2f9ed3
+}
2f9ed3
+gdb_test "" "main .* at .*" "start"
2f9ed3
+
2f9ed3
+gdb_test "continue" "Continuing.\r\n\r\nHardware read watchpoint \[0-9\]+: watchee\r\n\r\nValue = 0\r\n.*"