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

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