]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/watchthreads2.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchthreads2.exp
CommitLineData
dc621c35
DE
1# This testcase is part of GDB, the GNU debugger.
2
3666a048 3# Copyright 2009-2021 Free Software Foundation, Inc.
dc621c35
DE
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
7# the Free Software Foundation; either version 3 of the License, or
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
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18# Check that watchpoints get propagated to all existing threads when the
19# watchpoint is created.
20
21set NR_THREADS 4
22set X_INCR_COUNT 10
23
dc621c35
DE
24
25# This test verifies that a watchpoint is detected in the proper thread
26# so the test is only meaningful on a system with hardware watchpoints.
b800ec70
UW
27if {[skip_hw_watchpoint_tests]} {
28 return 0
dc621c35
DE
29}
30
0efbbabc
TT
31standard_testfile
32if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-DNR_THREADS=$NR_THREADS -DX_INCR_COUNT=$X_INCR_COUNT"]] != "" } {
dc621c35
DE
33 return -1
34}
35
0efbbabc 36clean_restart ${binfile}
dc621c35 37
35ec993f 38gdb_test_no_output "set can-use-hw-watchpoints 1" ""
dc621c35
DE
39
40#
41# Run to `main' where we begin our tests.
42#
43
44if ![runto_main] then {
c8ee3f04
PW
45 fail "can't run to main"
46 return 0
dc621c35
DE
47}
48
49gdb_test "break thread_started" \
50 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
51 "breakpoint on thread_started"
52
53# Run the program until all threads have hit thread_started.
54# We use this as the vehicle to determine when gdb is aware
55# of all threads (i.e. "info threads" would show all threads).
56
57set nr_started 0
58set message "run to thread_started"
59for { set i 0 } { $i < $NR_THREADS } { incr i } {
60 gdb_test_multiple "continue" $message {
61 -re ".*Breakpoint 2, thread_started ().*$gdb_prompt $" {
62 incr nr_started
63 }
64 timeout {
65 set i $NR_THREADS
66 }
67 }
68}
69if { $nr_started == $NR_THREADS } {
70 pass "all threads started"
71} else {
72 fail "all threads started"
73 # No point in continuing.
74 return -1
75}
76
77# Watch X, it will be modified by all threads.
78# We want this watchpoint to be set *after* all threads are running.
79gdb_test "watch x" "Hardware watchpoint 3: x"
80
81# Now that the watchpoint is set, we can let the threads increment X.
12b5d08a 82gdb_test_no_output "set var test_ready = 1"
dc621c35
DE
83
84# While debugging.
12b5d08a 85#gdb_test_no_output "set debug infrun 1"
dc621c35
DE
86
87set x_inc_line [gdb_get_line_number "X increment"]
88set x_thread_loc "thread_function \\\(arg=.*\\\) at .*watchthreads.c:$x_inc_line"
89
90# X is incremented under a mutex, so we should get NR_THREADS * X_INCR_COUNT
91# hits.
92set limit [expr $NR_THREADS*$X_INCR_COUNT]
93set x_count 0
94set done 0
95
96set message "x watch loop"
97
98for {set i 0} {!$done && $i < $limit} {incr i} {
99 set test_flag 0
100
101 gdb_test_multiple "continue" $message {
102 -re "(.*Hardware watchpoint.*)$gdb_prompt $" {
103 set string $expect_out(1,string)
104
105 if [regexp "Hardware watchpoint 3: x\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $x_count\[^\r\]*\r\[^\r\]*New value = [expr $x_count+1]\r" $string] {
106 incr x_count
107 set test_flag 1
108 } else {
109 # We test for new value = old value + 1 each iteration.
110 # This can fail due to gdb/10116.
111 # This is caught after the loop exits.
112 }
113 }
114 -re "The program is not being run.*$gdb_prompt $" {
115 fail "$message (program terminated)"
116 }
117 }
118
119 # If we fail above, don't bother continuing loop.
120 if { $test_flag == 0 } {
121 set done 1
122 }
123}
124
125if { $i == $limit } {
126 pass "all threads incremented x"
127} else {
128 kfail "gdb/10116" "gdb can drop watchpoints in multithreaded app"
129}