1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2004, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>.
18 # Check that GDB can support multiple watchpoints across threads.
21 # This test verifies that a watchpoint is detected in the proper thread
22 # so the test is only meaningful on a system with hardware watchpoints.
23 if {[skip_hw_watchpoint_multi_tests]} {
27 proc target_no_stopped_data { } {
28 return [istarget s390*-*-*]
31 set testfile "watchthreads"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
40 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_test_no_output "set can-use-hw-watchpoints 1" ""
46 # Run to `main' where we begin our tests.
49 if ![runto_main] then {
56 # Watch values that will be modified by distinct threads.
57 gdb_test "watch args\[0\]" "Hardware watchpoint 2: args\\\[0\\\]"
58 gdb_test "watch args\[1\]" "Hardware watchpoint 3: args\\\[1\\\]"
62 set init_line [gdb_get_line_number "Init value"]
63 set inc_line [gdb_get_line_number "Loop increment"]
64 set main_loc "main \\\(\\\) at .*watchthreads.c:$init_line"
65 set thread0_loc "thread_function \\\(arg=0x0\\\) at .*watchthreads.c:$inc_line"
66 set thread1_loc "thread_function \\\(arg=0x1\\\) at .*watchthreads.c:$inc_line"
68 # Loop and continue to allow both watchpoints to be triggered.
69 for {set i 0} {$i < 30} {incr i} {
73 gdb_test_multiple "continue" "threaded watch loop" {
74 -re "(.*Hardware watchpoint.*)$gdb_prompt $" {
75 # At least one hardware watchpoint was hit. Check if both were.
76 set string $expect_out(1,string)
78 if [regexp "Hardware watchpoint 2: args\\\[0\\\]\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $args_0\[^\r\]*\r\[^\r\]*New value = [expr $args_0+1]\r" $string] {
82 if [regexp "Hardware watchpoint 3: args\\\[1\\\]\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $args_1\[^\r\]*\r\[^\r\]*New value = [expr $args_1+1]\r" $string] {
87 set expected_loc "bogus location"
88 if { $test_flag_0 == 1 && $test_flag_1 == 0 && $args_0 == 1 } {
89 set expected_loc $main_loc
90 } elseif { $test_flag_0 == 0 && $test_flag_1 == 1 && $args_1 == 1 } {
91 set expected_loc $main_loc
92 } elseif { $test_flag_0 == 1 && $test_flag_1 == 0 } {
93 set expected_loc $thread0_loc
94 } elseif { $test_flag_0 == 0 && $test_flag_1 == 1 } {
95 set expected_loc $thread1_loc
96 } elseif { $test_flag_0 + $test_flag_1 == 2 } {
97 # On S/390, or any other system which can not report the
98 # stopped data address, it is OK to report two watchpoints
99 # at once in this test. Make sure the reported location
100 # corresponds to at least one of the watchpoints (and not,
101 # e.g., __nptl_create_event). On other systems, we should
102 # report the two watchpoints serially.
103 if { [target_no_stopped_data] } {
104 set expected_loc "($main_loc|$thread0_loc|$thread1_loc)"
108 if [ regexp "$expected_loc" $string ] {
111 fail "threaded watch loop"
114 # If one of the watchpoints is disabled, we'd better not stop there.
115 if { !$hwwp_2_enabled && $test_flag_0 } {
116 fail "disabled hw watchpoint 2 triggered"
118 if { !$hwwp_3_enabled && $test_flag_1 } {
119 fail "disabled hw watchpoint 3 triggered"
122 # If we get to 10 in one of the watched locations disable it so we
123 # see some of the other watched location.
124 # 10 is chosen so we're guaranteed to come through here.
125 if { $hwwp_2_enabled && $hwwp_3_enabled } {
126 if { $args_0 >= 10 && $hwwp_2_enabled } {
127 gdb_test_no_output "disable 2" "disable first watchpoint at 10"
129 } elseif { $args_1 >= 10 && $hwwp_3_enabled } {
130 gdb_test_no_output "disable 3" "disable first watchpoint at 10"
137 # If we fail above, don't bother continuing loop
138 if { $test_flag == 0 } {
143 # Print success message if loop succeeded.
144 if { $test_flag == 1 } {
145 pass "threaded watch loop"
148 # Verify that we hit first watchpoint in main thread.
149 set message "first watchpoint on args\[0\] hit"
156 # Verify that we hit second watchpoint in main thread.
157 set message "first watchpoint on args\[1\] hit"
164 # Verify that we hit first watchpoint in child thread.
165 set message "watchpoint on args\[0\] hit in thread"
172 # Verify that we hit second watchpoint in child thread.
173 set message "watchpoint on args\[1\] hit in thread"
180 # Verify that all watchpoint hits are accounted for.
181 set message "combination of threaded watchpoints = 30"
182 if { [target_no_stopped_data] } {
183 # See above. If we allow two watchpoints to be hit at once, we
184 # may have more than 30 hits total.
185 set result [expr $args_0 + $args_1 >= 30]
187 set result [expr $args_0 + $args_1 == 30]