1 # Copyright
2010-2019 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 # This file is part of the gdb testsuite.
18 # Test arm displaced stepping.
20 if {![is_aarch32_target
]} then {
21 verbose
"Skipping arm displaced stepping tests."
27 if { [prepare_for_testing
"failed to prepare" $testfile $srcfile] } {
32 #########################################
33 # Test ldm
/stm related to PC.
34 proc test_ldm_stm_pc
{} {
38 # Try to
set breakpoint
on test_ldm_stm_pc.
If symbol
'test_ldm_stm_pc'
39 # can
't be resolved, test case is compiled in Thumb mode, skip it.
40 gdb_test_multiple "break *test_ldm_stm_pc" "break test_ldm_stm_pc" {
41 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
42 pass "break test_ldm_stm_pc"
44 -re "No symbol.*\r\n$gdb_prompt $" {
45 pass "break test_ldm_stm_pc"
50 gdb_test "break *test_ldm_pc" \
51 "Breakpoint.*at.* file .*$srcfile, line.*" \
53 gdb_test "break *test_ldm_stm_pc_ret" \
54 "Breakpoint.*at.* file .*$srcfile, line.*" \
55 "break test_ldm_stm_pc_ret"
57 gdb_continue_to_breakpoint "continue to test_ldm_stm_pc" \
58 ".*stmdb.*sp\!\,.*\{lr\, pc\}.*"
59 gdb_continue_to_breakpoint "continue to test_ldm_pc" \
60 ".*ldmia.*sp\!\,.*\{pc\}.*"
61 gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \
65 #########################################
67 proc test_ldr_literal {} {
71 gdb_test_multiple "break *test_ldr_literal" "break test_ldr_literal" {
72 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
73 pass "break test_ldr_literal"
75 -re "No symbol.*\r\n$gdb_prompt $" {
80 gdb_test "break *test_ldrsb_literal" \
81 "Breakpoint.*at.* file .*$srcfile, line.*" \
82 "break test_ldrsb_literal"
83 gdb_test "break *test_ldrsh_literal" \
84 "Breakpoint.*at.* file .*$srcfile, line.*" \
85 "break test_ldrsh_literal"
86 gdb_test "break *test_ldr_literal_end" \
87 "Breakpoint.*at.* file .*$srcfile, line.*" \
88 "break test_test_ldr_literal_end"
90 gdb_continue_to_breakpoint "continue to test_ldr_literal" \
91 ".*ldrh.*r0\,.*\[pc\].*"
92 gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \
93 ".*ldrsb.*r0\,.*\[pc\].*"
94 gdb_continue_to_breakpoint "continue to test_ldrsh_literal" \
95 ".*ldrsh.*r0\,.*\[pc\].*"
96 gdb_continue_to_breakpoint "continue to test_ldr_literal_ret" \
100 proc test_ldr_literal_16 {} {
104 gdb_test_multiple "break *test_ldr_literal_16" "break test_ldr_literal_16" {
105 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
106 pass "break test_ldr_literal"
108 -re "No symbol.*\r\n$gdb_prompt $" {
112 gdb_test "break *test_ldr_literal_16_end" \
113 "Breakpoint.*at.* file .*$srcfile, line.*" \
114 "break test_ldr_literal_16_end"
116 gdb_continue_to_breakpoint "continue to test_ldr_literal_16" \
118 gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \
122 ##########################################
124 proc test_call_ret {} {
128 gdb_test "break *test_call" \
129 "Breakpoint.*at.* file .*$srcfile, line.*" \
132 gdb_test "break *test_call_end" \
133 "Breakpoint.*at.* file .*$srcfile, line.*" \
134 "break test_call_end"
135 gdb_test "break *test_ret" \
136 "Breakpoint.*at.* file .*$srcfile, line.*" \
138 gdb_test "break *test_ret_end" \
139 "Breakpoint.*at.* file .*$srcfile, line.*" \
142 gdb_continue_to_breakpoint "test_call" ".*bl test_call_subr.*"
143 gdb_continue_to_breakpoint "test_call_end" \
144 ".*@ Location test_call_end.*"
145 gdb_continue_to_breakpoint "test_ret" \
147 gdb_continue_to_breakpoint "continue to test_ret_end" \
148 ".*@ Location test_ret_end.*"
152 #########################################
154 proc test_branch {} {
156 gdb_test "break *test_branch" \
157 "Breakpoint.*at.* file .*$srcfile, line.*" \
159 gdb_test "break *L_branch" \
160 "Breakpoint.*at.* file .*$srcfile, line.*" \
163 gdb_continue_to_breakpoint "continue to test_branch" \
165 gdb_continue_to_breakpoint "continue to Lbranch" \
169 #########################################
172 proc test_ldr_from_pc {} {
174 gdb_test "break *test_ldr_pc" \
175 "Breakpoint.*at.* file .*$srcfile, line.*" \
177 gdb_test "break test_ldr_pc_ret" \
178 "Breakpoint.*at.* file .*$srcfile, line.*" \
179 "break test_ldr_pc_ret"
181 gdb_continue_to_breakpoint "continue to test_ldr_pc" \
182 ".*ldr.*r1\,.*\[pc, #0\].*"
183 gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \
187 #########################################
190 proc test_cbz_cbnz {} {
194 gdb_test_multiple "break *test_zero_cbnz" "break test_zero_cbnz" {
195 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
196 pass "break test_ldr_literal"
198 -re "No symbol.*\r\n$gdb_prompt $" {
203 gdb_test "break *test_zero_cbz" \
204 "Breakpoint.*at.* file .*$srcfile, line.*" \
205 "break test_zero_cbz"
206 gdb_test "break *test_non_zero_cbnz" \
207 "Breakpoint.*at.* file .*$srcfile, line.*" \
208 "break test_non_zero_cbnz"
209 gdb_test "break *test_non_zero_cbz" \
210 "Breakpoint.*at.* file .*$srcfile, line.*" \
211 "break test_non_zero_cbz"
213 gdb_continue_to_breakpoint "continue to test_zero_cbnz" \
214 ".*cbnz.*r0\,.*\.L3.*"
215 gdb_continue_to_breakpoint "continue to test_zero_cbz" \
216 ".*cbz.*r0\,.*\.L3.*"
217 gdb_continue_to_breakpoint "continue to test_non_zero_cbz" \
218 ".*cbz.*r0\,.*\.L4.*"
219 gdb_continue_to_breakpoint "continue to test_non_zero_cbnz" \
220 ".*cbnz.*r0\,.*\.L4.*"
229 gdb_test_multiple "break *test_adr" "break test_adr" {
230 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
231 pass "break test_adr"
233 -re "No symbol.*\r\n$gdb_prompt $" {
238 gdb_test "break *test_adr_end" \
239 "Breakpoint.*at.* file .*$srcfile, line.*" \
242 gdb_continue_to_breakpoint "test_adr" \
243 ".*adr.*r0\,.*\.L8.*"
244 gdb_continue_to_breakpoint "test_adr_end" \
248 proc test_adr_32bit {} {
252 gdb_test_multiple "break *test_adr_32bit" "break test_adr_32bit" {
253 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
254 pass "break test_adr"
256 -re "No symbol.*\r\n$gdb_prompt $" {
261 gdb_test "break *test_adr_32bit_after" \
262 "Breakpoint.*at.* file .*$srcfile, line.*" \
263 "break test_adr_32bit_after"
265 gdb_test "break *test_adr_32bit_end" \
266 "Breakpoint.*at.* file .*$srcfile, line.*" \
267 "break test_adr_32bit_end"
269 gdb_continue_to_breakpoint "test_adr_32bit" \
270 ".*adr.*r0\,.*\.L6.*"
271 gdb_continue_to_breakpoint "test_adr_32bit_after" \
272 ".*adr.*r0\,.*\.L6.*"
273 gdb_continue_to_breakpoint "test_adr_32bit_end" \
277 #########################################
279 proc test_pop_pc {} {
281 gdb_test "break *test_pop_pc_1" \
282 "Breakpoint.*at.* file .*$srcfile, line.*" \
283 "break test_pop_pc_1"
284 gdb_test "break *test_pop_pc_2" \
285 "Breakpoint.*at.* file .*$srcfile, line.*" \
286 "break test_pop_pc_2"
287 gdb_test "break *test_pop_pc_3" \
288 "Breakpoint.*at.* file .*$srcfile, line.*" \
289 "break test_pop_pc_3"
291 gdb_test "break *test_pop_pc_ret" \
292 "Breakpoint.*at.* file .*$srcfile, line.*" \
293 "break test_pop_pc_ret"
295 gdb_test "break *test_pop_pc_1_right" \
296 "Breakpoint.*at.* file .*$srcfile, line.*" \
297 "break test_pop_pc_1_right"
298 gdb_test "break *test_pop_pc_1_wrong" \
299 "Breakpoint.*at.* file .*$srcfile, line.*" \
300 "break test_pop_pc_1_wrong"
301 gdb_test "break *test_pop_pc_2_right" \
302 "Breakpoint.*at.* file .*$srcfile, line.*" \
303 "break test_pop_pc_2_right"
304 gdb_test "break *test_pop_pc_2_wrong" \
305 "Breakpoint.*at.* file .*$srcfile, line.*" \
306 "break test_pop_pc_2_wrong"
307 gdb_test "break *test_pop_pc_3_right" \
308 "Breakpoint.*at.* file .*$srcfile, line.*" \
309 "break test_pop_pc_3_right"
310 gdb_test "break *test_pop_pc_3_wrong" \
311 "Breakpoint.*at.* file .*$srcfile, line.*" \
312 "break test_pop_pc_1_wrong"
314 gdb_continue_to_breakpoint "continue to test_pop_pc_1" \
316 gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \
319 gdb_continue_to_breakpoint "continue to test_pop_pc_2" \
321 gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \
323 gdb_continue_to_breakpoint "continue to test_pop_pc_3" \
324 ".*\{r0\,r1\,r2\,r3\,r4\,r5\,r6\,r7\,pc\}.*"
325 gdb_continue_to_breakpoint "continue to test_pop_pc_3_check" \
327 gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \
331 ###########################################
333 proc test_str_pc {} {
337 gdb_test_multiple "break *test_str_pc" "break test_str_pc" {
338 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
339 pass "break test_str_pc"
341 -re "No symbol.*\r\n$gdb_prompt $" {
342 pass "break test_str_pc"
346 gdb_test "break *test_str_pc_end" \
347 "Breakpoint.*at.* file .*$srcfile, line.*" \
348 "break test_str_pc_end"
350 # Set breakpoint on both lables pc_offset_right and pc_offset_wrong
351 gdb_test "break *pc_offset_right" \
352 "Breakpoint.*at.* file .*$srcfile, line.*" \
353 "break pc_offset_right"
354 gdb_test "break *pc_offset_wrong" \
355 "Breakpoint.*at.* file .*$srcfile, line.*" \
356 "break pc_offset_wrong"
358 gdb_continue_to_breakpoint "continue to test_str_pc" \
359 ".*str.*pc\,.*\[sp, #-4\].*"
360 # If breakpoint on lable pc_offset_wrong is hit, that means the offset
361 # computed in displaced stepping is different from offset computed
362 # without displaced stepping. Report a failure.
363 gdb_continue_to_breakpoint "continue to pc_offset_right" \
364 ".*b.*test_str_pc_end.*"
365 gdb_continue_to_breakpoint "continue to test_str_pc_end" \
369 # Test 16 bit thumb instruction 'add rd
, pc
'.
371 proc test_add_rn_pc {} {
372 global srcfile gdb_prompt
374 set test "break test_add_rn_pc"
375 gdb_test_multiple "break *test_add_rn_pc" $test {
376 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
379 -re "No symbol.*\r\n$gdb_prompt $" {
384 gdb_continue_to_breakpoint "continue to test_add_rn_pc" \
387 gdb_test "break *test_add_rn_pc_start" \
388 "Breakpoint.*at.* file .*$srcfile, line.*" \
389 "break test_add_rn_pc_start"
391 gdb_continue_to_breakpoint "continue to test_add_rn_pc_start" \
394 set pc_val [get_integer_valueof "\$pc" 0]
396 gdb_test "break *test_add_rn_pc_end" \
397 "Breakpoint.*at.* file .*$srcfile, line.*" \
398 "break test_add_rn_pc_end"
400 gdb_continue_to_breakpoint "continue to test_add_rn_pc_end" \
403 set r3_val [get_integer_valueof "\$r3" 0]
404 # Test the value in r3 is correct.
405 gdb_assert { [expr {$pc_val + 4 + 4} == $r3_val] }
408 # Turn displaced stepping off before runto main. When displaced stepping
409 # is on, and we type 'run
', GDB will first try to single step on _dl_debug_state,
410 # which is in library might be compiled in Thumb.
411 gdb_test_no_output "set displaced-stepping off"
413 if ![runto_main] then {
414 fail "can't run to main
"
418 gdb_test_no_output
"set displaced-stepping on"
419 gdb_test
"show displaced-stepping" ".* displaced stepping .* is on.*"
445 ##########################################
447 # Done
, run
program to exit.
449 gdb_continue_to_end
"arm-disp-step"