Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.arch / arm-disp-step.exp
blob4319debda7dcbf4d0d0a840c2cfad5a8892bb7ae
1 # Copyright 2010-2024 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 require is_aarch32_target
22 standard_testfile .S
24 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
25     return -1
29 #########################################
30 # Test ldm/stm related to PC.
31 proc test_ldm_stm_pc {} {
32     global srcfile
33     global gdb_prompt
35     # Try to set breakpoint on test_ldm_stm_pc.  If symbol 'test_ldm_stm_pc'
36     # can't be resolved, test case is compiled in Thumb mode, skip it.
37     gdb_test_multiple "break *test_ldm_stm_pc" "" {
38         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
39             pass $gdb_test_name
40         }
41         -re "No symbol.*\r\n$gdb_prompt $" {
42             pass $gdb_test_name
43             return 0
44         }
45     }
47     gdb_test "break *test_ldm_pc" \
48         "Breakpoint.*at.* file .*$srcfile, line.*" \
49         "break test_ldm_pc"
50     gdb_test "break *test_ldm_stm_pc_ret" \
51         "Breakpoint.*at.* file .*$srcfile, line.*" \
52         "break test_ldm_stm_pc_ret"
54     gdb_continue_to_breakpoint "continue to test_ldm_stm_pc" \
55         ".*stmdb.*sp\!\,.*\{lr\, pc\}.*"
56     gdb_continue_to_breakpoint "continue to test_ldm_pc" \
57         ".*ldmia.*sp\!\,.*\{pc\}.*"
58     gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \
59         ".*bx lr.*"
62 #########################################
63 # Test ldrX literal
64 proc test_ldr_literal {} {
65     global srcfile
66     global gdb_prompt
68     gdb_test_multiple "break *test_ldr_literal" "" {
69        -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
70            pass $gdb_test_name
71        }
72        -re "No symbol.*\r\n$gdb_prompt $" {
73            return 0
74        }
75     }
77     gdb_test "break *test_ldrsb_literal" \
78        "Breakpoint.*at.* file .*$srcfile, line.*" \
79        "break test_ldrsb_literal"
80     gdb_test "break *test_ldrsh_literal" \
81        "Breakpoint.*at.* file .*$srcfile, line.*" \
82        "break test_ldrsh_literal"
83     gdb_test "break *test_ldr_literal_end" \
84        "Breakpoint.*at.* file .*$srcfile, line.*" \
85        "break test_test_ldr_literal_end"
87     gdb_continue_to_breakpoint "continue to test_ldr_literal" \
88        ".*ldrh.*r0\,.*\[pc\].*"
89     gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \
90        ".*ldrsb.*r0\,.*\[pc\].*"
91     gdb_continue_to_breakpoint "continue to test_ldrsh_literal" \
92        ".*ldrsh.*r0\,.*\[pc\].*"
93     gdb_continue_to_breakpoint "continue to test_ldr_literal_ret" \
94        ".*bx lr.*"
97 proc test_ldr_literal_16 {} {
98     global srcfile
99     global gdb_prompt
101     gdb_test_multiple "break *test_ldr_literal_16" "" {
102         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
103             pass $gdb_test_name
104         }
105         -re "No symbol.*\r\n$gdb_prompt $" {
106             return 0
107         }
108     }
109     gdb_test "break *test_ldr_literal_16_end" \
110         "Breakpoint.*at.* file .*$srcfile, line.*" \
111         "break test_ldr_literal_16_end"
113     gdb_continue_to_breakpoint "continue to test_ldr_literal_16" \
114         ".*ldr.*r0\,.*L2.*"
115     gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \
116         ".*bx lr.*"
119 ##########################################
120 # Test call/ret.
121 proc test_call_ret {} {
122     global srcfile
123     global testfile
125     gdb_test "break *test_call" \
126         "Breakpoint.*at.* file .*$srcfile, line.*" \
127         "break test_call"
129     gdb_test "break *test_call_end" \
130         "Breakpoint.*at.* file .*$srcfile, line.*" \
131         "break test_call_end"
132     gdb_test "break *test_ret" \
133         "Breakpoint.*at.* file .*$srcfile, line.*" \
134         "break test_ret"
135     gdb_test "break *test_ret_end" \
136         "Breakpoint.*at.* file .*$srcfile, line.*" \
137         "break test_ret_end"
139     gdb_continue_to_breakpoint "test_call" ".*bl test_call_subr.*"
140     gdb_continue_to_breakpoint "test_call_end" \
141         ".*@ Location test_call_end.*"
142     gdb_continue_to_breakpoint "test_ret" \
143         ".*bx lr.*"
144     gdb_continue_to_breakpoint "continue to test_ret_end" \
145         ".*@ Location test_ret_end.*"
149 #########################################
150 # Test branch
151 proc test_branch {} {
152     global srcfile
153     gdb_test "break *test_branch" \
154         "Breakpoint.*at.* file .*$srcfile, line.*" \
155         "break test_branch"
156     gdb_test "break *L_branch" \
157         "Breakpoint.*at.* file .*$srcfile, line.*" \
158         "break Lbranch"
160     gdb_continue_to_breakpoint "continue to test_branch" \
161         ".*b.*L_branch.*"
162     gdb_continue_to_breakpoint "continue to Lbranch" \
163         ".*bx lr.*"
166 #########################################
168 # Test ldr from pc
169 proc test_ldr_from_pc {} {
170     global srcfile
171     gdb_test "break *test_ldr_pc" \
172         "Breakpoint.*at.* file .*$srcfile, line.*" \
173         "break test_ldr_pc"
174     gdb_test "break test_ldr_pc_ret" \
175         "Breakpoint.*at.* file .*$srcfile, line.*" \
176         "break test_ldr_pc_ret"
178     gdb_continue_to_breakpoint "continue to test_ldr_pc" \
179         ".*ldr.*r1\,.*\[pc, #0\].*"
180     gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \
181         ".*bx lr.*"
184 #########################################
186 # Test cbz and cbnz
187 proc test_cbz_cbnz {} {
188     global srcfile
189     global gdb_prompt
191     gdb_test_multiple "break *test_zero_cbnz" "" {
192         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
193             pass $gdb_test_name
194         }
195         -re "No symbol.*\r\n$gdb_prompt $" {
196             return 0
197         }
198     }
200     gdb_test "break *test_zero_cbz" \
201         "Breakpoint.*at.* file .*$srcfile, line.*" \
202         "break test_zero_cbz"
203     gdb_test "break *test_non_zero_cbnz" \
204         "Breakpoint.*at.* file .*$srcfile, line.*" \
205         "break test_non_zero_cbnz"
206     gdb_test "break *test_non_zero_cbz" \
207         "Breakpoint.*at.* file .*$srcfile, line.*" \
208         "break test_non_zero_cbz"
210     gdb_continue_to_breakpoint "continue to test_zero_cbnz" \
211         ".*cbnz.*r0\,.*\.L3.*"
212     gdb_continue_to_breakpoint "continue to test_zero_cbz" \
213         ".*cbz.*r0\,.*\.L3.*"
214     gdb_continue_to_breakpoint "continue to test_non_zero_cbz" \
215         ".*cbz.*r0\,.*\.L4.*"
216     gdb_continue_to_breakpoint "continue to test_non_zero_cbnz" \
217         ".*cbnz.*r0\,.*\.L4.*"
220 # Test adr
222 proc test_adr {} {
223     global srcfile
224     global gdb_prompt
226     gdb_test_multiple "break *test_adr" "" {
227         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
228             pass $gdb_test_name
229         }
230         -re "No symbol.*\r\n$gdb_prompt $" {
231             return 0
232         }
233     }
235     gdb_test "break *test_adr_end" \
236         "Breakpoint.*at.* file .*$srcfile, line.*" \
237         "break test_adr_end"
239     gdb_continue_to_breakpoint "test_adr" \
240         ".*adr.*r0\,.*\.L8.*"
241     gdb_continue_to_breakpoint "test_adr_end" \
242         ".*bx lr.*"
245 proc test_adr_32bit {} {
246     global srcfile
247     global gdb_prompt
249     gdb_test_multiple "break *test_adr_32bit" "" {
250         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
251             pass $gdb_test_name
252         }
253         -re "No symbol.*\r\n$gdb_prompt $" {
254             return 0
255         }
256     }
258     gdb_test "break *test_adr_32bit_after" \
259         "Breakpoint.*at.* file .*$srcfile, line.*" \
260         "break test_adr_32bit_after"
262     gdb_test "break *test_adr_32bit_end" \
263         "Breakpoint.*at.* file .*$srcfile, line.*" \
264         "break test_adr_32bit_end"
266     gdb_continue_to_breakpoint "test_adr_32bit" \
267         ".*adr.*r0\,.*\.L6.*"
268     gdb_continue_to_breakpoint "test_adr_32bit_after" \
269         ".*adr.*r0\,.*\.L6.*"
270     gdb_continue_to_breakpoint "test_adr_32bit_end" \
271         ".*bx lr.*"
274 #########################################
275 # Test pop to PC
276 proc test_pop_pc {} {
277     global srcfile
278     gdb_test "break *test_pop_pc_1" \
279         "Breakpoint.*at.* file .*$srcfile, line.*" \
280         "break test_pop_pc_1"
281     gdb_test "break *test_pop_pc_2" \
282         "Breakpoint.*at.* file .*$srcfile, line.*" \
283         "break test_pop_pc_2"
284     gdb_test "break *test_pop_pc_3" \
285         "Breakpoint.*at.* file .*$srcfile, line.*" \
286         "break test_pop_pc_3"
288     gdb_test "break *test_pop_pc_ret" \
289         "Breakpoint.*at.* file .*$srcfile, line.*" \
290         "break test_pop_pc_ret"
292     gdb_test "break *test_pop_pc_1_right" \
293         "Breakpoint.*at.* file .*$srcfile, line.*" \
294         "break test_pop_pc_1_right"
295     gdb_test "break *test_pop_pc_1_wrong" \
296         "Breakpoint.*at.* file .*$srcfile, line.*" \
297         "break test_pop_pc_1_wrong"
298     gdb_test "break *test_pop_pc_2_right" \
299         "Breakpoint.*at.* file .*$srcfile, line.*" \
300         "break test_pop_pc_2_right"
301     gdb_test "break *test_pop_pc_2_wrong" \
302         "Breakpoint.*at.* file .*$srcfile, line.*" \
303         "break test_pop_pc_2_wrong"
304     gdb_test "break *test_pop_pc_3_right" \
305         "Breakpoint.*at.* file .*$srcfile, line.*" \
306         "break test_pop_pc_3_right"
307     gdb_test "break *test_pop_pc_3_wrong" \
308         "Breakpoint.*at.* file .*$srcfile, line.*" \
309         "break test_pop_pc_3_wrong"
311     gdb_continue_to_breakpoint "continue to test_pop_pc_1" \
312         ".*b.*\{r1\, pc\}.*"
313     gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \
314         ".*b.*right.*"
316     gdb_continue_to_breakpoint "continue to test_pop_pc_2" \
317         ".*\{pc\}.*"
318     gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \
319         ".*b.*right.*"
320     gdb_continue_to_breakpoint "continue to test_pop_pc_3" \
321         ".*\{r0\,r1\,r2\,r3\,r4\,r5\,r6\,r7\,pc\}.*"
322     gdb_continue_to_breakpoint "continue to test_pop_pc_3_check" \
323         ".*b.*right.*"
324     gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \
325         ".*r7.*"
328 ###########################################
330 proc test_str_pc {} {
331     global srcfile
332     global gdb_prompt
334     gdb_test_multiple "break *test_str_pc" "" {
335         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
336             pass $gdb_test_name
337         }
338         -re "No symbol.*\r\n$gdb_prompt $" {
339             pass $gdb_test_name
340             return
341         }
342     }
343     gdb_test "break *test_str_pc_end" \
344         "Breakpoint.*at.* file .*$srcfile, line.*" \
345         "break test_str_pc_end"
347     # Set breakpoint on both lables pc_offset_right and pc_offset_wrong
348     gdb_test "break *pc_offset_right" \
349         "Breakpoint.*at.* file .*$srcfile, line.*" \
350         "break pc_offset_right"
351     gdb_test "break *pc_offset_wrong" \
352         "Breakpoint.*at.* file .*$srcfile, line.*" \
353         "break pc_offset_wrong"
355     gdb_continue_to_breakpoint "continue to test_str_pc" \
356         ".*str.*pc\,.*\[sp, #-4\].*"
357     # If breakpoint on lable pc_offset_wrong is hit, that means the offset
358     # computed in displaced stepping is different from offset computed
359     # without displaced stepping.  Report a failure.
360     gdb_continue_to_breakpoint "continue to pc_offset_right" \
361         ".*b.*test_str_pc_end.*"
362     gdb_continue_to_breakpoint "continue to test_str_pc_end" \
363         ".*bx lr.*"
366 # Test 16 bit thumb instruction 'add rd, pc'.
368 proc test_add_rn_pc {} {
369     global srcfile gdb_prompt
371     gdb_test_multiple "break *test_add_rn_pc" "" {
372         -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
373             pass $gdb_test_name
374         }
375         -re "No symbol.*\r\n$gdb_prompt $" {
376             return
377         }
378     }
380     gdb_continue_to_breakpoint "continue to test_add_rn_pc" \
381         ".*mov.*r3, 4.*"
383     gdb_test "break *test_add_rn_pc_start" \
384         "Breakpoint.*at.* file .*$srcfile, line.*" \
385         "break test_add_rn_pc_start"
387     gdb_continue_to_breakpoint "continue to test_add_rn_pc_start" \
388         ".*add.*r3,.*pc.*"
390     set pc_val [get_integer_valueof "\$pc" 0]
392     gdb_test "break *test_add_rn_pc_end" \
393         "Breakpoint.*at.* file .*$srcfile, line.*" \
394         "break test_add_rn_pc_end"
396     gdb_continue_to_breakpoint "continue to test_add_rn_pc_end" \
397         ".*bx lr.*"
399     set r3_val [get_integer_valueof "\$r3" 0]
400     # Test the value in r3 is correct.
401     gdb_assert { [expr {$pc_val + 4 + 4} == $r3_val] }
404 # Turn displaced stepping off before runto main. When displaced stepping
405 # is on, and we type 'run', GDB will first try to single step on _dl_debug_state,
406 # which is in library might be compiled in Thumb.
407 gdb_test_no_output "set displaced-stepping off"
409 if {![runto_main]} {
410     return 0
413 gdb_test_no_output "set displaced-stepping on"
414 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
416 test_call_ret
418 test_branch
420 test_ldr_from_pc
422 test_ldm_stm_pc
424 test_ldr_literal
426 test_ldr_literal_16
428 test_cbz_cbnz
430 test_adr
432 test_adr_32bit
434 test_pop_pc
436 test_str_pc
438 test_add_rn_pc
440 ##########################################
442 # Done, run program to exit.
444 gdb_continue_to_end "arm-disp-step"