summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/range-stepping.exp
blob: 507d6cc8da896e7167e145e324c447d696b61424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# Copyright 2013-2015 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

load_lib "range-stepping-support.exp"

standard_testfile
set executable $testfile

if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug}] } {
    return -1
}

if ![runto_main] {
    fail "Can't run to main"
    return -1
}

if ![gdb_range_stepping_enabled] {
    unsupported "range stepping not supported by the target"
    return -1
}

# Check that range stepping can step a range of multiple instructions.

with_test_prefix "multi insns" {

    gdb_breakpoint [gdb_get_line_number "location 1"]
    gdb_continue_to_breakpoint "location 1"

    set pc_before_stepping ""
    set test "pc before stepping"
    gdb_test_multiple "print/x \$pc" $test {
	-re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
	    set pc_before_stepping $expect_out(1,string)
	    pass $test
	}
    }

    # When "next" is executed, GDB should send one vCont;s and vCont;r
    # and receive two stop replies:
    #
    # --> vCont;s  (step over breakpoint)
    # <-- T05
    # --> vCont;rSTART,END  (range step)
    # <-- T05
    set result [exec_cmd_expect_vCont_count "next" 1]
    if { $result } {
	# This is the first range-stepping test, and the simplest
	# one.  If it fails, probably the rest of the tests would
	# fail too, and the huge number of rsp packets in the test
	# with the time-consuming loop would blow up the gdb.log file.
	# Skip the rest of the tests.
	return
    }

    set pc_after_stepping ""
    set msg "pc after stepping"
    gdb_test_multiple "print/x \$pc" $msg {
	-re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
	    set pc_after_stepping $expect_out(1,string)
	    pass $msg
	}
    }

    # There should be at least two instructions between
    # PC_BEFORE_STEPPING and PC_AFTER_STEPPING.
    gdb_test "disassemble ${pc_before_stepping},${pc_after_stepping}" \
	"${hex} <main\\+${decimal}>:.*${hex} <main\\+${decimal}>:.*" \
	"stepped multiple insns"
}

# Check that range stepping can step over a function.

with_test_prefix "step over func" {

    set line_num [gdb_get_line_number "location 2"]
    gdb_test "where" "main \\(\\) at .*${srcfile}:${line_num}.*"

    # It's expected to get three stops and two 'vCont;r's.  In the C
    # code, the line of C source produces roughly the following
    # instructions:
    #
    # addr1:
    #  insn1
    #  insn2
    #  ...
    #  call func1
    # addr2:
    #  ...
    #  insn3
    # addr3:
    #  insn4
    #
    # Something like this will happen:
    # --> vCont;rADDR1,ADDR3  (range step from ADDR1 to ADDR3)
    # <-- T05  (target single-stepped to func, which is out of the step range)
    # --> $Z0,ADDR2  (place step-resume breakpoint at ADDR2)
    # --> vCont;c  (resume)
    # <-- T05  (target stops at ADDR2)
    # --> vCont;rADDR1,ADDR3  (continues range stepping)
    # <-- T05
    exec_cmd_expect_vCont_count "next" 2
}

# Check that breakpoints interrupt range stepping correctly.

with_test_prefix "breakpoint" {
    gdb_breakpoint "func1"
    # Something like this will happen:
    # --> vCont;rADDR1,ADDR3
    # <-- T05  (target single-steps to func1, which is out of the step range)
    # --> $Z0,ADDR2  (step-resume breakpoint at ADDR2)
    # --> vCont;c  (resume)
    # <-- T05  (target hits the breakpoint at func1)
    exec_cmd_expect_vCont_count "next" 1

    gdb_test "backtrace" "#0 .* func1 .*#1 .* main .*" \
	"backtrace from func1"

    # A cancelled range step should not confuse the following
    # execution commands.
    exec_cmd_expect_vCont_count "stepi" 0
    gdb_test "finish" ".*"
    gdb_test "next" ".*"
    delete_breakpoints
}

# Check that range stepping works well even when there's a loop in the
# step range.

with_test_prefix "loop" {

    # GDB should send one vCont;r and receive one stop reply:
    # --> vCont;rSTART,END  (range step)
    # <-- T05
    exec_cmd_expect_vCont_count "next" 1

    # Confirm the loop completed.
    gdb_test "print a" " = 15"
    gdb_test "print e" " = 105"
}

# Check that range stepping works well even when the target's PC was
# already within the loop's body.

with_test_prefix "loop 2" {
    # Stepi into the loop body.  15 should be large enough to make
    # sure the program stops within the loop's body.
    gdb_test "stepi 15" ".*"
    # GDB should send one vCont;r and receive one stop reply:
    # --> vCont;rSTART,END  (range step)
    # <-- T05
    exec_cmd_expect_vCont_count "next" 1

    # Confirm the loop completed.
    gdb_test "print a" " = 15"
    gdb_test "print e" " = 105"
}

# Check that range stepping works well even when it is interrupted by
# ctrl-c.

if ![target_info exists gdb,nointerrupts] {
    with_test_prefix "interrupt" {
	gdb_test_no_output "set debug remote 1"

	send_gdb "next\n"
	sleep 1
	send_gdb "\003"

	# GDB should send one vCont;r and receive one stop reply for
	# SIGINT:
	# --> vCont;rSTART,END  (range step)
	# <-- T02  (SIGINT)

	set vcont_r_counter 0

	set test "send ctrl-c to GDB"
	gdb_test_multiple "" $test {
	    -re "vCont;r\[^\r\n\]*\.\.\." {
		incr vcont_r_counter
		exp_continue
	    }
	    -re "Program received signal SIGINT.*$gdb_prompt $" {
		pass $test
	    }
	}
	gdb_test_no_output "set debug remote 0"

	# Check the number of 'vCont;r' packets.
	if { $vcont_r_counter == 1 } {
	    pass "${test}: 1 vCont;r"
	} else {
	    fail "${test}: 1 vCont;r"
	}

	# Break the loop earlier and continue range stepping.
	gdb_test "set variable c = 0"
	exec_cmd_expect_vCont_count "next" 1
    }
}

# Check that range stepping doesn't break software watchpoints.  With
# those, GDB needs to be notified of all single-steps, to evaluate
# whether the watched value changes at each step.
with_test_prefix "software watchpoint" {
    gdb_test "step" "soft-watch.*" "step into multiple instruction line"
    # A software watchpoint at PC makes the thread stop before the
    # whole line range is over (after one single-step, actually).
    gdb_test "watch \$pc" ".*" "set watchpoint"
    gdb_test "step" "soft-watch.*" "step still in same line"
}

return 0