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

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