1 # Copyright 2013-2015 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib "range-stepping-support.exp"
19 set executable $testfile
21 if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug}] } {
26 fail "Can't run to main"
30 if ![gdb_range_stepping_enabled] {
31 unsupported "range stepping not supported by the target"
35 # Check that range stepping can step a range of multiple instructions.
37 with_test_prefix "multi insns" {
39 gdb_breakpoint [gdb_get_line_number "location 1"]
40 gdb_continue_to_breakpoint "location 1"
42 set pc_before_stepping ""
43 set test "pc before stepping"
44 gdb_test_multiple "print/x \$pc" $test {
45 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
46 set pc_before_stepping $expect_out(1,string)
51 # When "next" is executed, GDB should send one vCont;s and vCont;r
52 # and receive two stop replies:
54 # --> vCont;s (step over breakpoint)
56 # --> vCont;rSTART,END (range step)
58 set result [exec_cmd_expect_vCont_count "next" 1 1]
60 # This is the first range-stepping test, and the simplest
61 # one. If it fails, probably the rest of the tests would
62 # fail too, and the huge number of rsp packets in the test
63 # with the time-consuming loop would blow up the gdb.log file.
64 # Skip the rest of the tests.
68 set pc_after_stepping ""
69 set msg "pc after stepping"
70 gdb_test_multiple "print/x \$pc" $msg {
71 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
72 set pc_after_stepping $expect_out(1,string)
77 # There should be at least two instructions between
78 # PC_BEFORE_STEPPING and PC_AFTER_STEPPING.
79 gdb_test "disassemble ${pc_before_stepping},${pc_after_stepping}" \
80 "${hex} <main\\+${decimal}>:.*${hex} <main\\+${decimal}>:.*" \
81 "stepped multiple insns"
84 # Check that range stepping can step over a function.
86 with_test_prefix "step over func" {
88 set line_num [gdb_get_line_number "location 2"]
89 gdb_test "where" "main \\(\\) at .*${srcfile}:${line_num}.*"
91 # It's expected to get three stops and two 'vCont;r's. In the C
92 # code, the line of C source produces roughly the following
106 # Something like this will happen:
107 # --> vCont;rADDR1,ADDR3 (range step from ADDR1 to ADDR3)
108 # <-- T05 (target single-stepped to func, which is out of the step range)
109 # --> $Z0,ADDR2 (place step-resume breakpoint at ADDR2)
110 # --> vCont;c (resume)
111 # <-- T05 (target stops at ADDR2)
112 # --> vCont;rADDR1,ADDR3 (continues range stepping)
114 exec_cmd_expect_vCont_count "next" 0 2
117 # Check that breakpoints interrupt range stepping correctly.
119 with_test_prefix "breakpoint" {
120 gdb_breakpoint "func1"
121 # Something like this will happen:
122 # --> vCont;rADDR1,ADDR3
123 # <-- T05 (target single-steps to func1, which is out of the step range)
124 # --> $Z0,ADDR2 (step-resume breakpoint at ADDR2)
125 # --> vCont;c (resume)
126 # <-- T05 (target hits the breakpoint at func1)
127 exec_cmd_expect_vCont_count "next" 0 1
129 gdb_test "backtrace" "#0 .* func1 .*#1 .* main .*" \
130 "backtrace from func1"
132 # A cancelled range step should not confuse the following
133 # execution commands.
134 exec_cmd_expect_vCont_count "stepi" 1 0
135 gdb_test "finish" ".*"
140 # Check that range stepping works well even when there's a loop in the
143 with_test_prefix "loop" {
145 # GDB should send one vCont;r and receive one stop reply:
146 # --> vCont;rSTART,END (range step)
148 exec_cmd_expect_vCont_count "next" 0 1
150 # Confirm the loop completed.
151 gdb_test "print a" " = 15"
152 gdb_test "print e" " = 105"
155 # Check that range stepping works well even when the target's PC was
156 # already within the loop's body.
158 with_test_prefix "loop 2" {
159 # Stepi into the loop body. 15 should be large enough to make
160 # sure the program stops within the loop's body.
161 gdb_test "stepi 15" ".*"
162 # GDB should send one vCont;r and receive one stop reply:
163 # --> vCont;rSTART,END (range step)
165 exec_cmd_expect_vCont_count "next" 0 1
167 # Confirm the loop completed.
168 gdb_test "print a" " = 15"
169 gdb_test "print e" " = 105"
172 # Check that range stepping works well even when it is interrupted by
175 with_test_prefix "interrupt" {
176 gdb_test_no_output "set debug remote 1"
182 # GDB should send one vCont;r and receive one stop reply for
184 # --> vCont;rSTART,END (range step)
187 set vcont_r_counter 0
189 set test "send ctrl-c to GDB"
190 gdb_test_multiple "" $test {
191 -re "vCont;r\[^\r\n\]*\.\.\." {
195 -re "Program received signal SIGINT.*$gdb_prompt $" {
199 gdb_test_no_output "set debug remote 0"
201 # Check the number of 'vCont;r' packets.
202 if { $vcont_r_counter == 1 } {
203 pass "${test}: 1 vCont;r"
205 fail "${test}: 1 vCont;r"
208 # Break the loop earlier and continue range stepping.
209 gdb_test "set variable c = 0"
210 exec_cmd_expect_vCont_count "next" 0 1
213 # Check that range stepping doesn't break software watchpoints. With
214 # those, GDB needs to be notified of all single-steps, to evaluate
215 # whether the watched value changes at each step.
216 with_test_prefix "software watchpoint" {
217 gdb_test "step" "soft-watch.*" "step into multiple instruction line"
218 # A software watchpoint at PC makes the thread stop before the
219 # whole line range is over (after one single-step, actually).
220 gdb_test "watch \$pc" ".*" "set watchpoint"
221 gdb_test "step" "soft-watch.*" "step still in same line"