]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - 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
1 # Copyright (C) 2014-2024 Free Software Foundation, Inc.
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
19 standard_testfile
20 set 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.
25 require allow_hw_watchpoint_tests
26
27 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
28 executable [list debug "incdir=${objdir}"]] != "" } {
29 return -1
30 }
31
32 # The test proper. DISPLACED is true if we should try with displaced
33 # stepping. WITH_BP is true if we should try with a thread-specific
34 # breakpoint (for the wrong thread) right after the instruction that
35 # triggers the watchpoint.
36 proc do_test { displaced with_bp } {
37 global executable
38 global gdb_prompt
39 global hex
40
41 if ${with_bp} {
42 set prefix "with thread-specific bp"
43 } else {
44 set prefix "no thread-specific bp"
45 }
46 with_test_prefix "displaced=$displaced: $prefix" {
47 # Cover both stepping and non-stepping execution commands.
48 foreach command {"step" "next" "continue" } {
49 with_test_prefix $command {
50 clean_restart $executable
51
52 if ![runto_main] {
53 continue
54 }
55
56 gdb_test_no_output "set displaced-stepping $displaced"
57
58 set line [gdb_get_line_number "set wait-thread breakpoint here"]
59 if { ![gdb_breakpoint $line] } {
60 return
61 }
62 gdb_continue_to_breakpoint "run to wait-thread breakpoint"
63 gdb_test "info threads" "\\\* 1 .* 2 .*" "info threads shows all threads"
64
65 gdb_test_no_output "set scheduler-locking on"
66
67 delete_breakpoints
68
69 gdb_breakpoint [gdb_get_line_number "set breakpoint child here"]
70 gdb_test "thread 2" "Switching to .*"
71 gdb_continue_to_breakpoint "run to breakpoint in thread 2"
72
73 set address_triggers_watch "<invalid>"
74 set after_address_triggers_watch "<invalid>"
75
76 # Let the watchpoint trigger once (with the other
77 # thread locked), in order to find both the address of
78 # the instruction that triggers the watchpoint and the
79 # address of the instruction immediately after.
80 with_test_prefix "find addresses" {
81 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
82 gdb_test "watch watch_me" "Hardware watchpoint .*"
83
84 gdb_test "continue" \
85 "Hardware watchpoint.*: watch_me.*New value = 1.*" \
86 "continue to watchpoint"
87
88 set msg "find addresses"
89 gdb_test_multiple "disassemble" $msg {
90 -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" {
91 set address_triggers_watch $expect_out(1,string)
92 set after_address_triggers_watch $expect_out(2,string)
93 pass $msg
94 }
95 }
96
97 delete_breakpoints
98 }
99
100 gdb_test "break *$address_triggers_watch" "Breakpoint .*" \
101 "set breakpoint at address that triggers watch"
102 gdb_continue_to_breakpoint \
103 "run to instruction that triggers watch in thread 2"
104
105 gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2"
106 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
107 gdb_test "watch watch_me" "Hardware watchpoint .*"
108
109 if ${with_bp} {
110 gdb_test "b *$after_address_triggers_watch thread 1" \
111 "Breakpoint .*" \
112 "set breakpoint specific to thread 1"
113 }
114
115 # Switch back to thread 1 and disable scheduler locking.
116 gdb_test "thread 1" "Switching to .*"
117 gdb_test_no_output "set scheduler-locking off"
118
119 # Thread 2 is still stopped at a breakpoint that needs
120 # to be stepped over. However, the instruction that
121 # is under the breakpoint triggers a watchpoint, which
122 # should trap and be reported to the user.
123 gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
124 }
125 }
126 }
127 }
128
129 foreach displaced { "off" "on" } {
130 if { $displaced != "off" && ![support_displaced_stepping] } {
131 continue
132 }
133
134 foreach with_bp { 0 1 } {
135 do_test $displaced $with_bp
136 }
137 }