]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/local-watch-wrong-thread.exp
update copyright year range in GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / local-watch-wrong-thread.exp
CommitLineData
f6bc2008
PA
1# This testcase is part of GDB, the GNU debugger.
2
61baf725 3# Copyright 2009-2017 Free Software Foundation, Inc.
f6bc2008
PA
4
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.
9#
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.
14#
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/>.
17
18# This test verifies that a local watchpoint isn't deleted when a
19# thread other than the thread the local watchpoint was set in stops
20# for a breakpoint.
21
b800ec70
UW
22if {[skip_hw_watchpoint_multi_tests]} {
23 return 0
f6bc2008
PA
24}
25
0efbbabc 26standard_testfile
f6bc2008
PA
27if {[gdb_compile_pthreads \
28 "${srcdir}/${subdir}/${srcfile}" \
29 "${binfile}" executable {debug} ] != "" } {
30 return -1
31}
32
0efbbabc 33clean_restart ${binfile}
f6bc2008 34
35ec993f 35gdb_test_no_output "set can-use-hw-watchpoints 1" ""
f6bc2008
PA
36
37if ![runto_main] then {
bc6c7af4 38 fail "can't run to main"
f6bc2008
PA
39 return
40}
41
42set inc_line_1 [gdb_get_line_number "Loop increment 1"]
43set inc_line_2 [gdb_get_line_number "Loop increment 2"]
44set bkpt_here [gdb_get_line_number "set breakpoint here"]
45
46# Run to the loop within thread_function0, so we can set our local
47# watchpoint.
48gdb_test "break ${srcfile}:${inc_line_1}" \
49 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
50 "breakpoint on thread_function0"
51
52gdb_test "continue" \
53 ".*Breakpoint 2.*thread_function0.*" \
54 "continue to thread_function0"
55
56delete_breakpoints
57
58# Set the local watchpoint, and confirm that it traps as expected.
59gdb_test "watch *myp" \
60 "Hardware watchpoint 3\: \\*myp.*" \
61 "set local watchpoint on *myp"
62
63gdb_test "continue" \
64 "Hardware watchpoint.*Old value.*New value.*thread_function0.*" \
65 "local watchpoint triggers"
66
67delete_breakpoints
68
69# Recreate the watchpoint, but this time with a condition we know
70# won't trigger. This is so the watchpoint is inserted, and the
71# target reports events, but GDB doesn't stop for them. We want to
72# hit the breakpoints on the other thread, and make sure this
73# watchpoint isn't deleted then.
74gdb_test "watch *myp if trigger != 0" \
75 "Hardware watchpoint 4\: \\*myp.*" \
76 "set local watchpoint on *myp, with false conditional"
77
78# Run to a breakpoint on a different thread. The previous local
79# watchpoint should not be deleted with the standard 'the program has
80# left the block in which its expression is valid', because the
81# thread_function0 thread should still be running in the loop.
82gdb_test "break ${srcfile}:${inc_line_2}" \
83 "Breakpoint 5 at .*: file .*${srcfile}, line .*" \
84 "breakpoint on the other thread"
85
86gdb_test "continue" \
87 "Breakpoint 5, thread_function1.*" \
88 "the other thread stopped on breakpoint"
89
90# Delete the new breakpoint, we don't need it anymore.
35ec993f 91gdb_test_no_output "delete 5" ""
f6bc2008
PA
92
93# Check if the local watchpoint hasn't been deleted (is still listed).
94# This is simpler to check than expecting 'the program has left ...',
95# and, is immune to string changes in that warning.
96gdb_test "info breakpoints" \
97 ".*4.*hw watchpoint.*keep.*y.*\\*myp.*" \
98 "local watchpoint is still in breakpoint list"
99
100# Make the watchpoint condition eval true.
12b5d08a 101gdb_test_no_output "set trigger=1" "let local watchpoint trigger"
f6bc2008
PA
102
103gdb_test "continue" \
104 "Hardware watchpoint.*Old value.*New value.*thread_function0.*" \
105 "local watchpoint still triggers"
106
107# Confirm that the local watchpoint is indeed deleted when
108# thread_function0 returns.
12b5d08a 109gdb_test_no_output "set *myp=0" "let thread_function0 return"
f6bc2008
PA
110
111gdb_test "break ${srcfile}:${bkpt_here}" \
112 "Breakpoint 6 at .*: file .*${srcfile}, line .*" \
113 "breakpoint on thread_function0's caller"
114
115gdb_test "continue" \
116 ".*Watchpoint.*deleted.*" \
117 "local watchpoint automatically deleted"