1 # Copyright (C) 2014-2016 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
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
25 if {[skip_hw_watchpoint_tests]} {
29 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
30 executable [list debug "incdir=${objdir}"]] != "" } {
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 } {
44 set prefix "with thread-specific bp"
46 set prefix "no thread-specific bp"
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
58 gdb_test_no_output "set displaced-stepping $displaced"
60 gdb_breakpoint [gdb_get_line_number "set wait-thread breakpoint here"]
61 gdb_continue_to_breakpoint "run to wait-thread breakpoint"
62 gdb_test "info threads" "\\\* 1 .* 2 .*" "info threads shows all threads"
64 gdb_test_no_output "set scheduler-locking on"
68 gdb_breakpoint [gdb_get_line_number "set breakpoint child here"]
69 gdb_test "thread 2" "Switching to .*"
70 gdb_continue_to_breakpoint "run to breakpoint in thread 2"
72 set address_triggers_watch "<invalid>"
73 set after_address_triggers_watch "<invalid>"
75 # Let the watchpoint trigger once (with the other
76 # thread locked), in order to find both the address of
77 # the instruction that triggers the watchpoint and the
78 # address of the instruction immediately after.
79 with_test_prefix "find addresses" {
80 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
81 gdb_test "watch watch_me" "Hardware watchpoint .*"
84 "Hardware watchpoint.*: watch_me.*New value = 1.*" \
85 "continue to watchpoint"
87 set msg "find addresses"
88 gdb_test_multiple "disassemble" $msg {
89 -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" {
90 set address_triggers_watch $expect_out(1,string)
91 set after_address_triggers_watch $expect_out(2,string)
99 gdb_test "break *$address_triggers_watch" "Breakpoint .*" \
100 "set breakpoint at address that triggers watch"
101 gdb_continue_to_breakpoint \
102 "run to instruction that triggers watch in thread 2"
104 gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2"
105 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
106 gdb_test "watch watch_me" "Hardware watchpoint .*"
109 gdb_test "b *$after_address_triggers_watch thread 1" \
111 "set breakpoint specific to thread 1"
114 # Switch back to thread 1 and disable scheduler locking.
115 gdb_test "thread 1" "Switching to .*"
116 gdb_test_no_output "set scheduler-locking off"
118 # Thread 2 is still stopped at a breakpoint that needs
119 # to be stepped over. However, the instruction that
120 # is under the breakpoint triggers a watchpoint, which
121 # should trap and be reported to the user.
122 gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
128 foreach displaced { "off" "on" } {
129 if { $displaced != "off" && ![support_displaced_stepping] } {
133 foreach with_bp { 0 1 } {
134 do_test $displaced $with_bp