]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/local-watch-wrong-thread.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / local-watch-wrong-thread.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2009-2013 Free Software Foundation, Inc.
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
22 if {[skip_hw_watchpoint_multi_tests]} {
23 return 0
24 }
25
26 standard_testfile
27 if {[gdb_compile_pthreads \
28 "${srcdir}/${subdir}/${srcfile}" \
29 "${binfile}" executable {debug} ] != "" } {
30 return -1
31 }
32
33 clean_restart ${binfile}
34
35 gdb_test_no_output "set can-use-hw-watchpoints 1" ""
36
37 if ![runto_main] then {
38 fail "Can't run to main"
39 return
40 }
41
42 set inc_line_1 [gdb_get_line_number "Loop increment 1"]
43 set inc_line_2 [gdb_get_line_number "Loop increment 2"]
44 set 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.
48 gdb_test "break ${srcfile}:${inc_line_1}" \
49 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
50 "breakpoint on thread_function0"
51
52 gdb_test "continue" \
53 ".*Breakpoint 2.*thread_function0.*" \
54 "continue to thread_function0"
55
56 delete_breakpoints
57
58 # Set the local watchpoint, and confirm that it traps as expected.
59 gdb_test "watch *myp" \
60 "Hardware watchpoint 3\: \\*myp.*" \
61 "set local watchpoint on *myp"
62
63 gdb_test "continue" \
64 "Hardware watchpoint.*Old value.*New value.*thread_function0.*" \
65 "local watchpoint triggers"
66
67 delete_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.
74 gdb_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.
82 gdb_test "break ${srcfile}:${inc_line_2}" \
83 "Breakpoint 5 at .*: file .*${srcfile}, line .*" \
84 "breakpoint on the other thread"
85
86 gdb_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.
91 gdb_test_no_output "delete 5" ""
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.
96 gdb_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.
101 gdb_test_no_output "set trigger=1" "let local watchpoint trigger"
102
103 gdb_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.
109 gdb_test_no_output "set *myp=0" "let thread_function0 return"
110
111 gdb_test "break ${srcfile}:${bkpt_here}" \
112 "Breakpoint 6 at .*: file .*${srcfile}, line .*" \
113 "breakpoint on thread_function0's caller"
114
115 gdb_test "continue" \
116 ".*Watchpoint.*deleted.*" \
117 "local watchpoint automatically deleted"