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

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