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

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