]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/wp-replication.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / wp-replication.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2009-2015 Free Software Foundation, Inc.
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 hardware watchpoints get correctly replicated to all
19 # existing threads when hardware watchpoints are created. This test
20 # creates one hardware watchpoint per thread until a maximum is
21 # reached. It originally addresses a deficiency seen on embedded
22 # powerpc targets with slotted hardware *point designs.
23
24 set NR_THREADS 10
25 set NR_TRIGGERS_PER_THREAD 2
26
27 # This test verifies that a hardware watchpoint gets replicated to
28 # every existing thread and is detected properly. This test is
29 # only meaningful on a target with hardware watchpoint support.
30 if {[skip_hw_watchpoint_tests]} {
31 return 0
32 }
33
34 standard_testfile
35 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-DNR_THREADS=$NR_THREADS -DNR_TRIGGERS_PER_THREAD=$NR_TRIGGERS_PER_THREAD"]] != "" } {
36 return -1
37 }
38
39 clean_restart ${binfile}
40
41 # Force hardware watchpoints to be used.
42 gdb_test_no_output "set can-use-hw-watchpoints 1" ""
43
44 # Run to `main' where we begin our tests.
45 if ![runto_main] then {
46 fail "Failed to run to main"
47 return 0
48 }
49
50 # First, break at empty_cycle.
51 gdb_test "break empty_cycle" \
52 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
53 "Breakpoint on empty_cycle"
54
55 # Set some default values.
56 set hwatch_count 0
57 set done 0
58
59 # Count the number of hardware watchpoints available on
60 # this target.
61 while { $done == 0 } {
62
63 gdb_test "continue" \
64 ".*Breakpoint 2, empty_cycle \\(\\) at .*${srcfile}.*" \
65 "Continue to empty_cycle to insert watchpoint $hwatch_count"
66
67 # Some targets do resource counting as we insert watchpoints.
68 # Such targets won't cause a watchpoint insertion failure, but
69 # will switch to software watchpoints silently. We check for
70 # both cases here.
71 gdb_test_multiple "watch watched_data\[$hwatch_count\]" \
72 "watch watched_data\[$hwatch_count\]" {
73 -re "Hardware watchpoint .*$gdb_prompt $" {
74 }
75 -re "Watchpoint .*$gdb_prompt $" {
76 set done 1
77 break
78 }
79 }
80
81 gdb_test_multiple "continue" "watchpoint created successfully" {
82 -re ".*Breakpoint 2, empty_cycle \\(\\).*$gdb_prompt $" {
83 incr hwatch_count
84
85 # Some targets (like S/390) behave as though supporting
86 # unlimited hardware watchpoints. In this case we just take a
87 # safe exit out of the loop.
88 if { $hwatch_count == $NR_THREADS } {
89 set done 1
90 break
91 }
92 }
93 -re ".*Could not insert hardware watchpoint.*$gdb_prompt $" {
94 set done 1
95 break
96 }
97 }
98 }
99
100 # Target cannot insert hardware watchpoints. It should have reported
101 # (through board settings) that it did not support them in the first place.
102 # Just exit.
103 if { $hwatch_count == 0} {
104 fail "No hardware watchpoints available"
105 return 0
106 }
107
108 # Set the testcase's internal variable indicating the number of
109 # hardware watchpoints the target supports.
110 gdb_test_no_output "set var hw_watch_count=${hwatch_count}" \
111 "set var hw_watch_count=${hwatch_count}"
112
113 # At this point, we know how many hardware watchpoints
114 # the target supports. Use that to do further testing.
115 delete_breakpoints
116
117 # Break out of the empty_cycle loop by changing the
118 # controlling variable.
119 gdb_test_no_output "set var watch_count_done=1" \
120 "set var watch_count_done=1"
121
122 # Prepare to create all the threads.
123 gdb_test "break thread_started" \
124 "Breakpoint \[0-9\]+ at .*: file .*${srcfile}, line .*" \
125 "Breakpoint on thread_started"
126
127 # Move all threads to where they're supposed to be for testing.
128 for { set i 0 } { $i < $NR_THREADS } { incr i } {
129
130 # We want to set the maximum number of hardware watchpoints
131 # and make sure the target can handle that without an error.
132 # That will show us the watchpoints got replicated to all the
133 # threads correctly, and that no new watchpoints got created
134 # in the background for a specific thread.
135 if {$i < $hwatch_count} {
136 gdb_test "watch watched_data\[$i\]" \
137 "Hardware watchpoint .*" \
138 "watch watched_data\[$i\]"
139 } else {
140 verbose -log "Not setting watchpoint for watched_data\[$i\]\n"
141 }
142
143 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, thread_started \\(\\) at .*$srcfile.*" \
144 "Thread $i hit breakpoint at thread_started"
145 }
146
147 # Let the threads run and change the watched data, leading
148 # to watchpoint triggers.
149 gdb_test_no_output "set var test_ready=1" \
150 "set var test_ready=1"
151
152 # Set the number of expected watchpoint triggers.
153 set TRIGGERS [expr "$NR_THREADS * $hwatch_count * $NR_TRIGGERS_PER_THREAD"]
154
155 # Move the threads and hit the watchpoints TRIGGERS times.
156 for { set i 1 } { $i <= $TRIGGERS } { incr i } {
157 gdb_test continue "Continuing\\..*Hardware watchpoint \[0-9\]+: watched_data\[\[0-9\]+\].*Old value = \[0-9\]+.*New value = \[0-9\]+.*thread_function \\(arg=$hex\\) at .*$srcfile.*" \
158 "Continue to watchpoint trigger $i out of ${TRIGGERS} on watched_data"
159 }