Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.threads / step-over-trips-on-watchpoint.exp
blob332ec9a03fdf97c1f615d0a046ccba1d5a069b69
1 # Copyright (C) 2014-2022 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test that when a step-over trips on a watchpoint, that watchpoint is
17 # reported.
19 standard_testfile
20 set executable ${testfile}
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 if {[skip_hw_watchpoint_tests]} {
26     return 0
29 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
30          executable [list debug "incdir=${objdir}"]] != "" } {
31     return -1
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.
38 proc do_test { displaced with_bp } {
39     global executable
40     global gdb_prompt
41     global hex
43     if ${with_bp} {
44         set prefix "with thread-specific bp"
45     } else {
46         set prefix "no thread-specific bp"
47     }
48     with_test_prefix "displaced=$displaced: $prefix" {
49         # Cover both stepping and non-stepping execution commands.
50         foreach command {"step" "next" "continue" } {
51             with_test_prefix $command {
52                 clean_restart $executable
54                 if ![runto_main] {
55                     continue
56                 }
58                 gdb_test_no_output "set displaced-stepping $displaced"
60                 set line [gdb_get_line_number "set wait-thread breakpoint here"]
61                 if { ![gdb_breakpoint $line] } {
62                     return
63                 }
64                 gdb_continue_to_breakpoint "run to wait-thread breakpoint"
65                 gdb_test "info threads" "\\\* 1 .*  2 .*" "info threads shows all threads"
67                 gdb_test_no_output "set scheduler-locking on"
69                 delete_breakpoints
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"
75                 set address_triggers_watch "<invalid>"
76                 set after_address_triggers_watch "<invalid>"
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 .*"
86                     gdb_test "continue" \
87                         "Hardware watchpoint.*: watch_me.*New value = 1.*" \
88                         "continue to watchpoint"
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                     }
99                     delete_breakpoints
100                 }
102                 gdb_test "break *$address_triggers_watch" "Breakpoint .*" \
103                     "set breakpoint at address that triggers watch"
104                 gdb_continue_to_breakpoint \
105                     "run to instruction that triggers watch in thread 2"
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 .*"
111                 if ${with_bp} {
112                     gdb_test "b *$after_address_triggers_watch thread 1" \
113                         "Breakpoint .*" \
114                         "set breakpoint specific to thread 1"
115                 }
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"
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.
125                 gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
126             }
127         }
128     }
131 foreach displaced { "off" "on" } {
132     if { $displaced != "off" && ![support_displaced_stepping] } {
133         continue
134     }
136     foreach with_bp { 0 1 } {
137         do_test $displaced $with_bp
138     }