1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2004 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Check that GDB can support multiple watchpoints across threads.
28 # This test verifies that a watchpoint is detected in the proper thread
29 # so the test is only meaningful on a system with hardware watchpoints.
30 if [target_info exists gdb,no_hardware_watchpoints] {
34 set testfile "schedlock"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
43 gdb_reinitialize_dir $srcdir/$subdir
46 gdb_test "set can-use-hw-watchpoints 1" "" ""
49 # Run to `main' where we begin our tests.
52 if ![runto_main] then {
59 # Watch values that will be modified by distinct threads.
60 gdb_test "watch args\[0\]" "Hardware watchpoint 2: args\\\[0\\\]"
61 gdb_test "watch args\[1\]" "Hardware watchpoint 3: args\\\[1\\\]"
63 # Loop and continue to allow both watchpoints to be triggered.
64 for {set i 0} {$i < 30} {incr i} {
66 gdb_test_multiple "continue" "threaded watch loop" {
67 -re "Hardware watchpoint 2: args\\\[0\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*schedlock.c:21.*$gdb_prompt $"
68 { set args_0 1; set test_flag 1 }
69 -re "Hardware watchpoint 3: args\\\[1\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*schedlock.c:21.*$gdb_prompt $"
70 { set args_1 1; set test_flag 1 }
71 -re "Hardware watchpoint 2: args\\\[0\\\].*Old value = $args_0.*New value = [expr $args_0+1].*in thread_function \\\(arg=0x0\\\) at .*schedlock.c:42.*$gdb_prompt $"
72 { set args_0 [expr $args_0+1]; set test_flag 1 }
73 -re "Hardware watchpoint 3: args\\\[1\\\].*Old value = $args_1.*New value = [expr $args_1+1].*in thread_function \\\(arg=0x1\\\) at .*schedlock.c:42.*$gdb_prompt $"
74 { set args_1 [expr $args_1+1]; set test_flag 1 }
76 # If we fail above, don't bother continuing loop
77 if { $test_flag == 0 } {
82 # Print success message if loop succeeded.
83 if { $test_flag == 1 } {
84 pass "threaded watch loop"
87 # Verify that we hit first watchpoint in main thread.
88 set message "first watchpoint on args\[0\] hit"
95 # Verify that we hit second watchpoint in main thread.
96 set message "first watchpoint on args\[1\] hit"
103 # Verify that we hit first watchpoint in child thread.
104 set message "watchpoint on args\[0\] hit in thread"
111 # Verify that we hit second watchpoint in child thread.
112 set message "watchpoint on args\[1\] hit in thread"
119 # Verify that all watchpoint hits are accounted for.
120 set message "combination of threaded watchpoints = 30"
121 if { [expr $args_0+$args_1] == 30 } {