Fix gdb.info build failure
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / range-stepping.exp
CommitLineData
bc5065a7
PA
1# Copyright 2013 Free Software Foundation, Inc.
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
16load_lib "range-stepping-support.exp"
17
18standard_testfile
19set executable $testfile
20
21if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug}] } {
22 return -1
23}
24
25if ![runto_main] {
26 fail "Can't run to main"
27 return -1
28}
29
30# Check whether range stepping is supported by the target.
31
32proc gdb_range_stepping_enabled { } {
33 global gdb_prompt
34
35 set command "set range-stepping on"
36 set message "probe range-stepping support"
37 gdb_test_multiple $command $message {
38 -re "Range stepping is not supported.*\r\n$gdb_prompt $" {
39 pass $message
40 return 0
41 }
42 -re "^$command\r\n$gdb_prompt $" {
43 pass $message
44 return 1
45 }
46 }
47
48 return 0
49}
50
51if ![gdb_range_stepping_enabled] {
52 unsupported "range stepping not supported by the target"
53 return -1
54}
55
56# Check that range stepping can step a range of multiple instructions.
57
58with_test_prefix "multi insns" {
59
60 gdb_breakpoint [gdb_get_line_number "location 1"]
61 gdb_continue_to_breakpoint "location 1"
62
63 set pc_before_stepping ""
64 set test "pc before stepping"
65 gdb_test_multiple "print/x \$pc" $test {
66 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
67 set pc_before_stepping $expect_out(1,string)
68 pass $test
69 }
70 }
71
72 # When "next" is executed, GDB should send one vCont;s and vCont;r
73 # and receive two stop replies:
74 #
75 # --> vCont;s (step over breakpoint)
76 # <-- T05
77 # --> vCont;rSTART,END (range step)
78 # <-- T05
79 exec_cmd_expect_vCont_count "next" 1 1
80
81 set pc_after_stepping ""
82 set msg "pc after stepping"
83 gdb_test_multiple "print/x \$pc" $msg {
84 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
85 set pc_after_stepping $expect_out(1,string)
86 pass $msg
87 }
88 }
89
90 # There should be at least two instructions between
91 # PC_BEFORE_STEPPING and PC_AFTER_STEPPING.
92 gdb_test "disassemble ${pc_before_stepping},${pc_after_stepping}" \
93 "${hex} <main\\+${decimal}>:.*${hex} <main\\+${decimal}>:.*" \
94 "stepped multiple insns"
95}
96
97# Check that range stepping can step over a function.
98
99with_test_prefix "step over func" {
100
101 set line_num [gdb_get_line_number "location 2"]
102 gdb_test "where" "main \\(\\) at .*${srcfile}:${line_num}.*"
103
104 # It's expected to get three stops and two 'vCont;r's. In the C
105 # code, the line of C source produces roughly the following
106 # instructions:
107 #
108 # addr1:
109 # insn1
110 # insn2
111 # ...
112 # call func1
113 # addr2:
114 # ...
115 # insn3
116 # addr3:
117 # insn4
118 #
119 # Something like this will happen:
120 # --> vCont;rADDR1,ADDR3 (range step from ADDR1 to ADDR3)
121 # <-- T05 (target single-stepped to func, which is out of the step range)
122 # --> $Z0,ADDR2 (place step-resume breakpoint at ADDR2)
123 # --> vCont;c (resume)
124 # <-- T05 (target stops at ADDR2)
125 # --> vCont;rADDR1,ADDR3 (continues range stepping)
126 # <-- T05
127 exec_cmd_expect_vCont_count "next" 0 2
128}
129
130# Check that breakpoints interrupt range stepping correctly.
131
132with_test_prefix "breakpoint" {
133 gdb_breakpoint "func1"
134 # Something like this will happen:
135 # --> vCont;rADDR1,ADDR3
136 # <-- T05 (target single-steps to func1, which is out of the step range)
137 # --> $Z0,ADDR2 (step-resume breakpoint at ADDR2)
138 # --> vCont;c (resume)
139 # <-- T05 (target hits the breakpoint at func1)
140 exec_cmd_expect_vCont_count "next" 0 1
141
142 gdb_test "backtrace" "#0 .* func1 .*#1 .* main .*" \
143 "backtrace from func1"
144
145 # A cancelled range step should not confuse the following
146 # execution commands.
147 exec_cmd_expect_vCont_count "stepi" 1 0
148 gdb_test "finish" ".*"
149 gdb_test "next" ".*"
150 delete_breakpoints
151}
152
153# Check that range stepping works well even when there's a loop in the
154# step range.
155
156with_test_prefix "loop" {
157
158 # GDB should send one vCont;r and receive one stop reply:
159 # --> vCont;rSTART,END (range step)
160 # <-- T05
161 exec_cmd_expect_vCont_count "next" 0 1
162
163 # Confirm the loop completed.
164 gdb_test "print a" " = 15"
165 gdb_test "print e" " = 105"
166}
167
168# Check that range stepping works well even when the target's PC was
169# already within the loop's body.
170
171with_test_prefix "loop 2" {
172 # Stepi into the loop body. 15 should be large enough to make
173 # sure the program stops within the loop's body.
174 gdb_test "stepi 15" ".*"
175 # GDB should send one vCont;r and receive one stop reply:
176 # --> vCont;rSTART,END (range step)
177 # <-- T05
178 exec_cmd_expect_vCont_count "next" 0 1
179
180 # Confirm the loop completed.
181 gdb_test "print a" " = 15"
182 gdb_test "print e" " = 105"
183}
184
185# Check that range stepping works well even when it is interrupted by
186# ctrl-c.
187
188with_test_prefix "interrupt" {
189 gdb_test_no_output "set debug remote 1"
190
191 send_gdb "next\n"
192 sleep 1
193 send_gdb "\003"
194
195 # GDB should send one vCont;r and receive one stop reply for
196 # SIGINT:
197 # --> vCont;rSTART,END (range step)
198 # <-- T02 (SIGINT)
199
200 set vcont_r_counter 0
201
202 set test "send ctrl-c to GDB"
203 gdb_test_multiple "" $test {
204 -re "vCont;r\[^\r\n\]*\.\.\." {
205 incr vcont_r_counter
206 exp_continue
207 }
208 -re "Program received signal SIGINT.*$gdb_prompt $" {
209 pass $test
210 }
211 }
212 gdb_test_no_output "set debug remote 0"
213
214 # Check the number of 'vCont;r' packets.
215 if { $vcont_r_counter == 1 } {
216 pass "${test}: 1 vCont;r"
217 } else {
218 fail "${test}: 1 vCont;r"
219 }
220
221 # Break the loop earlier and continue range stepping.
222 gdb_test "set variable c = 0"
223 exec_cmd_expect_vCont_count "next" 0 1
224}
225
226# Check that range stepping doesn't break software watchpoints. With
227# those, GDB needs to be notified of all single-steps, to evaluate
228# whether the watched value changes at each step.
229with_test_prefix "software watchpoint" {
230 gdb_test "step" "soft-watch.*" "step into multiple instruction line"
231 # A software watchpoint at PC makes the thread stop before the
232 # whole line range is over (after one single-step, actually).
233 gdb_test "watch \$pc" ".*" "set watchpoint"
234 gdb_test "step" "soft-watch.*" "step still in same line"
235}
236
237return 0
This page took 0.05791 seconds and 4 git commands to generate.