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

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