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

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