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

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