Re: [PATCH] PR threads/10729: x86 hw watchpoints and non-stop mode

Jan Kratochvil
2011-12-12T18:38:19Z

On Mon, 12 Dec 2011 18:22:38 +0100, Jan Kratochvil wrote:
> I will yet update the testcase to support gdbserver.

Here you are.

I have deleted now from:
http://sourceware.org/gdb/wiki/TestingGDB#Native_Board_File
# Can't do hardware watchpoints, in general.
set_board_info gdb,no_hardware_watchpoints 1

as all the new tests PASS for me on
{x86_64,x86_64-m32,i686}-fedora16-linux-gnu. There is just:
Running gdb/testsuite/gdb.base/watchpoint-hw.exp ...
+PASS: gdb.base/watchpoint-hw.exp: watch watchee
+UNTESTED: gdb.base/watchpoint-hw.exp: start

but that was discussed elsewhere that gdb_start_cmd should be rather removed.

Regards,
Jan

gdb/testsuite/
2011-12-12 Jan Kratochvil <jan.kratochvil@redhat.com>

* gdb.base/watchpoint-hw-pre-hit.c: New file.
* gdb.base/watchpoint-hw-pre-hit.exp: New file.

--- /dev/null
+++ b/gdb/testsuite/gdb.base/watchpoint-hw-pre-hit.c
@@ -0,0 +1,118 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE 1
+#include <sys/ptrace.h>
+#include <linux/ptrace.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/debugreg.h>
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+
+static pid_t child;
+
+static void
+cleanup (void)
+{
+ if (child > 0)
+ kill (child, SIGKILL);
+ child = 0;
+}
+
+static void
+handler_fail (int signo)
+{
+ cleanup ();
+ signal (signo, SIG_DFL);
+ raise (signo);
+}
+
+static volatile int dummy;
+
+static void
+marker (void)
+{
+ dummy++;
+}
+
+static int check, resume;
+
+int
+main (void)
+{
+ pid_t got_pid;
+ int i, status, cycles = 0;
+ long l;
+
+ /* Unused variable. */
+ check = 0;
+
+ atexit (cleanup);
+ signal (SIGABRT, handler_fail);
+ signal (SIGINT, handler_fail);
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ assert (0);
+ case 0:
+ l = ptrace (PTRACE_TRACEME, 0, NULL, NULL);
+ assert (l == 0);
+
+ i = raise (SIGUSR1);
+ assert (i == 0);
+
+ while (!resume && cycles++ < 600 * 10)
+ usleep (1000000 / 10);
+
+ marker ();
+
+ assert (0);
+ default:
+ break;
+ }
+
+ got_pid = waitpid (child, &status, 0);
+ assert (got_pid == child);
+ assert (WIFSTOPPED (status));
+ assert (WSTOPSIG (status) == SIGUSR1);
+
+ /* Set all 4 watchpoint registers as hit. It may remain set this way from
+ a different debugger or internal use of ptrace in the application etc. */
+ errno = 0;
+ l = ptrace (PTRACE_POKEUSER, child, offsetof (struct user, u_debugreg[6]),
+ 0xFUL);
+ assert_perror (errno);
+ assert (l == 0);
+
+ errno = 0;
+ l = ptrace (PTRACE_DETACH, child, NULL, NULL);
+ assert_perror (errno);
+ assert (l == 0);
+
+ marker ();
+
+ return 0;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/watchpoint-hw-pre-hit.exp
@@ -0,0 +1,73 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test a newly created hardware watchpoint gets cleared its possible pre-set
+# hit in the status register. Otherwise a false hit may occur.
+
+load_lib gdbserver-support.exp
+
+if {[skip_hw_watchpoint_access_tests]
+ || (![istarget "i?86-*-linux*"] && ![istarget "x86_64-*-linux*"])
+ || ([is_remote target] && [skip_gdbserver_tests])} {
+ return 0
+}
+
+set test watchpoint-hw-pre-hit
+set srcfile ${test}.c
+if { [prepare_for_testing ${test}.exp ${test} ${srcfile}] } {
+ return -1
+}
+
+if ![runto "marker"] {
+ return -1
+}
+
+set test "print child"
+gdb_test_multiple $test $test {
+ -re " = (\[0-9\]+)\r\n$gdb_prompt $" {
+ pass $test
+ set child $expect_out(1,string)
+ }
+}
+
+gdb_test "kill" "" "kill" \
+ {Kill the program being debugged\? \(y or n\) } "y"
+
+if [is_remote target] {
+ gdbserver_start_extended
+}
+
+gdb_test "attach $child" "(Attaching to program: .*, process $child|Attached to process $child)\r\n.*" \
+ "attach"
+
+gdb_test_no_output "set variable resume=1"
+#gdb_test "maintenance set show-debug-regs on"
+gdb_test "awatch check" {Hardware access \(read/write\) watchpoint [0-9]+: check}
+
+if [is_remote target] {
+ setup_kfail remote/13492 "*-*-*"
+}
+set test "stepi"
+gdb_test_multiple $test $test {
+ -re "\r\nHardware access \\(read/write\\) watchpoint \[0-9\]+: check\r\n.*\r\n$gdb_prompt $" {
+ fail $test
+ }
+ -re "\r\n$gdb_prompt $" {
+ pass $test
+ }
+}
+
+gdb_test "kill" "" "kill" \
+ {Kill the program being debugged\? \(y or n\) } "y"