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

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