1 # Copyright 2010-2014 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 {![istarget "arm*-*-*"]} then {
21 verbose "Skipping arm displaced stepping tests."
25 set testfile "arm-disp-step"
26 set srcfile ${testfile}.S
27 set binfile ${objdir}/${subdir}/${testfile}
29 set additional_flags "-Wa,-g"
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
32 untested arm-disp-step.exp
37 #########################################
38 # Test ldm/stm related to PC.
39 proc test_ldm_stm_pc {} {
43 # Try to set breakpoint on test_ldm_stm_pc. If symbol 'test_ldm_stm_pc'
44 # can't be resolved, test case is compiled in Thumb mode, skip it.
45 gdb_test_multiple "break *test_ldm_stm_pc" "break test_ldm_stm_pc" {
46 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
47 pass "break test_ldm_stm_pc"
49 -re "No symbol.*\r\n$gdb_prompt $" {
50 pass "break test_ldm_stm_pc"
55 gdb_test "break *test_ldm_pc" \
56 "Breakpoint.*at.* file .*$srcfile, line.*" \
58 gdb_test "break *test_ldm_stm_pc_ret" \
59 "Breakpoint.*at.* file .*$srcfile, line.*" \
60 "break test_ldm_stm_pc_ret"
62 gdb_continue_to_breakpoint "continue to test_ldm_stm_pc" \
63 ".*stmdb.*sp\!\,.*\{lr\, pc\}.*"
64 gdb_continue_to_breakpoint "continue to test_ldm_pc" \
65 ".*ldmia.*sp\!\,.*\{pc\}.*"
66 gdb_continue_to_breakpoint "continue to test_ldm_stm_pc_ret" \
70 #########################################
72 proc test_ldr_literal {} {
76 gdb_test_multiple "break *test_ldr_literal" "break test_ldr_literal" {
77 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
78 pass "break test_ldr_literal"
80 -re "No symbol.*\r\n$gdb_prompt $" {
85 gdb_test "break *test_ldrsb_literal" \
86 "Breakpoint.*at.* file .*$srcfile, line.*" \
87 "break test_ldrsb_literal"
88 gdb_test "break *test_ldrsh_literal" \
89 "Breakpoint.*at.* file .*$srcfile, line.*" \
90 "break test_ldrsh_literal"
91 gdb_test "break *test_ldr_literal_end" \
92 "Breakpoint.*at.* file .*$srcfile, line.*" \
93 "break test_test_ldr_literal_end"
95 gdb_continue_to_breakpoint "continue to test_ldr_literal" \
96 ".*ldrh.*r0\,.*\[pc\].*"
97 gdb_continue_to_breakpoint "continue to test_ldrsb_literal" \
98 ".*ldrsb.*r0\,.*\[pc\].*"
99 gdb_continue_to_breakpoint "continue to test_ldrsh_literal" \
100 ".*ldrsh.*r0\,.*\[pc\].*"
101 gdb_continue_to_breakpoint "continue to test_ldr_literal_ret" \
105 proc test_ldr_literal_16 {} {
109 gdb_test_multiple "break *test_ldr_literal_16" "break test_ldr_literal_16" {
110 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
111 pass "break test_ldr_literal"
113 -re "No symbol.*\r\n$gdb_prompt $" {
117 gdb_test "break *test_ldr_literal_16_end" \
118 "Breakpoint.*at.* file .*$srcfile, line.*" \
119 "break test_ldr_literal_16_end"
121 gdb_continue_to_breakpoint "continue to test_ldr_literal_16" \
123 gdb_continue_to_breakpoint "continue to test_ldr_literal_16_end" \
127 ##########################################
129 proc test_call_ret {} {
133 gdb_test "break *test_call" \
134 "Breakpoint.*at.* file .*$srcfile, line.*" \
137 gdb_test "break *test_call_end" \
138 "Breakpoint.*at.* file .*$srcfile, line.*" \
139 "break test_call_end"
140 gdb_test "break *test_ret" \
141 "Breakpoint.*at.* file .*$srcfile, line.*" \
143 gdb_test "break *test_ret_end" \
144 "Breakpoint.*at.* file .*$srcfile, line.*" \
147 gdb_continue_to_breakpoint "test_call" ".*bl test_call_subr.*"
148 gdb_continue_to_breakpoint "test_call_end" \
149 ".*@ Location test_call_end.*"
150 gdb_continue_to_breakpoint "test_ret" \
152 gdb_continue_to_breakpoint "continue to test_ret_end" \
153 ".*@ Location test_ret_end.*"
157 #########################################
159 proc test_branch {} {
161 gdb_test "break *test_branch" \
162 "Breakpoint.*at.* file .*$srcfile, line.*" \
164 gdb_test "break *L_branch" \
165 "Breakpoint.*at.* file .*$srcfile, line.*" \
168 gdb_continue_to_breakpoint "continue to test_branch" \
170 gdb_continue_to_breakpoint "continue to Lbranch" \
174 #########################################
177 proc test_ldr_from_pc {} {
179 gdb_test "break *test_ldr_pc" \
180 "Breakpoint.*at.* file .*$srcfile, line.*" \
182 gdb_test "break test_ldr_pc_ret" \
183 "Breakpoint.*at.* file .*$srcfile, line.*" \
184 "break test_ldr_pc_ret"
186 gdb_continue_to_breakpoint "continue to test_ldr_pc" \
187 ".*ldr.*r1\,.*\[pc, #0\].*"
188 gdb_continue_to_breakpoint "continue to test_ldr_pc_ret" \
192 #########################################
195 proc test_cbz_cbnz {} {
199 gdb_test_multiple "break *test_zero_cbnz" "break test_zero_cbnz" {
200 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
201 pass "break test_ldr_literal"
203 -re "No symbol.*\r\n$gdb_prompt $" {
208 gdb_test "break *test_zero_cbz" \
209 "Breakpoint.*at.* file .*$srcfile, line.*" \
210 "break test_zero_cbz"
211 gdb_test "break *test_non_zero_cbnz" \
212 "Breakpoint.*at.* file .*$srcfile, line.*" \
213 "break test_non_zero_cbnz"
214 gdb_test "break *test_non_zero_cbz" \
215 "Breakpoint.*at.* file .*$srcfile, line.*" \
216 "break test_non_zero_cbz"
218 gdb_continue_to_breakpoint "continue to test_zero_cbnz" \
219 ".*cbnz.*r0\,.*\.L3.*"
220 gdb_continue_to_breakpoint "continue to test_zero_cbz" \
221 ".*cbz.*r0\,.*\.L3.*"
222 gdb_continue_to_breakpoint "continue to test_non_zero_cbz" \
223 ".*cbz.*r0\,.*\.L4.*"
224 gdb_continue_to_breakpoint "continue to test_non_zero_cbnz" \
225 ".*cbnz.*r0\,.*\.L4.*"
234 gdb_test_multiple "break *test_adr" "break test_adr" {
235 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
236 pass "break test_adr"
238 -re "No symbol.*\r\n$gdb_prompt $" {
243 gdb_test "break *test_adr_end" \
244 "Breakpoint.*at.* file .*$srcfile, line.*" \
247 gdb_continue_to_breakpoint "test_adr" \
248 ".*adr.*r0\,.*\.L8.*"
249 gdb_continue_to_breakpoint "test_adr_end" \
253 proc test_adr_32bit {} {
257 gdb_test_multiple "break *test_adr_32bit" "break test_adr_32bit" {
258 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
259 pass "break test_adr"
261 -re "No symbol.*\r\n$gdb_prompt $" {
266 gdb_test "break *test_adr_32bit_after" \
267 "Breakpoint.*at.* file .*$srcfile, line.*" \
268 "break test_adr_32bit_after"
270 gdb_test "break *test_adr_32bit_end" \
271 "Breakpoint.*at.* file .*$srcfile, line.*" \
272 "break test_adr_32bit_end"
274 gdb_continue_to_breakpoint "test_adr_32bit" \
275 ".*adr.*r0\,.*\.L6.*"
276 gdb_continue_to_breakpoint "test_adr_32bit_after" \
277 ".*adr.*r0\,.*\.L6.*"
278 gdb_continue_to_breakpoint "test_adr_32bit_end" \
282 #########################################
284 proc test_pop_pc {} {
286 gdb_test "break *test_pop_pc_1" \
287 "Breakpoint.*at.* file .*$srcfile, line.*" \
288 "break test_pop_pc_1"
289 gdb_test "break *test_pop_pc_2" \
290 "Breakpoint.*at.* file .*$srcfile, line.*" \
291 "break test_pop_pc_2"
292 gdb_test "break *test_pop_pc_3" \
293 "Breakpoint.*at.* file .*$srcfile, line.*" \
294 "break test_pop_pc_3"
296 gdb_test "break *test_pop_pc_ret" \
297 "Breakpoint.*at.* file .*$srcfile, line.*" \
298 "break test_pop_pc_ret"
300 gdb_test "break *test_pop_pc_1_right" \
301 "Breakpoint.*at.* file .*$srcfile, line.*" \
302 "break test_pop_pc_1_right"
303 gdb_test "break *test_pop_pc_1_wrong" \
304 "Breakpoint.*at.* file .*$srcfile, line.*" \
305 "break test_pop_pc_1_wrong"
306 gdb_test "break *test_pop_pc_2_right" \
307 "Breakpoint.*at.* file .*$srcfile, line.*" \
308 "break test_pop_pc_2_right"
309 gdb_test "break *test_pop_pc_2_wrong" \
310 "Breakpoint.*at.* file .*$srcfile, line.*" \
311 "break test_pop_pc_2_wrong"
312 gdb_test "break *test_pop_pc_3_right" \
313 "Breakpoint.*at.* file .*$srcfile, line.*" \
314 "break test_pop_pc_3_right"
315 gdb_test "break *test_pop_pc_3_wrong" \
316 "Breakpoint.*at.* file .*$srcfile, line.*" \
317 "break test_pop_pc_1_wrong"
319 gdb_continue_to_breakpoint "continue to test_pop_pc_1" \
321 gdb_continue_to_breakpoint "continue to test_pop_pc_1_check" \
324 gdb_continue_to_breakpoint "continue to test_pop_pc_2" \
326 gdb_continue_to_breakpoint "continue to test_pop_pc_2_check" \
328 gdb_continue_to_breakpoint "continue to test_pop_pc_3" \
329 ".*\{r0\,r1\,r2\,r3\,r4\,r5\,r6\,r7\,pc\}.*"
330 gdb_continue_to_breakpoint "continue to test_pop_pc_3_check" \
332 gdb_continue_to_breakpoint "continue to test_pop_pc_ret" \
336 ###########################################
338 proc test_str_pc {} {
342 gdb_test_multiple "break *test_str_pc" "break test_str_pc" {
343 -re "Breakpoint.*at.* file .*$srcfile, line.*\r\n$gdb_prompt $" {
344 pass "break test_str_pc"
346 -re "No symbol.*\r\n$gdb_prompt $" {
347 pass "break test_str_pc"
351 gdb_test "break *test_str_pc_end" \
352 "Breakpoint.*at.* file .*$srcfile, line.*" \
353 "break test_str_pc_end"
355 # Set breakpoint on both lables pc_offset_right and pc_offset_wrong
356 gdb_test "break *pc_offset_right" \
357 "Breakpoint.*at.* file .*$srcfile, line.*" \
358 "break pc_offset_right"
359 gdb_test "break *pc_offset_wrong" \
360 "Breakpoint.*at.* file .*$srcfile, line.*" \
361 "break pc_offset_wrong"
363 gdb_continue_to_breakpoint "continue to test_str_pc" \
364 ".*str.*pc\,.*\[sp, #-4\].*"
365 # If breakpoint on lable pc_offset_wrong is hit, that means the offset
366 # computed in displaced stepping is different from offset computed
367 # without displaced stepping. Report a failure.
368 gdb_continue_to_breakpoint "continue to pc_offset_right" \
369 ".*b.*test_str_pc_end.*"
370 gdb_continue_to_breakpoint "continue to test_str_pc_end" \
374 # Get things started.
376 clean_restart ${testfile}
378 # Turn displaced stepping off before runto main. When displaced stepping
379 # is on, and we type 'run', GDB will first try to single step on _dl_debug_state,
380 # which is in library might be compiled in Thumb.
381 gdb_test_no_output "set displaced-stepping off"
383 if ![runto_main] then {
384 fail "Can't run to main"
388 gdb_test_no_output "set displaced-stepping on"
389 gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
413 ##########################################
415 # Done, run program to exit.
417 gdb_continue_to_end "arm-disp-step"