* verilog.c: New file.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchthreads.exp
CommitLineData
5633ea5c
JJ
1# This testcase is part of GDB, the GNU debugger.
2
0fb0cc75 3# Copyright 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
5633ea5c
JJ
4
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
5633ea5c
JJ
8# (at your option) any later version.
9#
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.
14#
15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
5633ea5c
JJ
17
18# Check that GDB can support multiple watchpoints across threads.
19
20if $tracelevel {
21 strace $tracelevel
22}
23
24set prms_id 0
25set bug_id 0
26
27# This test verifies that a watchpoint is detected in the proper thread
28# so the test is only meaningful on a system with hardware watchpoints.
29if [target_info exists gdb,no_hardware_watchpoints] {
30 return 0;
31}
32
d983da9c
DJ
33proc target_no_stopped_data { } {
34 return [istarget s390*-*-*]
35}
36
e1923096 37set testfile "watchthreads"
5633ea5c
JJ
38set srcfile ${testfile}.c
39set binfile ${objdir}/${subdir}/${testfile}
40if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
41 return -1
42}
43
44gdb_exit
45gdb_start
46gdb_reinitialize_dir $srcdir/$subdir
47gdb_load ${binfile}
48
49gdb_test "set can-use-hw-watchpoints 1" "" ""
50
51#
52# Run to `main' where we begin our tests.
53#
54
55if ![runto_main] then {
56 gdb_suppress_tests
57}
58
59set args_0 0
60set args_1 0
61
62# Watch values that will be modified by distinct threads.
63gdb_test "watch args\[0\]" "Hardware watchpoint 2: args\\\[0\\\]"
64gdb_test "watch args\[1\]" "Hardware watchpoint 3: args\\\[1\\\]"
65
e1923096
JJ
66set init_line [expr [gdb_get_line_number "Init value"]+1]
67set inc_line [gdb_get_line_number "Loop increment"]
d983da9c
DJ
68set main_loc "main \\\(\\\) at .*watchthreads.c:$init_line"
69set thread0_loc "thread_function \\\(arg=0x0\\\) at .*watchthreads.c:$inc_line"
70set thread1_loc "thread_function \\\(arg=0x1\\\) at .*watchthreads.c:$inc_line"
e1923096 71
5633ea5c
JJ
72# Loop and continue to allow both watchpoints to be triggered.
73for {set i 0} {$i < 30} {incr i} {
d983da9c
DJ
74 set test_flag_0 0
75 set test_flag_1 0
5633ea5c
JJ
76 set test_flag 0
77 gdb_test_multiple "continue" "threaded watch loop" {
d983da9c
DJ
78 -re "(.*Hardware watchpoint.*)$gdb_prompt $" {
79 # At least one hardware watchpoint was hit. Check if both were.
80 set string $expect_out(1,string)
81
82 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] {
83 incr args_0
84 incr test_flag_0
85 }
86 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 incr args_1
88 incr test_flag_1
89 }
90
91 set expected_loc "bogus location"
92 if { $test_flag_0 == 1 && $test_flag_1 == 0 && $args_0 == 1 } {
93 set expected_loc $main_loc
94 } elseif { $test_flag_0 == 0 && $test_flag_1 == 1 && $args_1 == 1 } {
95 set expected_loc $main_loc
96 } elseif { $test_flag_0 == 1 && $test_flag_1 == 0 } {
97 set expected_loc $thread0_loc
98 } elseif { $test_flag_0 == 0 && $test_flag_1 == 1 } {
99 set expected_loc $thread1_loc
100 } elseif { $test_flag_0 + $test_flag_1 == 2 } {
101 # On S/390, or any other system which can not report the
102 # stopped data address, it is OK to report two watchpoints
103 # at once in this test. Make sure the reported location
104 # corresponds to at least one of the watchpoints (and not,
105 # e.g., __nptl_create_event). On other systems, we should
106 # report the two watchpoints serially.
107 if { [target_no_stopped_data] } {
108 set expected_loc "($main_loc|$thread0_loc|$thread1_loc)"
109 }
110 }
111
112 if [ regexp "$expected_loc" $string ] {
113 set test_flag 1
114 } else {
115 fail "threaded watch loop"
116 }
117 }
5633ea5c 118 }
d983da9c 119
5633ea5c
JJ
120 # If we fail above, don't bother continuing loop
121 if { $test_flag == 0 } {
122 set i 30;
123 }
124}
125
126# Print success message if loop succeeded.
127if { $test_flag == 1 } {
128 pass "threaded watch loop"
129}
130
131# Verify that we hit first watchpoint in main thread.
132set message "first watchpoint on args\[0\] hit"
133if { $args_0 > 0 } {
134 pass $message
135} else {
136 fail $message
137}
138
139# Verify that we hit second watchpoint in main thread.
140set message "first watchpoint on args\[1\] hit"
141if { $args_1 > 0 } {
142 pass $message
143} else {
144 fail $message
145}
146
147# Verify that we hit first watchpoint in child thread.
148set message "watchpoint on args\[0\] hit in thread"
149if { $args_0 > 1 } {
150 pass $message
151} else {
152 fail $message
153}
154
155# Verify that we hit second watchpoint in child thread.
156set message "watchpoint on args\[1\] hit in thread"
157if { $args_1 > 1 } {
158 pass $message
159} else {
160 fail $message
161}
162
163# Verify that all watchpoint hits are accounted for.
164set message "combination of threaded watchpoints = 30"
d983da9c
DJ
165if { [target_no_stopped_data] } {
166 # See above. If we allow two watchpoints to be hit at once, we
167 # may have more than 30 hits total.
168 set result [expr $args_0 + $args_1 >= 30]
169} else {
170 set result [expr $args_0 + $args_1 == 30]
171}
172if { $result } {
5633ea5c
JJ
173 pass $message
174} else {
175 fail $message
176}
This page took 0.421911 seconds and 4 git commands to generate.