a8767b3
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
f524ac5
From: Jeff Johnston <jjohnstn@redhat.com>
f524ac5
Date: Fri, 27 Oct 2017 21:07:50 +0200
f524ac5
Subject: gdb-6.3-threaded-watchpoints2-20050225.patch
f524ac5
f637971
;; Test sibling threads to set threaded watchpoints for x86 and x86-64
f637971
;;=fedoratest
f637971
e3c8b47
2005-02-28  Jeff Johnston  <jjohnstn@redhat.com>
e3c8b47
e3c8b47
	* config/i386/nm-linux.h: Change dr register routines to
e3c8b47
	accept a ptid_t first argument.  Change all calling macros
e3c8b47
	to default the inferior_ptid for the first argument.
e3c8b47
	(i386_linux_insert_watchpoint): New prototype.
e3c8b47
	(i386_linux_remove_watchpoint, i386_linux_insert_hw_breakpoint): Ditto.
e3c8b47
	(i386_linux_remove_hw_breakpoint): Ditto.
e3c8b47
	(target_insert_watchpoint, target_remove_watchpoint): Undef and
e3c8b47
	override.
e3c8b47
	(target_insert_hw_breakpoint, target_remove_hw_breakpoint): Ditto.
e3c8b47
	* config/i386/nm-linux64.h: Ditto except add amd64 versions of
e3c8b47
	the watchpoint/hw-breakpoint insert/remove routines.
e3c8b47
	* i386-nat.c: Include "inferior.h" to define inferior_ptid.
e3c8b47
	* i386-linux-nat.c: Change all dr get/set routines to accept
e3c8b47
	ptid_t as first argument and to use this argument to determine
e3c8b47
	the tid for PTRACE.
e3c8b47
	(i386_linux_set_debug_regs_for_thread): New function.
e3c8b47
	(i386_linux_sync_debug_registers_callback): Ditto.
e3c8b47
	(i386_linux_sync_debug_registers_across_threads): Ditto.
e3c8b47
	(i386_linux_insert_watchpoint, i386_linux_remove_watchpoint): Ditto.
e3c8b47
	(i386_linux_hw_breakpoint, i386_linux_remove_hw_breakpoint): Ditto.
e3c8b47
	(i386_linux_new_thread): Ditto.
e3c8b47
	(_initialize_i386_linux_nat): Ditto.
e3c8b47
	* amd64-linux-nat.c: Change all dr get/set routines to accept
e3c8b47
	ptid_t as first argument and to use this argument to determine
e3c8b47
	the tid for PTRACE.
e3c8b47
	(amd64_linux_set_debug_regs_for_thread): New function.
e3c8b47
	(amd64_linux_sync_debug_registers_callback): Ditto.
e3c8b47
	(amd64_linux_sync_debug_registers_across_threads): Ditto.
e3c8b47
	(amd64_linux_insert_watchpoint, amd64_linux_remove_watchpoint): Ditto.
e3c8b47
	(amd64_linux_hw_breakpoint, amd64_linux_remove_hw_breakpoint): Ditto.
e3c8b47
	(amd64_linux_new_thread): Ditto.
e3c8b47
	(_initialize_amd64_linux_nat): Register linux new thread observer.
Jan Kratochvil 254f0e9
	* testsuite/gdb.threads/watchthreads-threaded.c: New test case.
Jan Kratochvil 254f0e9
	* testsuite/gdb.threads/watchthreads-threaded.exp: Ditto.
e3c8b47
e3c8b47
[ With recent upstream GDB (6.8) reduced only to the testcase.  ]
e3c8b47
Jan Kratochvil 254f0e9
[ It was called watchthreads2.{exp,c} before but it conflicted with FSF GDB new
Jan Kratochvil 254f0e9
  testcase of the same name.  ]
Jan Kratochvil 254f0e9
10f824b
FIXME: The testcase does not expects multiple watchpoints hits per one stop.
10f824b
f637971
diff --git a/gdb/testsuite/gdb.threads/watchthreads-threaded.c b/gdb/testsuite/gdb.threads/watchthreads-threaded.c
f637971
new file mode 100644
f637971
--- /dev/null
f637971
+++ b/gdb/testsuite/gdb.threads/watchthreads-threaded.c
e3c8b47
@@ -0,0 +1,66 @@
e3c8b47
+/* This testcase is part of GDB, the GNU debugger.
e3c8b47
+
e3c8b47
+   Copyright 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
e3c8b47
+
e3c8b47
+   This program is free software; you can redistribute it and/or modify
e3c8b47
+   it under the terms of the GNU General Public License as published by
e3c8b47
+   the Free Software Foundation; either version 2 of the License, or
e3c8b47
+   (at your option) any later version.
e3c8b47
+
e3c8b47
+   This program is distributed in the hope that it will be useful,
e3c8b47
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e3c8b47
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e3c8b47
+   GNU General Public License for more details.
e3c8b47
+
e3c8b47
+   You should have received a copy of the GNU General Public License
e3c8b47
+   along with this program; if not, write to the Free Software
e3c8b47
+   Foundation, Inc., 59 Temple Place - Suite 330,
e3c8b47
+   Boston, MA 02111-1307, USA.  
e3c8b47
+ 
e3c8b47
+   This file is copied from schedlock.c.  */
e3c8b47
+
e3c8b47
+#include <stdio.h>
e3c8b47
+#include <unistd.h>
e3c8b47
+#include <stdlib.h>
e3c8b47
+#include <pthread.h>
e3c8b47
+
e3c8b47
+void *thread_function(void *arg); /* Pointer to function executed by each thread */
e3c8b47
+
e3c8b47
+#define NUM 5
e3c8b47
+
e3c8b47
+unsigned int args[NUM+1];
e3c8b47
+
e3c8b47
+int main() {
e3c8b47
+    int res;
e3c8b47
+    pthread_t threads[NUM];
e3c8b47
+    void *thread_result;
e3c8b47
+    long i;
e3c8b47
+
e3c8b47
+    for (i = 0; i < NUM; i++)
e3c8b47
+      {
e3c8b47
+	args[i] = 1; /* Init value.  */
e3c8b47
+	res = pthread_create(&threads[i],
e3c8b47
+		             NULL,
e3c8b47
+			     thread_function,
e3c8b47
+			     (void *) i);
e3c8b47
+      }
e3c8b47
+
e3c8b47
+    args[i] = 1;
e3c8b47
+    thread_function ((void *) i);
e3c8b47
+
e3c8b47
+    exit(EXIT_SUCCESS);
e3c8b47
+}
e3c8b47
+
e3c8b47
+void *thread_function(void *arg) {
e3c8b47
+    int my_number =  (long) arg;
e3c8b47
+    int *myp = (int *) &args[my_number];
e3c8b47
+
e3c8b47
+    /* Don't run forever.  Run just short of it :)  */
e3c8b47
+    while (*myp > 0)
e3c8b47
+      {
e3c8b47
+	(*myp) ++; usleep (1); /* Loop increment.  */
e3c8b47
+      }
e3c8b47
+
e3c8b47
+    pthread_exit(NULL);
e3c8b47
+}
e3c8b47
+
f637971
diff --git a/gdb/testsuite/gdb.threads/watchthreads-threaded.exp b/gdb/testsuite/gdb.threads/watchthreads-threaded.exp
f637971
new file mode 100644
f637971
--- /dev/null
f637971
+++ b/gdb/testsuite/gdb.threads/watchthreads-threaded.exp
dd46ae6
@@ -0,0 +1,126 @@
e3c8b47
+# This testcase is part of GDB, the GNU debugger.
e3c8b47
+
e3c8b47
+# Copyright 2005 Free Software Foundation, Inc.
e3c8b47
+
e3c8b47
+# This program is free software; you can redistribute it and/or modify
e3c8b47
+# it under the terms of the GNU General Public License as published by
e3c8b47
+# the Free Software Foundation; either version 2 of the License, or
e3c8b47
+# (at your option) any later version.
e3c8b47
+#
e3c8b47
+# This program is distributed in the hope that it will be useful,
e3c8b47
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
e3c8b47
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e3c8b47
+# GNU General Public License for more details.
e3c8b47
+#
e3c8b47
+# You should have received a copy of the GNU General Public License
e3c8b47
+# along with this program; if not, write to the Free Software
e3c8b47
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
e3c8b47
+
e3c8b47
+# Check that GDB can support multiple watchpoints across threads.
e3c8b47
+
e3c8b47
+# This test verifies that a watchpoint is detected in the proper thread
e3c8b47
+# so the test is only meaningful on a system with hardware watchpoints.
e3c8b47
+if [target_info exists gdb,no_hardware_watchpoints] {
e3c8b47
+    return 0;
e3c8b47
+}
e3c8b47
+
Jan Kratochvil 254f0e9
+set testfile "watchthreads-threaded"
e3c8b47
+set srcfile ${testfile}.c
Jan Kratochvil 22d1e60
+set binfile [standard_output_file ${testfile}]
e3c8b47
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
e3c8b47
+    return -1
e3c8b47
+}
e3c8b47
+
e3c8b47
+gdb_exit
e3c8b47
+gdb_start
e3c8b47
+gdb_reinitialize_dir $srcdir/$subdir
e3c8b47
+gdb_load ${binfile}
e3c8b47
+
e3c8b47
+gdb_test "set can-use-hw-watchpoints 1" "" ""
e3c8b47
+
e3c8b47
+#
e3c8b47
+# Run to `main' where we begin our tests.
e3c8b47
+#
e3c8b47
+
e3c8b47
+if ![runto_main] then {
e3c8b47
+    gdb_suppress_tests
e3c8b47
+}
e3c8b47
+
e3c8b47
+set args_2 0
e3c8b47
+set args_3 0
e3c8b47
+
e3c8b47
+gdb_breakpoint "thread_function"
e3c8b47
+gdb_continue_to_breakpoint "thread_function"
e3c8b47
+gdb_test "disable 2" ""
e3c8b47
+
e3c8b47
+gdb_test_multiple "p args\[2\]" "get initial args2" {
e3c8b47
+  -re "\\\$\[0-9\]* = (.*)$gdb_prompt $" {
e3c8b47
+    set init_args_2 $expect_out(1,string)
e3c8b47
+    pass "get initial args2"
e3c8b47
+  }
e3c8b47
+}
e3c8b47
+
e3c8b47
+gdb_test_multiple "p args\[3\]" "get initial args3" {
e3c8b47
+  -re "\\\$\[0-9\]* = (.*)$gdb_prompt $" {
e3c8b47
+    set init_args_3 $expect_out(1,string)
e3c8b47
+    pass "get initial args3"
e3c8b47
+  }
e3c8b47
+}
e3c8b47
+
e3c8b47
+set args_2 $init_args_2
e3c8b47
+set args_3 $init_args_3
e3c8b47
+
e3c8b47
+# Watch values that will be modified by distinct threads.
e3c8b47
+gdb_test "watch args\[2\]" "Hardware watchpoint 3: args\\\[2\\\]"
e3c8b47
+gdb_test "watch args\[3\]" "Hardware watchpoint 4: args\\\[3\\\]"
e3c8b47
+
e3c8b47
+set init_line [expr [gdb_get_line_number "Init value"]+1]
e3c8b47
+set inc_line [gdb_get_line_number "Loop increment"]
e3c8b47
+
e3c8b47
+# Loop and continue to allow both watchpoints to be triggered.
e3c8b47
+for {set i 0} {$i < 30} {incr i} {
e3c8b47
+  set test_flag 0
e3c8b47
+  gdb_test_multiple "continue" "threaded watch loop" {
Jan Kratochvil 254f0e9
+    -re "Hardware watchpoint 3: args\\\[2\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*watchthreads-threaded.c:$init_line.*$gdb_prompt $"
e3c8b47
+       { set args_2 1; set test_flag 1 }
Jan Kratochvil 254f0e9
+    -re "Hardware watchpoint 4: args\\\[3\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*watchthreads-threaded.c:$init_line.*$gdb_prompt $"
e3c8b47
+       { set args_3 1; set test_flag 1 }
Jan Kratochvil 254f0e9
+    -re "Hardware watchpoint 3: args\\\[2\\\].*Old value = $args_2.*New value = [expr $args_2+1].*in thread_function \\\(arg=0x2\\\) at .*watchthreads-threaded.c:$inc_line.*$gdb_prompt $"
e3c8b47
+       { set args_2 [expr $args_2+1]; set test_flag 1 }
Jan Kratochvil 254f0e9
+    -re "Hardware watchpoint 4: args\\\[3\\\].*Old value = $args_3.*New value = [expr $args_3+1].*in thread_function \\\(arg=0x3\\\) at .*watchthreads-threaded.c:$inc_line.*$gdb_prompt $"
e3c8b47
+       { set args_3 [expr $args_3+1]; set test_flag 1 }
e3c8b47
+  }
e3c8b47
+  # If we fail above, don't bother continuing loop
e3c8b47
+  if { $test_flag == 0 } {
e3c8b47
+    set i 30;
e3c8b47
+  }
e3c8b47
+}
e3c8b47
+
e3c8b47
+# Print success message if loop succeeded.
e3c8b47
+if { $test_flag == 1 } {
e3c8b47
+  pass "threaded watch loop"
e3c8b47
+}
e3c8b47
+
e3c8b47
+# Verify that we hit first watchpoint in child thread.
e3c8b47
+set message "watchpoint on args\[2\] hit in thread"
e3c8b47
+if { $args_2 > 1 } {
e3c8b47
+  pass $message 
e3c8b47
+} else {
e3c8b47
+  fail $message
e3c8b47
+}
e3c8b47
+
e3c8b47
+# Verify that we hit second watchpoint in child thread.
e3c8b47
+set message "watchpoint on args\[3\] hit in thread"
e3c8b47
+if { $args_3 > 1 } {
e3c8b47
+  pass $message 
e3c8b47
+} else {
e3c8b47
+  fail $message 
e3c8b47
+}
e3c8b47
+
e3c8b47
+# Verify that all watchpoint hits are accounted for.
e3c8b47
+set message "combination of threaded watchpoints = 30 + initial values"
e3c8b47
+if { [expr $args_2+$args_3] == [expr [expr 30+$init_args_2]+$init_args_3] } {
e3c8b47
+  pass $message 
e3c8b47
+} else {
e3c8b47
+  fail $message 
e3c8b47
+}