Automatic Copyright Year update after running gdb/copyright.py
[binutils-gdb.git] / gdb / testsuite / gdb.threads / wp-replication.exp
blobd1c5b9df2d51e28039300a4c6647362a88afc0c0
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2009-2022 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 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.
24 set NR_THREADS 10
25 set NR_TRIGGERS_PER_THREAD 2
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
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
39 clean_restart ${binfile}
41 # Force hardware watchpoints to be used.
42 gdb_test_no_output "set can-use-hw-watchpoints 1" ""
44 # Run to `main' where we begin our tests.
45 if ![runto_main] then {
46     return 0
49 # Set some default values.
50 set hwatch_count 0
51 set count 0
53 # Count the number of hardware watchpoints available on
54 # this target.
56 # So we get an immediate warning/error if the target doesn't support a
57 # hardware watchpoint or run out of hardware resource.
58 gdb_test_no_output "set breakpoint always-inserted on"
60 while { $count < $NR_THREADS } {
61     # Some targets do resource counting as we insert watchpoints.
62     # Such targets won't cause a watchpoint insertion failure, but
63     # will switch to software watchpoints silently.  We check for
64     # both cases here.
65     gdb_test_multiple "watch watched_data\[$hwatch_count\]" \
66         "watch watched_data\[$hwatch_count\]" {
67             -re ".*Could not insert hardware watchpoint.*$gdb_prompt $" {
68                 # End the loop.
69                 set count $NR_THREADS
70             }
71             -re "Hardware watchpoint .*$gdb_prompt $" {
72                 incr hwatch_count
73             }
74             -re "Watchpoint .*$gdb_prompt $" {
75                 # End the loop.
76                 set count $NR_THREADS
77             }
78         }
79     incr count
82 gdb_test_no_output "set breakpoint always-inserted off"
84 # Target cannot insert hardware watchpoints.  It should have reported
85 # (through board settings) that it did not support them in the first place.
86 # Just exit.
87 if { $hwatch_count == 0} {
88   fail "no hardware watchpoints available"
89   return 0
92 # Set the testcase's internal variable indicating the number of
93 # hardware watchpoints the target supports.
94 gdb_test_no_output "set var hw_watch_count=${hwatch_count}" \
95                    "set var hw_watch_count=${hwatch_count}"
97 # At this point, we know how many hardware watchpoints
98 # the target supports.  Use that to do further testing.
99 delete_breakpoints
101 # Prepare to create all the threads.
102 gdb_test "break thread_started" \
103          "Breakpoint \[0-9\]+ at .*: file .*${srcfile}, line .*" \
104          "breakpoint on thread_started"
106 # Move all threads to where they're supposed to be for testing.
107 for { set i 0 } { $i < $NR_THREADS } { incr i } {
109     # We want to set the maximum number of hardware watchpoints
110     # and make sure the target can handle that without an error.
111     # That will show us the watchpoints got replicated to all the
112     # threads correctly, and that no new watchpoints got created
113     # in the background for a specific thread.
114     if {$i < $hwatch_count} {
115       gdb_test "watch watched_data\[$i\]" \
116         "Hardware watchpoint .*"
117     } else {
118       verbose -log "Not setting watchpoint for watched_data\[$i\]\n"
119     }
121     gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, thread_started \\(\\) at .*$srcfile.*" \
122     "Thread $i hit breakpoint at thread_started"
125 # Let the threads run and change the watched data, leading
126 # to watchpoint triggers.
127 gdb_test_no_output "set var test_ready=1" \
128       "set var test_ready=1"
130 # Set the number of expected watchpoint triggers.
131 set TRIGGERS [expr "$NR_THREADS * $hwatch_count * $NR_TRIGGERS_PER_THREAD"]
133 # Move the threads and hit the watchpoints TRIGGERS times.
134 for { set i 1 } { $i <= $TRIGGERS } { incr i } {
135     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.*" \
136     "Continue to watchpoint trigger $i out of ${TRIGGERS} on watched_data"