Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2014-2015 Free Software Foundation, Inc. |
8e9db26e PA |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
16 | # Test alternating between watchpoint types, watching a sliding window | |
17 | # of addresses (thus alternating between aligned and unaligned | |
18 | # addresses). Only a single watchpoint exists at any given time. On | |
19 | # targets that only update the debug registers on resume, this | |
20 | # stresses the debug register setup code, both in GDB and in the | |
21 | # target/kernel as one watchpoint replaces the other in a single | |
22 | # operation. (Note that we don't have any of these watchpoints | |
23 | # trigger.) | |
24 | ||
25 | if [target_info exists gdb,no_hardware_watchpoints] { | |
26 | unsupported "no target support" | |
27 | return | |
28 | } | |
29 | ||
30 | standard_testfile | |
31 | ||
32 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { | |
33 | return -1 | |
34 | } | |
35 | ||
36 | if ![runto_main] then { | |
37 | fail "Can't run to main" | |
38 | return 0 | |
39 | } | |
40 | ||
41 | # The line we'll be stepping. | |
42 | set srcline [gdb_get_line_number "stepi line"] | |
43 | ||
44 | # The address the program is stopped at currently. | |
45 | set cur_addr "" | |
46 | ||
47 | # Get the current PC. | |
48 | ||
49 | proc get_pc {} { | |
50 | global hex gdb_prompt | |
51 | ||
52 | set addr "" | |
53 | set test "get PC" | |
54 | gdb_test_multiple "p /x \$pc" "$test" { | |
55 | -re " = ($hex).*$gdb_prompt $" { | |
56 | set addr $expect_out(1,string) | |
57 | pass "$test" | |
58 | } | |
59 | } | |
60 | ||
61 | return $addr | |
62 | } | |
63 | ||
64 | ||
65 | # Issue a stepi, and make sure the program advanced past the current | |
66 | # instruction (stored in the CUR_ADDR global). | |
67 | ||
68 | proc stepi {} { | |
69 | global hex gdb_prompt cur_addr | |
70 | ||
71 | set srcline " for (i = 0; i < 100000; i++); /* stepi line */" | |
72 | set test "stepi advanced" | |
73 | gdb_test_multiple "stepi" $test { | |
74 | -re "($hex).*[string_to_regexp $srcline]\r\n$gdb_prompt $" { | |
75 | set addr $expect_out(1,string) | |
76 | if {$addr != $cur_addr} { | |
77 | pass $test | |
78 | } else { | |
79 | fail $test | |
80 | } | |
81 | set cur_addr addr | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | gdb_breakpoint $srcline | |
87 | gdb_continue_to_breakpoint "stepi line" | |
88 | ||
89 | # The test tries various sequences of different types of watchpoints. | |
90 | # Probe for support first. | |
91 | ||
92 | # So we get an immediate warning/error if the target doesn't support a | |
93 | # given watchpoint type. | |
94 | gdb_test_no_output "set breakpoint always-inserted on" | |
95 | ||
96 | # The list of supported commands. Below we'll probe for support and | |
97 | # add elements to this list. | |
98 | set cmds {} | |
99 | ||
100 | foreach cmd {"watch" "awatch" "rwatch"} { | |
101 | set test $cmd | |
102 | gdb_test_multiple "$cmd buf.byte\[0\]" $test { | |
103 | -re "You may have requested too many.*$gdb_prompt $" { | |
104 | unsupported $test | |
105 | } | |
aebf9d24 AA |
106 | -re "Target does not support.*$gdb_prompt $" { |
107 | unsupported $test | |
108 | } | |
8e9db26e PA |
109 | -re "$gdb_prompt $" { |
110 | pass $test | |
111 | lappend cmds $cmd | |
112 | } | |
113 | } | |
114 | ||
115 | delete_breakpoints | |
116 | } | |
117 | ||
118 | set test "hbreak" | |
119 | gdb_test_multiple "hbreak main" $test { | |
120 | -re "You may have requested too many.*$gdb_prompt $" { | |
aebf9d24 AA |
121 | unsupported $test |
122 | } | |
123 | -re "No hardware breakpoint support.*$gdb_prompt $" { | |
124 | unsupported $test | |
8e9db26e PA |
125 | } |
126 | -re "$gdb_prompt $" { | |
127 | pass $test | |
128 | lappend cmds "hbreak" | |
129 | } | |
130 | } | |
131 | ||
132 | delete_breakpoints | |
133 | ||
134 | set cur_addr [get_pc] | |
135 | ||
136 | # Watch WIDTH bytes at BASE + OFFSET. CMD specifices the specific | |
137 | # type of watchpoint to use. If CMD is "hbreak", WIDTH is ignored. | |
138 | ||
139 | proc watch_command {cmd base offset width} { | |
140 | global srcfile srcline hex | |
141 | ||
142 | if {$cmd == "hbreak"} { | |
143 | set expr "*(buf.byte + $base + $offset)" | |
144 | gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex" | |
145 | } elseif {$cmd == "watch"} { | |
146 | set expr "*(buf.byte + $base + $offset)@$width" | |
147 | gdb_test "$cmd $expr" \ | |
148 | "Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]" | |
149 | } elseif {$cmd == "awatch"} { | |
150 | set expr "*(buf.byte + $base + $offset)@$width" | |
151 | gdb_test "$cmd $expr" \ | |
152 | "Hardware access \\(read/write\\) watchpoint \[0-9\]+: [string_to_regexp $expr]" | |
153 | } elseif {$cmd == "rwatch"} { | |
154 | set expr "*(buf.byte + $base + $offset)@$width" | |
155 | gdb_test "$cmd $expr" \ | |
156 | "Hardware read watchpoint \[0-9\]+: [string_to_regexp $expr]" | |
157 | } | |
158 | } | |
159 | ||
160 | # Run test proper. See intro for description. | |
161 | ||
162 | foreach always_inserted {"off" "on" } { | |
163 | gdb_test_no_output "set breakpoint always-inserted $always_inserted" | |
164 | foreach cmd1 $cmds { | |
165 | foreach cmd2 $cmds { | |
166 | for {set width 1} {$width < 4} {incr width} { | |
167 | ||
168 | if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} { | |
169 | # hbreak ignores WIDTH, no use testing more than | |
170 | # once. | |
171 | continue | |
172 | } | |
173 | ||
174 | for {set x 0} {$x < 4} {incr x} { | |
175 | set prefix "always-inserted $always_inserted: " | |
176 | append prefix "$cmd1 x $cmd2: " | |
177 | with_test_prefix "$prefix: width $width, iter $x" { | |
178 | with_test_prefix "base + 0" { | |
179 | watch_command $cmd1 $x 0 $width | |
180 | stepi | |
181 | gdb_test_no_output "delete \$bpnum" | |
182 | } | |
183 | with_test_prefix "base + 1" { | |
184 | watch_command $cmd2 $x 1 $width | |
185 | stepi | |
186 | gdb_test_no_output "delete \$bpnum" | |
187 | } | |
188 | } | |
189 | } | |
190 | } | |
191 | } | |
192 | } | |
193 | } |