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

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