Update copyright year range in all GDB files.
[binutils-gdb.git] / gdb / testsuite / gdb.arch / arm-disp-step.exp
blob034b8363b7b1c2a994880fd43eca0d12806e4c71
1 # Copyright 2010-2020 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."
22     return
25 standard_testfile .S
27 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
28     return -1
32 #########################################
33 # Test ldm/stm related to PC.
34 proc test_ldm_stm_pc {} {
35     global srcfile
36     global gdb_prompt
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"
43         }
44         -re "No symbol.*\r\n$gdb_prompt $" {
45             pass "break test_ldm_stm_pc"
46             return 0
47         }
48     }
50     gdb_test "break *test_ldm_pc" \
51         "Breakpoint.*at.* file .*$srcfile, line.*" \
52         "break test_ldm_pc"
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" \
62         ".*bx lr.*"
65 #########################################
66 # Test ldrX literal
67 proc test_ldr_literal {} {
68     global srcfile
69     global gdb_prompt
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"
74        }
75        -re "No symbol.*\r\n$gdb_prompt $" {
76            return 0
77        }
78     }
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" \
97        ".*bx lr.*"
100 proc test_ldr_literal_16 {} {
101     global srcfile
102     global gdb_prompt
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"
107         }
108         -re "No symbol.*\r\n$gdb_prompt $" {
109             return 0
110         }
111     }
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" \
117         ".*ldr.*r0\,.*L2.*"
118     gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \
119         ".*bx lr.*"
122 ##########################################
123 # Test call/ret.
124 proc test_call_ret {} {
125     global srcfile
126     global testfile
128     gdb_test "break *test_call" \
129         "Breakpoint.*at.* file .*$srcfile, line.*" \
130         "break test_call"
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.*" \
137         "break test_ret"
138     gdb_test "break *test_ret_end" \
139         "Breakpoint.*at.* file .*$srcfile, line.*" \
140         "break test_ret_end"
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" \
146         ".*bx lr.*"
147     gdb_continue_to_breakpoint "continue to test_ret_end" \
148         ".*@ Location test_ret_end.*"
152 #########################################
153 # Test branch
154 proc test_branch {} {
155     global srcfile
156     gdb_test "break *test_branch" \
157         "Breakpoint.*at.* file .*$srcfile, line.*" \
158         "break test_branch"
159     gdb_test "break *L_branch" \
160         "Breakpoint.*at.* file .*$srcfile, line.*" \
161         "break Lbranch"
163     gdb_continue_to_breakpoint "continue to test_branch" \
164         ".*b.*L_branch.*"
165     gdb_continue_to_breakpoint "continue to Lbranch" \
166         ".*bx lr.*"
169 #########################################
171 # Test ldr from pc
172 proc test_ldr_from_pc {} {
173     global srcfile
174     gdb_test "break *test_ldr_pc" \
175         "Breakpoint.*at.* file .*$srcfile, line.*" \
176         "break test_ldr_pc"
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" \
184         ".*bx lr.*"
187 #########################################
189 # Test cbz and cbnz
190 proc test_cbz_cbnz {} {
191     global srcfile
192     global gdb_prompt
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"
197         }
198         -re "No symbol.*\r\n$gdb_prompt $" {
199             return 0
200         }
201     }
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.*"
223 # Test adr
225 proc test_adr {} {
226     global srcfile
227     global gdb_prompt
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"
232         }
233         -re "No symbol.*\r\n$gdb_prompt $" {
234             return 0
235         }
236     }
238     gdb_test "break *test_adr_end" \
239         "Breakpoint.*at.* file .*$srcfile, line.*" \
240         "break test_adr_end"
242     gdb_continue_to_breakpoint "test_adr" \
243         ".*adr.*r0\,.*\.L8.*"
244     gdb_continue_to_breakpoint "test_adr_end" \
245         ".*bx lr.*"
248 proc test_adr_32bit {} {
249     global srcfile
250     global gdb_prompt
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"
255         }
256         -re "No symbol.*\r\n$gdb_prompt $" {
257             return 0
258         }
259     }
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" \
274         ".*bx lr.*"
277 #########################################
278 # Test pop to PC
279 proc test_pop_pc {} {
280     global srcfile
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" \
315         ".*b.*\{r1\, pc\}.*"
316     gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \
317         ".*b.*right.*"
319     gdb_continue_to_breakpoint "continue to test_pop_pc_2" \
320         ".*\{pc\}.*"
321     gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \
322         ".*b.*right.*"
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" \
326         ".*b.*right.*"
327     gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \
328         ".*r7.*"
331 ###########################################
333 proc test_str_pc {} {
334     global srcfile
335     global gdb_prompt
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"
340         }
341         -re "No symbol.*\r\n$gdb_prompt $" {
342             pass "break test_str_pc"
343             return
344         }
345     }
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" \
366         ".*bx lr.*"
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 $" {
377             pass $test
378         }
379         -re "No symbol.*\r\n$gdb_prompt $" {
380             return
381         }
382     }
384     gdb_continue_to_breakpoint "continue to test_add_rn_pc" \
385         ".*mov.*r3, 4.*"
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" \
392         ".*add.*r3,.*pc.*"
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" \
401         ".*bx lr.*"
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"
415     return 0
418 gdb_test_no_output "set displaced-stepping on"
419 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
421 test_call_ret
423 test_branch
425 test_ldr_from_pc
427 test_ldm_stm_pc
429 test_ldr_literal
431 test_ldr_literal_16
433 test_cbz_cbnz
435 test_adr
437 test_adr_32bit
439 test_pop_pc
441 test_str_pc
443 test_add_rn_pc
445 ##########################################
447 # Done, run program to exit.
449 gdb_continue_to_end "arm-disp-step"