]>
Commit | Line | Data |
---|---|---|
7280ceea PA |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | # Copyright 2014-2024 Free Software Foundation, Inc. |
7280ceea 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 file is part of the gdb testsuite. | |
19 | ||
20 | # Test that GDB presents a hardware watchpoint stop at the first | |
21 | # instruction right after the instruction that changes memory. | |
22 | # | |
23 | # Some targets trigger a hardware watchpoint after the instruction | |
24 | # that wrote memory executes, thus with the memory already changed and | |
25 | # the PC pointing to the instruction after the instruction that wrote | |
26 | # to memory. These targets are said to have "continuable" | |
27 | # watchpoints, referring to the fact that to make progress after the | |
28 | # watchpoint triggers, GDB just needs to continue the target. | |
29 | # | |
30 | # Other targets trigger a hardware watchpoint at the instruction which | |
31 | # has attempted to write to the piece of memory under control of the | |
32 | # watchpoint, with the instruction actually not executed yet. To be | |
33 | # able to check whether the watched value changed, GDB needs to | |
34 | # complete the memory write, single-stepping the target once. These | |
35 | # targets are said to have "non-continuable" watchpoints. | |
36 | # | |
37 | # This test makes sure that GDB knows which kind of watchpoint the | |
38 | # target has, using this sequence of steps: | |
39 | # | |
40 | # 1 - run to main | |
41 | # | |
42 | # 2 - set a software watchpoint | |
43 | # | |
44 | # 3 - continue until watchpoint triggers | |
45 | # | |
46 | # 4 - the PC now points to the instruction right after the instruction | |
47 | # that actually caused the memory write. So this is the address a | |
48 | # hardware watchpoint should present the stop to the user too. | |
49 | # Store the PC address. | |
50 | # | |
51 | # 5 - replace the software watchpoint by a hardware watchpoint | |
52 | # | |
53 | # 6 - continue until hardware watchpoint triggers | |
54 | # | |
55 | # 7 - the PC must point to the same address the software watchpoint | |
56 | # triggered at. | |
57 | # | |
58 | # If the target has continuable watchpoints, but GDB thinks it has | |
59 | # non-continuable watchpoints, GDB will stop the inferior two | |
60 | # instructions after the watched value change, rather than at the next | |
61 | # instruction. | |
62 | # | |
63 | # If the target has non-continuable watchpoints, while GDB thinks it | |
64 | # has continuable watchpoints, GDB will see a watchpoint trigger, | |
65 | # notice no value changed, and immediatly continue the target. Now, | |
66 | # either the target manages to step-over the watchpoint transparently, | |
67 | # and GDB thus fails to present to value change to the user, or, the | |
68 | # watchpoint will keep re-triggering, with the program never making | |
69 | # any progress. | |
70 | ||
71 | standard_testfile | |
72 | ||
73 | # No use testing this if we can't use hardware watchpoints. | |
e379cbb1 | 74 | require allow_hw_watchpoint_tests |
7280ceea | 75 | |
5b362f04 | 76 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
7280ceea PA |
77 | return -1 |
78 | } | |
79 | ||
65a33d75 | 80 | if {![runto_main]} { |
7280ceea PA |
81 | return |
82 | } | |
83 | ||
84 | # Get the current PC. TEST is used as test prefix. | |
85 | ||
86 | proc get_pc {test} { | |
87 | global hex gdb_prompt | |
88 | ||
89 | set addr "" | |
90 | gdb_test_multiple "p /x \$pc" "$test" { | |
91 | -re " = ($hex).*$gdb_prompt $" { | |
92 | set addr $expect_out(1,string) | |
93 | pass "$test" | |
94 | } | |
95 | } | |
96 | ||
97 | return $addr | |
98 | } | |
99 | ||
100 | # So we get an immediate warning/error if the target doesn't support a | |
101 | # given watchpoint type. | |
102 | gdb_test_no_output "set breakpoint always-inserted on" | |
103 | ||
104 | set hw_watchpoints_supported 0 | |
105 | ||
106 | set test "set probe hw watchpoint" | |
107 | gdb_test_multiple "watch global" $test { | |
108 | -re "You may have requested too many.*$gdb_prompt $" { | |
109 | pass $test | |
110 | } | |
111 | -re "Target does not support.*$gdb_prompt $" { | |
112 | pass $test | |
113 | } | |
114 | -re "$gdb_prompt $" { | |
115 | pass $test | |
116 | set hw_watchpoints_supported 1 | |
117 | } | |
118 | } | |
119 | ||
120 | if {!$hw_watchpoints_supported} { | |
121 | unsupported "no hw watchpoints support" | |
122 | return | |
123 | } | |
124 | ||
125 | delete_breakpoints | |
126 | ||
127 | proc test {always_inserted} { | |
128 | global srcfile binfile | |
129 | ||
130 | with_test_prefix "always-inserted $always_inserted" { | |
131 | ||
132 | clean_restart $binfile | |
133 | ||
65a33d75 | 134 | if {![runto_main]} { |
7280ceea PA |
135 | return |
136 | } | |
137 | ||
138 | # Force use of software watchpoints. | |
139 | gdb_test_no_output "set can-use-hw-watchpoints 0" | |
140 | ||
141 | gdb_test "watch global" \ | |
142 | "Watchpoint .*: global" \ | |
143 | "set software watchpoint on global variable" | |
144 | ||
145 | gdb_test "continue" \ | |
146 | "Watchpoint .*: global.*Old value = 0.*New value = 1.*set_global \\(val=1\\).*$srcfile.*" \ | |
147 | "software watchpoint triggers" | |
148 | ||
149 | set sw_watch_pc [get_pc "get sw watchpoint PC"] | |
150 | ||
151 | delete_breakpoints | |
152 | ||
153 | # Allow hardware watchpoints again. | |
154 | gdb_test_no_output "set can-use-hw-watchpoints 1" | |
155 | ||
156 | gdb_test "watch global" \ | |
157 | "Hardware watchpoint .*: global" \ | |
158 | "set hardware watchpoint on global variable" | |
159 | ||
160 | gdb_test "continue" \ | |
161 | "Hardware watchpoint .*: global.*Old value = 1.*New value = 2.*set_global \\(val=2\\).*$srcfile.*" \ | |
162 | "hardware watchpoint triggers" | |
163 | ||
164 | set hw_watch_pc [get_pc "get hw watchpoint PC"] | |
165 | ||
635856f5 | 166 | gdb_assert {$sw_watch_pc == $hw_watch_pc} "hw watchpoint stops at right instruction" |
7280ceea PA |
167 | } |
168 | } | |
169 | ||
170 | foreach always_inserted {"off" "on" } { | |
171 | test $always_inserted | |
172 | } |