]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/step-over-trips-on-watchpoint.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / step-over-trips-on-watchpoint.exp
CommitLineData
213516ef 1# Copyright (C) 2014-2023 Free Software Foundation, Inc.
2adfaa28
PA
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# Test that when a step-over trips on a watchpoint, that watchpoint is
17# reported.
18
19standard_testfile
20set executable ${testfile}
21
22# This test verifies that a watchpoint is detected in a multithreaded
23# program so the test is only meaningful on a system with hardware
24# watchpoints.
25if {[skip_hw_watchpoint_tests]} {
26 return 0
27}
28
29if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
30 executable [list debug "incdir=${objdir}"]] != "" } {
31 return -1
32}
33
c79d856c
PA
34# The test proper. DISPLACED is true if we should try with displaced
35# stepping. WITH_BP is true if we should try with a thread-specific
36# breakpoint (for the wrong thread) right after the instruction that
37# triggers the watchpoint.
38proc do_test { displaced with_bp } {
2adfaa28 39 global executable
ebc90b50
PA
40 global gdb_prompt
41 global hex
2adfaa28
PA
42
43 if ${with_bp} {
44 set prefix "with thread-specific bp"
45 } else {
46 set prefix "no thread-specific bp"
47 }
c79d856c 48 with_test_prefix "displaced=$displaced: $prefix" {
2adfaa28
PA
49 # Cover both stepping and non-stepping execution commands.
50 foreach command {"step" "next" "continue" } {
51 with_test_prefix $command {
52 clean_restart $executable
53
54 if ![runto_main] {
55 continue
56 }
57
c79d856c
PA
58 gdb_test_no_output "set displaced-stepping $displaced"
59
0dd7b8f7
TV
60 set line [gdb_get_line_number "set wait-thread breakpoint here"]
61 if { ![gdb_breakpoint $line] } {
62 return
63 }
2adfaa28 64 gdb_continue_to_breakpoint "run to wait-thread breakpoint"
b05b1202 65 gdb_test "info threads" "\\\* 1 .* 2 .*" "info threads shows all threads"
2adfaa28
PA
66
67 gdb_test_no_output "set scheduler-locking on"
68
69 delete_breakpoints
70
71 gdb_breakpoint [gdb_get_line_number "set breakpoint child here"]
72 gdb_test "thread 2" "Switching to .*"
73 gdb_continue_to_breakpoint "run to breakpoint in thread 2"
ebc90b50
PA
74
75 set address_triggers_watch "<invalid>"
76 set after_address_triggers_watch "<invalid>"
77
78 # Let the watchpoint trigger once (with the other
79 # thread locked), in order to find both the address of
80 # the instruction that triggers the watchpoint and the
81 # address of the instruction immediately after.
82 with_test_prefix "find addresses" {
83 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
84 gdb_test "watch watch_me" "Hardware watchpoint .*"
85
86 gdb_test "continue" \
87 "Hardware watchpoint.*: watch_me.*New value = 1.*" \
88 "continue to watchpoint"
89
90 set msg "find addresses"
91 gdb_test_multiple "disassemble" $msg {
92 -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" {
93 set address_triggers_watch $expect_out(1,string)
94 set after_address_triggers_watch $expect_out(2,string)
95 pass $msg
96 }
97 }
98
99 delete_breakpoints
100 }
101
07473109
PA
102 gdb_test "break *$address_triggers_watch" "Breakpoint .*" \
103 "set breakpoint at address that triggers watch"
ebc90b50
PA
104 gdb_continue_to_breakpoint \
105 "run to instruction that triggers watch in thread 2"
106
2adfaa28
PA
107 gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2"
108 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
109 gdb_test "watch watch_me" "Hardware watchpoint .*"
110
111 if ${with_bp} {
07473109
PA
112 gdb_test "b *$after_address_triggers_watch thread 1" \
113 "Breakpoint .*" \
114 "set breakpoint specific to thread 1"
2adfaa28
PA
115 }
116
117 # Switch back to thread 1 and disable scheduler locking.
118 gdb_test "thread 1" "Switching to .*"
119 gdb_test_no_output "set scheduler-locking off"
120
d4569d7b
PA
121 # Thread 2 is still stopped at a breakpoint that needs
122 # to be stepped over. However, the instruction that
123 # is under the breakpoint triggers a watchpoint, which
124 # should trap and be reported to the user.
2adfaa28
PA
125 gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
126 }
127 }
128 }
129}
130
c79d856c
PA
131foreach displaced { "off" "on" } {
132 if { $displaced != "off" && ![support_displaced_stepping] } {
133 continue
134 }
135
136 foreach with_bp { 0 1 } {
137 do_test $displaced $with_bp
138 }
139}