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