Blame SOURCES/gdb-6.3-threaded-watchpoints2-20050225.patch

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