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

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